Skip to content

Instantly share code, notes, and snippets.

@jamescarr
Created May 5, 2010 18:15
Show Gist options
  • Save jamescarr/391211 to your computer and use it in GitHub Desktop.
Save jamescarr/391211 to your computer and use it in GitHub Desktop.
import static java.util.Arrays.asList;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import java.util.List;
import org.junit.Test;
public class PersonTest {
@Test
public void shouldHavePersonNamedJohnInTheList(){
List<Person> people = asList(new Person("John", "Doe"),
new Person("Jane", "Doe"),
new Person("John", "Smith"));
assertThat((List)people, hasItem(hasProperty("firstName", is("John"))));
}
}
//--- Person.java
public class Person{
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Person(String firstName, String lastName) {
setFirstName(firstName);
setLastName(lastName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment