From 3fbef75d38d4080e63dfb8f0e606c6a11b842331 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer <paul-christian.volkmer@mni.thm.de> Date: Thu, 13 Jun 2013 15:48:20 +0200 Subject: [PATCH] Fixed possible NullPointerException in CouchDBDao/QuestionService --- src/main/java/de/thm/arsnova/dao/CouchDBDao.java | 2 +- src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java | 4 +--- .../java/de/thm/arsnova/services/QuestionServiceTest.java | 6 ++++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java index 515d3e70..fa234570 100644 --- a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java +++ b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java @@ -1026,7 +1026,7 @@ public class CouchDBDao implements IDatabaseDao { ); ViewResults results = this.getDatabase().view(view); List<Answer> answers = new ArrayList<Answer>(); - if (results.getResults().isEmpty()) { + if (results == null || results.getResults() == null || results.getResults().isEmpty()) { return answers; } for (Document d : results.getResults()) { diff --git a/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java b/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java index 37750ff8..d9212d13 100644 --- a/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java +++ b/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java @@ -18,7 +18,6 @@ */ package de.thm.arsnova.dao; -import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -274,8 +273,7 @@ public class StubDatabaseDao implements IDatabaseDao { @Override public List<Answer> getMyAnswers(String sessionKey) { - // TODO Auto-generated method stub - return null; + return new ArrayList<Answer>(); } @Override diff --git a/src/test/java/de/thm/arsnova/services/QuestionServiceTest.java b/src/test/java/de/thm/arsnova/services/QuestionServiceTest.java index 96e81937..a78e67a1 100644 --- a/src/test/java/de/thm/arsnova/services/QuestionServiceTest.java +++ b/src/test/java/de/thm/arsnova/services/QuestionServiceTest.java @@ -101,4 +101,10 @@ public class QuestionServiceTest { assertFalse(theQ.isRead()); } + + @Test + public void testShouldNotThrowExceptionInMyAnsersCall() { + userService.setUserAuthenticated(true); + assertNotNull(questionService.getMyAnswers("12345678")); + } } -- GitLab