O'Reilly logo

Pragmatic Unit Testing in Java 8 with JUnit by Jeff Langr, Andy Hunt, Dave Thomas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Another Small Increment

The next test demonstrates that matches returns false when the Profile instance contains no matching Answer object:

iloveyouboss/tdd-9/test/iloveyouboss/ProfileTest.java
 
public​ ​class​ ProfileTest {
*
private​ Answer answerThereIsNotRelocation;
 
// ...
 
@Before
 
public​ ​void​ createQuestionAndAnswer() {
 
questionIsThereRelocation =
 
new​ BooleanQuestion(1, ​"Relocation package?"​);
 
answerThereIsRelocation =
 
new​ Answer(questionIsThereRelocation, Bool.TRUE);
*
answerThereIsNotRelocation =
*
new​ Answer(questionIsThereRelocation, Bool.FALSE);
 
}
 
// ...
*
@Test
*
public​ ​void​ doesNotMatchWhenNoMatchingAnswer() {
*
profile.add(answerThereIsNotRelocation);
*
Criterion criterion =
*
new​ Criterion(answerThereIsRelocation, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required