package com.pm.server.player;

import static org.junit.Assert.assertEquals;
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.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import com.pm.server.TestTemplate;
import com.pm.server.datatype.CoordinateImpl;

public class GhostRepositoryTest extends TestTemplate {

	@Autowired
	private GhostRepository ghostRepository;

	private static final double DELTA = 1e-15;

	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());

	}

	@Test
	public void unitTest_addGhost() {

		// Given
		Integer ghostId = 12345;
		Double latitude = 246.802;
		Double longitude = 135.791;

		Ghost ghost = new GhostImpl();
		ghost.setId(ghostId);
		ghost.setLocation(new CoordinateImpl(latitude, longitude));

		// When
		try {
			ghostRepository.addGhost(ghost);
		}
		catch(Exception e) {
			log.error(e.getMessage());
			fail();
		}

		// Then
		Ghost ghostFromRepository = ghostRepository.getGhostById(ghostId);
		assertTrue(ghostFromRepository != null);

		assertEquals(ghost.getId(), ghostFromRepository.getId());
		assertEquals(
				ghost.getLocation().getLatitude(),
				ghostFromRepository.getLocation().getLatitude(),
				DELTA
		);
		assertEquals(
				ghost.getLocation().getLongitude(),
				ghostFromRepository.getLocation().getLongitude(),
				DELTA
		);

	}

}

@@ -405,16 +405,58 @@
 mplate;%0A
+import com.pm.server.datatype.Coordinate;%0A
 import c
@@ -551,16 +551,88 @@
 late %7B%0A%0A
+%09private Ghost ghost1;%0A%0A%09private Ghost ghost2;%0A%0A%09private Ghost ghost3;%0A%0A
 %09@Autowi
@@ -854,16 +854,571 @@
 Up() %7B%0A%0A
+%09%09Integer ghost1_id = 12345;%0A%09%09Coordinate ghost1_location = new CoordinateImpl(1.0, 0.1);%0A%09%09ghost1 = new GhostImpl();%0A%09%09ghost1.setId(ghost1_id);%0A%09%09ghost1.setLocation(ghost1_location);%0A%0A%09%09Integer ghost2_id = 23456;%0A%09%09Coordinate ghost2_location = new CoordinateImpl(2.0, 0.2);%0A%09%09ghost2 = new GhostImpl();%0A%09%09ghost2.setId(ghost2_id);%0A%09%09ghost2.setLocation(ghost2_location);%0A%0A%09%09Integer ghost3_id = 34567;%0A%09%09Coordinate ghost3_location = new CoordinateImpl(3.0, 0.3);%0A%09%09ghost3 = new GhostImpl();%0A%09%09ghost3.setId(ghost3_id);%0A%09%09ghost3.setLocation(ghost3_location);%0A%0A
 %09%09List%3CG
@@ -1467,17 +1467,16 @@
 osts();%0A
-%0A
 %09%09for(Gh
@@ -1642,17 +1642,16 @@
 %09%09%7D%0A%09%09%7D%0A
-%0A
 %09%09assert

Add and set up 3 ghosts for GhostRepositoryTest