O'Reilly logo

Pragmatic Unit Testing in Java 8 with JUnit by Jeff Langr, Andy Hunt, Dave Thomas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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(), ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required