@Test public void testVerifyVotesRejectsMissingCategory() { assertFalse(1 == firstEvent.getVoteCategories().size()); List<Long> voteList = Lists.newArrayList(); voteList.add(firstEvent.getVoteCategories().get(0).getVoteOptions().get(0).getId()); try { voteService.verifyVotes(firstEvent, voteList); fail("should not succeed"); } catch (Exception e) { assertTrue(e.getMessage().contains("Invalid voting")); } }
@Test public void testVerifyVotesRejectsVotesForOtherEvent() { assertEquals(2, firstEvent.getVoteCategories().size()); List<Long> voteList = Lists.newArrayList(); voteList.add(firstEvent.getVoteCategories().get(0).getVoteOptions().get(0).getId()); voteList.add(secondEvent.getVoteCategories().get(0).getVoteOptions().get(0).getId()); try { voteService.verifyVotes(firstEvent, voteList); fail("should not succeed"); } catch (Exception e) { assertTrue(e.getMessage().contains("Must vote in all categories")); } }
@Test public void testVoteEventDoesntExist() { Event e = new Event(null, null, "", "", EventType.PUBLIC, DateTime.now(), DateTime.now()); e.setId((long) 10000); List<Long> voteList = Lists.newArrayList(); voteList.add((long) 1); try { voteService.verifyVotes(e, voteList); fail("should not succeed"); } catch (Exception e1) { assertTrue(e1.getMessage() != null); } }
@Test public void testVerifyVotes() { assertEquals(2, firstEvent.getVoteCategories().size()); List<Long> voteList = Lists.newArrayList(); voteList.add(firstEvent.getVoteCategories().get(0).getVoteOptions().get(0).getId()); voteList.add(firstEvent.getVoteCategories().get(1).getVoteOptions().get(0).getId()); try { voteService.verifyVotes(firstEvent, voteList); return; } catch (Exception e) { // ignore } fail("should not succeed"); }