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

Last Tests

Another special case: matches() returns true when the criterion is marked as “don’t care”:

iloveyouboss/tdd-14/test/iloveyouboss/ProfileTest.java
 
@Test
 
public​ ​void​ matchesWhenCriterionIsDontCare() {
 
profile.add(answerDoesNotReimburseTuition);
 
Criterion criterion =
 
new​ Criterion(answerReimbursesTuition, Weight.DontCare);
 
 
assertTrue(profile.matches(criterion));
 
}

Making the test pass requires adding a new conditional in the matches() method:

iloveyouboss/tdd-14/src/iloveyouboss/Profile.java
 
public​ ​boolean​ matches(Criterion criterion) {
 
return
 
criterion.getWeight() == Weight.DontCare ||
 
criterion.getAnswer().match(getMatchingProfileAnswer(criterion));
 
}

The new test passes, but another test breaks—the first ...

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