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));
	}
	
	@Test(expected=NullPointerException.class)
	public void testSaveCommunityFails() {
		
		CommunityDto dummyCommDto = CommunityConverter.convert(community);
		service.save(dummyCommDto);
		
	}
	
	
	@Test
	public void testFindByAuthorId()
	{	
		Mockito.when(service.findByAuthorId(1L)).thenReturn(new ArrayList<CommunityDto>() );
		service.findByAuthorId(1L);
	}
	
	
	
}
@@ -2141,98 +2141,245 @@
 %0A%09%7B%09
+%09
 %0A%09%09
-Mockito.when(service.findByAuthorId(1L)).thenReturn(new ArrayList%3CCommunityDto%3E() );%0A%09%09
+//TODO anpassen bei der Implementierung, da sonnst error%0A%09%09Assert.assertNull(service.findByAuthorId(1L));%0A%09%7D%0A%09%0A%09@Test%0A%09public void testFindUserRelated()%7B%0A%09%09//TODO anpassen bei der Implementierung, da sonnst error%0A%09%09Assert.assertNull(
 serv
@@ -2390,26 +2390,35 @@
 find
-ByAuthorI
+UserRelate
 d(1L)
+)
 ;%0A%09
-%7D
+%09%0A%09%7D%0A%09%0A%09
 %0A%09%0A%09

TEST PREPARE