package th.or.nectec.tanrabad.entity;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.util.UUID;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;

@RunWith(JUnit4.class)
public class PlaceTest {

    public static final UUID BANGPHAI_UUID = UUID.randomUUID();
    public static final String BANGPHAI_NAME = "บางไผ่";
    public static final int BANGPHAI_TYPE = Place.TYPE_VILLAGE_COMMUNITY;

    @Test
    public void testPlaceWithName() throws Exception {
        Place place = Place.withName(BANGPHAI_NAME);
        assertEquals(BANGPHAI_NAME, place.getName());
    }

    @Test
    public void testGetPlaceId() throws Exception {
        Place place = new Place(BANGPHAI_UUID, BANGPHAI_NAME);
        assertEquals(BANGPHAI_UUID, place.getId());
    }

    @Test
    public void testGetPlaceName() throws Exception {
        Place place = new Place(BANGPHAI_UUID, BANGPHAI_NAME);
        assertEquals(BANGPHAI_NAME, place.getName());
    }

    @Test
    public void testSetThenGetPlaceName() throws Exception {
        Place place = new Place(BANGPHAI_UUID, BANGPHAI_NAME);
        place.setName("บางโพธิ์");
        assertEquals("บางโพธิ์", place.getName());
    }

    @Test
    public void testSetThenGetPlaceType() throws Exception {
        Place place = new Place(BANGPHAI_UUID, BANGPHAI_NAME);
        place.setType(Place.TYPE_SCHOOL);
        assertEquals(Place.TYPE_SCHOOL, place.getType());
    }

    @Test
    public void placeWithDifferentNameMustNotEqual() throws Exception {
        Place place1 = new Place(BANGPHAI_UUID, BANGPHAI_NAME);
        place1.setType(BANGPHAI_TYPE);
        Place place2 = new Place(BANGPHAI_UUID, "บางโพธิ์");
        place2.setType(BANGPHAI_TYPE);
        assertNotEquals(place1, place2);
    }

    @Test
    public void placeWithDifferentTypeMustNotEqual() throws Exception {
        Place place1 = new Place(BANGPHAI_UUID, BANGPHAI_NAME);
        place1.setType(Place.TYPE_FACTORY);
        Place place2 = new Place(BANGPHAI_UUID, BANGPHAI_NAME);
        place2.setType(Place.TYPE_SCHOOL);
        assertNotEquals(place1, place2);
    }

    @Test
    public void placeWithTheSameNameAndTypeMustEqual() throws Exception {
        Place place1 = new Place(BANGPHAI_UUID, BANGPHAI_NAME);
        place1.setType(BANGPHAI_TYPE);
        Place place2 = new Place(BANGPHAI_UUID, BANGPHAI_NAME);
        place2.setType(BANGPHAI_TYPE);
        assertEquals(place1, place2);
    }
}

@@ -483,16 +483,164 @@
 MMUNITY;
+%0A    private final Place place1 = new Place(BANGPHAI_UUID, BANGPHAI_NAME);%0A    private final Place place2 = new Place(BANGPHAI_UUID, BANGPHAI_NAME);
 %0A%0A    @T
@@ -663,21 +663,16 @@
 oid test
-Place
 WithName
@@ -840,21 +840,16 @@
  testGet
-Place
 Id() thr
@@ -868,71 +868,8 @@
 n %7B%0A
-        Place place = new Place(BANGPHAI_UUID, BANGPHAI_NAME);%0A
     
@@ -901,24 +901,25 @@
 _UUID, place
+1
 .getId());%0A 
@@ -957,21 +957,16 @@
  testGet
-Place
 Name() t
@@ -987,71 +987,8 @@
 n %7B%0A
-        Place place = new Place(BANGPHAI_UUID, BANGPHAI_NAME);%0A
     
@@ -1016,32 +1016,33 @@
 PHAI_NAME, place
+1
 .getName());%0A   
@@ -1128,76 +1128,14 @@
     
-Place place = new Place(BANGPHAI_UUID, BANGPHAI_NAME);%0A        
 place
+1
 .set
@@ -1186,24 +1186,25 @@
 %E0%B8%9E%E0%B8%98%E0%B8%B4%E0%B9%8C%22, place
+1
 .getName());
@@ -1294,76 +1294,14 @@
     
-Place place = new Place(BANGPHAI_UUID, BANGPHAI_NAME);%0A        
 place
+1
 .set
@@ -1366,24 +1366,25 @@
 CHOOL, place
+1
 .getType());
@@ -1485,60 +1485,35 @@
     
-Place place1 = new Place(BANGPHAI_UUID, BANGPHAI_NAM
+place1.setType(BANGPHAI_TYP
 E);%0A
@@ -1517,33 +1517,33 @@
 );%0A        place
-1
+2
 .setType(BANGPHA
@@ -1539,121 +1539,60 @@
 ype(
-BANGPHAI_TYPE);%0A        Place place2 = new Place(BANGPHAI_UUID, %22%E0%B8%9A%E0%B8%B2%E0%B8%87%E0%B9%82%E0%B8%9E%E0%B8%98%E0%B8%B4%E0%B9%8C%22);%0A        place2.setType(BANGPHAI_TYPE
+place1.getType());%0A        place2.setName(%22%E0%B8%9A%E0%B8%B2%E0%B8%87%E0%B9%82%E0%B8%9E%E0%B8%98%E0%B8%B4%E0%B9%8C%22
 );%0A 
@@ -1732,169 +1732,41 @@
     
-Place place1 = new Place(BANGPHAI_UUID, BANGPHAI_NAME);%0A        place1.setType(Place.TYPE_FACTORY);%0A        Place place2 = new Place(BANGPHAI_UUID, BANGPHAI_NAME
+place1.setType(Place.TYPE_FACTORY
 );%0A 
@@ -1951,163 +1951,35 @@
     
-Place place1 = new Place(BANGPHAI_UUID, BANGPHAI_NAME);%0A        place1.setType(BANGPHAI_TYPE);%0A        Place place2 = new Place(BANGPHAI_UUID, BANGPHAI_NAM
+place1.setType(BANGPHAI_TYP
 E);%0A

refactor test สำหรับ entity Place