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 ...

Get Pragmatic Unit Testing in Java 8 with JUnit now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.