package com.fundynamic.d2tm.game.entities;

import com.fundynamic.d2tm.game.map.Map;
import junit.framework.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;

import java.util.HashMap;

import static org.mockito.Mockito.mock;

@RunWith(MockitoJUnitRunner.class)
public class EntityRepositoryTest {

    @Mock
    public Map map;

    @Test
    public void createUnitCreatesUnitData() throws SlickException {
        HashMap<String, EntityRepository.EntityData> entitiesData = new HashMap<>();

        EntityRepository entityRepository = new EntityRepository(map, entitiesData) {
            @Override
            protected Image loadImage(String pathToImage) throws SlickException {
                return mock(Image.class);
            }
        };

        int widthInPixels = 32;
        int heightInPixels = 32;
        int idOfEntity = 1;
        entityRepository.createUnit(idOfEntity, "quad.png", widthInPixels, heightInPixels);

        EntityRepository.EntityData data = entityRepository.getEntityData(EntityRepository.EntityType.UNIT, idOfEntity);

        Assert.assertEquals(EntityRepository.EntityType.UNIT, data.type);
        Assert.assertEquals(widthInPixels, data.width);
        Assert.assertEquals(heightInPixels, data.height);
    }

    @Test
    public void createStructureCreatesStructureData() throws SlickException {
        HashMap<String, EntityRepository.EntityData> entitiesData = new HashMap<>();

        EntityRepository entityRepository = new EntityRepository(map, entitiesData) {
            @Override
            protected Image loadImage(String pathToImage) throws SlickException {
                return mock(Image.class);
            }
        };

        int widthInPixels = 64;
        int heightInPixels = 64;
        int idOfEntity = 1;
        entityRepository.createStructure(idOfEntity, "constyard.png", widthInPixels, heightInPixels);

        EntityRepository.EntityData data = entityRepository.getEntityData(EntityRepository.EntityType.STRUCTURE, idOfEntity);

        Assert.assertEquals(EntityRepository.EntityType.STRUCTURE, data.type);
        Assert.assertEquals(widthInPixels, data.width);
        Assert.assertEquals(heightInPixels, data.height);
    }

}
@@ -109,16 +109,41 @@
 Assert;%0A
+import org.junit.Before;%0A
 import o
@@ -510,220 +510,188 @@
 ap;%0A
-%0A    @Test%0A    public void createUnitCreatesUnitData() throws SlickException %7B%0A        HashMap%3CString, EntityRepository.EntityData%3E entitiesData = new HashMap%3C%3E();%0A%0A        EntityRepository entityRepository = new
+    private EntityRepository entityRepository;%0A%0A    @Before%0A    public void setUp() throws SlickException %7B%0A        entityRepository = new EntityRepository(map, new HashMap%3CString,
  Ent
@@ -703,34 +703,30 @@
 pository
-(map, e
+.E
 ntit
-ies
+y
 Data
+%3E()
 ) %7B%0A    
@@ -884,32 +884,116 @@
    %7D%0A        %7D;%0A
+    %7D%0A%0A    @Test%0A    public void createUnitCreatesUnitData() throws SlickException %7B
 %0A        int wid
@@ -1572,352 +1572,8 @@
 n %7B%0A
-        HashMap%3CString, EntityRepository.EntityData%3E entitiesData = new HashMap%3C%3E();%0A%0A        EntityRepository entityRepository = new EntityRepository(map, entitiesData) %7B%0A            @Override%0A            protected Image loadImage(String pathToImage) throws SlickException %7B%0A                return mock(Image.class);%0A            %7D%0A        %7D;%0A%0A
     

Put setup in @before method