Testing Databases

We first saw the StatCompiler code in [F]IRST: [F]ast!. We were able to refactor this class so that most of its code doesn’t directly interact with a QuestionController instance, which in turn let us write fast tests for the bulk of its logic. We were left with one method, questionText(), that interacts with a controller object, and we’d now like to test that method:

iloveyouboss/16-branch-persistence-redesign/src/iloveyouboss/domain/StatCompiler.java
 
public​ ​Map​<​Integer​,​String​> questionText(​List​<BooleanAnswer> answers) {
 
Map​<​Integer​,​String​> questions = ​new​ ​HashMap​<>();
 
answers.stream().forEach(answer -> {
 
if​ (!questions.containsKey(answer.getQuestionId()))
 
questions.put(answer.getQuestionId(), ...

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

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