Automated and Manual Refactorings

In our case, the answer local variable doesn’t clarify the code, and it’s used only once. Inline (remove) the variable by replacing its use with the answerMatching(criterion) expression:

iloveyouboss/20/src/iloveyouboss/Profile.java
 
for​ (Criterion criterion: criteria) {
*
boolean​ match = criterion.matches(answerMatching(criterion));
 
 
if​ (!match && criterion.getWeight() == Weight.MustMatch) {
 
kill = true;
 
}
 
if​ (match) {
 
score += criterion.getWeight().getValue();
 
}
 
anyMatches |= match;
 
}

You could manually inline answer, but your IDE most likely automates the inline refactoring. In Eclipse, select Refactor Inline… from the main menu to inline.

The very existence of automated IDE automated ...

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.