The Profile Class and the SRP

Let’s take a look at our Profile class so far:

public​ ​class​ Profile {
private​ ​Map​<​String​,Answer> answers = ​new​ ​HashMap​<>();
private​ ​int​ score;
private​ ​String​ name;
public​ Profile(​String​ name) { = name;
public​ ​String​ getName() {
return​ name;
public​ ​void​ add(Answer answer) {
answers.put(answer.getQuestionText(), answer);
public​ ​boolean​ matches(Criteria criteria) {
if​ (doesNotMeetAnyMustMatchCriterion(criteria))
return​ false;
return​ anyMatches(criteria);
private​ ​boolean​ doesNotMeetAnyMustMatchCriterion(Criteria criteria) {

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.