Testing Databases

Learn how to write tests in order to test databases.

We were able to refactor this class so that most of its code doesn’t directly interact with a QuestionController instance, which in turn lets us write fast tests for the bulk of its logic. We were left with one method, questionText(), that interacts with a controller object. Let’s test that method:

Press + to interact
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(),
controller.find(answer.getQuestionId()).getText()); });
return questions;
}

The questionText() method takes a list of answer objects and returns a ...