package com.pm.server.player;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Before;
import org.springframework.beans.factory.annotation.Autowired;

import com.pm.server.TestTemplate;

public class GhostRepositoryTest extends TestTemplate {

	@Autowired
	private GhostRepository ghostRepository;

	private static final Logger log =
			LogManager.getLogger(GhostRepositoryTest.class.getName());

	@Before
	public void setUp() {

		List<Ghost> ghostList = ghostRepository.getAllGhosts();

		for(Ghost ghost : ghostList) {
			try {
				ghostRepository.deleteGhostById(ghost.getId());
			}
			catch(Exception e) {
				log.error(e.getMessage());
				fail();
			}
		}

		assertTrue(ghostRepository.getAllGhosts().isEmpty());

	}

}

@@ -24,16 +24,61 @@
 layer;%0A%0A
+import static org.junit.Assert.assertEquals;%0A
 import s
@@ -112,16 +112,16 @@
 rtTrue;%0A
-
 import s
@@ -283,16 +283,39 @@
 Before;%0A
+import org.junit.Test;%0A
 import o
@@ -404,16 +404,62 @@
 emplate;
+%0Aimport com.pm.server.datatype.CoordinateImpl;
 %0A%0Apublic
@@ -564,16 +564,61 @@
 itory;%0A%0A
+%09private static final double DELTA = 1e-15;%0A%0A
 %09private
@@ -975,16 +975,16 @@
 %09%7D%0A%09%09%7D%0A%0A
-
 %09%09assert
@@ -1036,10 +1036,834 @@
 );%0A%0A%09%7D%0A%0A
+%09@Test%0A%09public void unitTest_addGhost() %7B%0A%0A%09%09// Given%0A%09%09Integer ghostId = 12345;%0A%09%09Double latitude = 246.802;%0A%09%09Double longitude = 135.791;%0A%0A%09%09Ghost ghost = new GhostImpl();%0A%09%09ghost.setId(ghostId);%0A%09%09ghost.setLocation(new CoordinateImpl(latitude, longitude));%0A%0A%09%09// When%0A%09%09try %7B%0A%09%09%09ghostRepository.addGhost(ghost);%0A%09%09%7D%0A%09%09catch(Exception e) %7B%0A%09%09%09log.error(e.getMessage());%0A%09%09%09fail();%0A%09%09%7D%0A%0A%09%09// Then%0A%09%09Ghost ghostFromRepository = ghostRepository.getGhostById(ghostId);%0A%09%09assertTrue(ghostFromRepository != null);%0A%0A%09%09assertEquals(ghost.getId(), ghostFromRepository.getId());%0A%09%09assertEquals(%0A%09%09%09%09ghost.getLocation().getLatitude(),%0A%09%09%09%09ghostFromRepository.getLocation().getLatitude(),%0A%09%09%09%09DELTA%0A%09%09);%0A%09%09assertEquals(%0A%09%09%09%09ghost.getLocation().getLongitude(),%0A%09%09%09%09ghostFromRepository.getLocation().getLongitude(),%0A%09%09%09%09DELTA%0A%09%09);%0A%0A%09%7D%0A%0A
 %7D%0A

Write test for GhostRepository addGhost()