Skip to content
Snippets Groups Projects
Commit e67e7b65 authored by Paul-Christian Volkmer's avatar Paul-Christian Volkmer
Browse files

Throw NotFoundException if there are no feedbacks to get average value.

parent 8a74dba3
No related merge requests found
...@@ -29,7 +29,6 @@ import org.springframework.web.bind.annotation.PathVariable; ...@@ -29,7 +29,6 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import de.thm.arsnova.entities.Feedback; import de.thm.arsnova.entities.Feedback;
......
...@@ -31,6 +31,7 @@ import org.springframework.stereotype.Service; ...@@ -31,6 +31,7 @@ import org.springframework.stereotype.Service;
import de.thm.arsnova.dao.IDatabaseDao; import de.thm.arsnova.dao.IDatabaseDao;
import de.thm.arsnova.entities.Feedback; import de.thm.arsnova.entities.Feedback;
import de.thm.arsnova.entities.User; import de.thm.arsnova.entities.User;
import de.thm.arsnova.exceptions.NotFoundException;
import de.thm.arsnova.socket.ARSnovaSocketIOServer; import de.thm.arsnova.socket.ARSnovaSocketIOServer;
@Service @Service
...@@ -81,11 +82,11 @@ public class FeedbackService implements IFeedbackService { ...@@ -81,11 +82,11 @@ public class FeedbackService implements IFeedbackService {
double sum = values.get(1) + (values.get(2) * 2) + (values.get(3) * 3); double sum = values.get(1) + (values.get(2) * 2) + (values.get(3) * 3);
if (count == 0) if (count == 0)
return 0; throw new NotFoundException();
return sum / count; return sum / count;
} }
@Override @Override
public long getAverageFeedbackRounded(String sessionkey) { public long getAverageFeedbackRounded(String sessionkey) {
return Math.round(this.getAverageFeedback(sessionkey)); return Math.round(this.getAverageFeedback(sessionkey));
......
...@@ -78,9 +78,15 @@ public class FeedbackServiceTest { ...@@ -78,9 +78,15 @@ public class FeedbackServiceTest {
} }
@Test @Test
public void testShouldReturnZeroFeedbackCountForNoFeedbackAtAll() {
userService.setUserAuthenticated(true);
assertEquals(0, feedbackService.getFeedbackCount("12345678"));
}
@Test(expected = NotFoundException.class)
public void testShouldReturnAverageFeedbackForNoFeedbackAtAll() { public void testShouldReturnAverageFeedbackForNoFeedbackAtAll() {
userService.setUserAuthenticated(true); userService.setUserAuthenticated(true);
assertEquals(0, feedbackService.getAverageFeedback("12345678"), 0); feedbackService.getAverageFeedback("12345678");
} }
@Test @Test
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment