package com.fundynamic.dune2themaker.game.map;

import com.fundynamic.dune2themaker.game.terrain.Terrain;
import com.fundynamic.dune2themaker.game.terrain.TerrainFacing;
import junit.framework.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;

import static org.mockito.AdditionalMatchers.not;

public class FacingDeterminerTest {

    private final Terrain SAND = makeTerrain();
    private final Terrain ROCK = makeTerrain();

    @Test
    public void returnsMiddleWhenNoSameTypeOfNeighbours() throws Exception {
        FacingDeterminer facingDeterminer = new FacingDeterminer(SAND, SAND, SAND, SAND);
        TerrainFacing facing = facingDeterminer.getFacing(ROCK);
        Assert.assertEquals(TerrainFacing.MIDDLE, facing);
    }

    @Test
    public void returnsTopWhenSameTypeAbove() throws Exception {
        FacingDeterminer facingDeterminer = new FacingDeterminer(ROCK, SAND, SAND, SAND);
        TerrainFacing facing = facingDeterminer.getFacing(ROCK);
        Assert.assertEquals(TerrainFacing.TOP, facing);
    }

    @Test
    @Ignore
    public void returnsFullWhenAllSameTypeOfNeighbours() throws Exception {
        FacingDeterminer facingDeterminer = new FacingDeterminer(ROCK, ROCK, ROCK, ROCK);
        TerrainFacing facing = facingDeterminer.getFacing(ROCK);
        Assert.assertEquals(TerrainFacing.FULL, facing);
    }

    private Terrain makeTerrain() {
        Terrain terrain = Mockito.mock(Terrain.class);
        Mockito.when(terrain.isSame(terrain)).thenReturn(true);
        return terrain;
    }

    private class FacingDeterminer {

        private final Terrain up;
        private final Terrain right;
        private final Terrain down;
        private final Terrain left;

        public FacingDeterminer(Terrain up, Terrain right, Terrain down, Terrain left) {
            this.up = up;
            this.right = right;
            this.down = down;
            this.left = left;
        }

        public TerrainFacing getFacing(Terrain center) {
            if (up.isSame(center)) {
                return TerrainFacing.TOP;
            }
            return TerrainFacing.MIDDLE;
        }
    }
}

@@ -1049,32 +1049,327 @@
 facing);%0A    %7D%0A%0A
+    @Test%0A    public void returnsTopWhenSameTypeRight() throws Exception %7B%0A        FacingDeterminer facingDeterminer = new FacingDeterminer(SAND, ROCK, SAND, SAND);%0A        TerrainFacing facing = facingDeterminer.getFacing(ROCK);%0A        Assert.assertEquals(TerrainFacing.RIGHT, facing);%0A    %7D%0A%0A
     @Test%0A    @I
@@ -2401,24 +2401,122 @@
           %7D%0A
+            if (right.isSame(center)) %7B%0A                return TerrainFacing.RIGHT;%0A            %7D%0A
             

Add right facing