Created
May 5, 2010 18:15
-
-
Save jamescarr/391211 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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