package at.fhj.swd14.pse.community;


import static org.mockito.Mockito.times;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

import javax.naming.NamingException;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;

import at.fhj.swd14.pse.converter.CommunityConverter;
import at.fhj.swd14.pse.converter.PersonConverter;
import at.fhj.swd14.pse.converter.StatusConverter;
import at.fhj.swd14.pse.converter.UserConverter;
import at.fhj.swd14.pse.person.PersonDto;
import at.fhj.swd14.pse.person.PersonImage;
import at.fhj.swd14.pse.repository.CommunityRepository;
import at.fhj.swd14.pse.repository.PersonRepository;
import at.fhj.swd14.pse.repository.PersonStatusRepository;
import at.fhj.swd14.pse.user.User;
import at.fhj.swd14.pse.user.UserService;
import org.junit.Assert;

@RunWith(MockitoJUnitRunner.class)
public class CommunityServiceImplTest {

	@InjectMocks
	private CommunityServiceImpl service;
	
	@Mock
	private CommunityRepository communityRepo;
	
	
	private Community community;
	private Community communityWithData;
	private List<Community> communities;

	@Before
	public void setup() throws NamingException
	{
		
        community = CommunityTestHelper.getTestCommunity();
        communityWithData = CommunityTestHelper.getTestCommunityWithData();

	}
	
	@Test
	public void testFind()
	{
		Mockito.when(communityRepo.find(1L)).thenReturn(community);
		CommunityDto expectedCommunity = service.find(1L);
		
	}
	
	@Test
	public void testSaveCommunity()
	{
		CommunityDto dummyCommDto = CommunityConverter.convert(communityWithData);
		service.save(dummyCommDto);
		
		Mockito.verify(communityRepo,Mockito.times(1)).save(Mockito.any(Community.class));
	}
	
	
	
}
@@ -1643,16 +1643,22 @@
 1L);%0A%09%09%0A
+%09%09%0A%09%09%0A
 %09%7D%0A%09%0A%09@T
@@ -1899,11 +1899,180 @@
 %0A%09%7D%0A%09%0A%09%0A
+%09@Test%0A%09public void testFindByAuthorId()%0A%09%7B%09%0A%09%09Mockito.when(service.findByAuthorId(1L)).thenReturn(new ArrayList%3CCommunityDto%3E() );%0A%09%09service.findByAuthorId(1L);%0A%09%7D%0A%09%0A%09%0A
 %09%0A%7D

Add testFindByAuthorId