package com.pollistics.services;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import com.pollistics.PollisticsApplication;
import com.pollistics.models.Poll;
import com.pollistics.repositories.PollRepository;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = PollisticsApplication.class)
public class PollServiceTests {
	@Autowired
	private PollRepository pollRepo;

	@Autowired
	private PollService pollService;

	@Test
	public void getPollByIdTest() {
		Poll poll = pollRepo.findAll().get(0);
		Poll pollById = pollService.getPoll(poll.getId().toString());
		assertThat(poll.equals(pollById));
	}

	@Test
	public void getAllPollsTest() {
		assertThat(pollService.getAllPolls() != null);
		assertThat(pollService.getAllPolls().get(0) != null);
		assertThat(pollService.getAllPolls().equals(pollRepo.findAll()));
	}
	
	@Test
	public void createPollTest() {
		Poll poll = pollRepo.findAll().get(0);
		String id = pollService.createPoll(poll.getName(), poll.getOptions());
		assertThat(id instanceof String);
		
		Poll pollById = pollService.getPoll(id);
		assertThat(id.equals(pollById.getId()));		
	}
}

@@ -262,24 +262,88 @@
 ngBootTest;%0A
+import org.springframework.data.mongodb.core.mapping.TextScore;%0A
 import org.s
@@ -391,16 +391,16 @@
 Runner;%0A
-
 %0Aimport 
@@ -524,16 +524,65 @@
 itory;%0A%0A
+import java.util.HashMap;%0Aimport java.util.Set;%0A%0A
 @RunWith
@@ -1185,18 +1185,17 @@
 )));%0A%09%7D%0A
-%09
 %0A
+
 %09@Test%0A%09
@@ -1375,19 +1375,17 @@
 tring);%0A
-%09%09
 %0A
+
 %09%09Poll p
@@ -1461,16 +1461,395 @@
 tId()));
-%09%09
+%0A%09%7D%0A%0A%09@Test%0A%09public void voteOptionTest() %7B%0A%09%09Poll poll = pollRepo.findAll().get(0);%0A%09%09HashMap%3CString, Integer%3E opts = poll.getOptions();%0A%09%09String%5B%5D keys = opts.keySet().toArray(new String%5B0%5D);%0A%09%09String first = keys%5B0%5D;%0A%0A%09%09int firstVal = opts.get(first);%0A%0A%09%09boolean result = pollService.voteOption(poll, first);%0A%09%09assert result;%0A%0A%09%09assertThat(opts.get(first).equals(firstVal + 1));
 %0A%09%7D%0A%7D%0A

test service