Supporting Multiple Answers: A Small Design Detour

A profile can contain many answers, so the next test tackles that scenario:

iloveyouboss/tdd-10/test/iloveyouboss/ProfileTest.java
 
@Test
 
public​ ​void​ matchesWhenContainsMultipleAnswers() {
 
profile.add(answerThereIsRelocation);
 
profile.add(answerDoesNotReimburseTuition);
 
Criterion criterion =
 
new​ Criterion(answerThereIsRelocation, Weight.Important);
 
 
boolean​ result = profile.matches(criterion);
 
 
assertTrue(result);
 
}

Having multiple Answers in the Profile requires a way to store and distinguish them. We choose to store the Answers in a Map where the key is the question text and the value is the associated Answer. (It’d probably be better to use an Answer ID as the key, ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.