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 BuildingTest {

    public static final UUID BUILDING_UUID = UUID.randomUUID();
    public static final String BUILDING_NAME = "โบสถ์ใหญ่";
    private final Place place = Place.withName("วิหารเซนต์เมรี่");

    @Test
    public void testWithName() throws Exception {
        Building building = Building.withName(BUILDING_NAME);
        assertEquals(BUILDING_NAME, building.getName());
    }

    @Test
    public void testSetThenGetPlace() throws Exception {
        Building building = new Building(BUILDING_UUID, BUILDING_NAME);
        building.setPlace(place);
        assertEquals(place, building.getPlace());
    }

    @Test
    public void testGetName() throws Exception {
        Building building = new Building(BUILDING_UUID, BUILDING_NAME);
        assertEquals(BUILDING_NAME, building.getName());
    }

    @Test
    public void testSetThenGetName() throws Exception {
        Building building = new Building(BUILDING_UUID, BUILDING_NAME);
        building.setName("โบสถ์เล็ก");
        assertEquals("โบสถ์เล็ก", building.getName());
    }

    @Test
    public void testGetId() throws Exception {
        Building building = new Building(BUILDING_UUID, BUILDING_NAME);
        assertEquals(BUILDING_UUID, building.getId());
    }

    @Test
    public void buildingWithDifferentIdMustNotEqual() throws Exception {
        Building building1 = new Building(BUILDING_UUID, BUILDING_NAME);
        building1.setPlace(place);
        Building building2 = new Building(UUID.randomUUID(), BUILDING_NAME);
        building2.setPlace(place);
        assertNotEquals(building1, building2);
    }

    @Test
    public void buildingWithDifferentNameMustNotEqual() throws Exception {
        Building building1 = new Building(BUILDING_UUID, BUILDING_NAME);
        building1.setPlace(place);
        Building building2 = new Building(BUILDING_UUID, "โบสถ์เล็ก");
        building2.setPlace(place);
        assertNotEquals(building1, building2);
    }

    @Test
    public void buildingWithDifferentPlaceMustNotEqual() throws Exception {
        Building building1 = new Building(BUILDING_UUID, BUILDING_NAME);
        building1.setPlace(place);
        Building building2 = new Building(BUILDING_UUID, BUILDING_NAME);
        building2.setPlace(Place.withName("โรงเรียนเซนต์เมรี่"));
        assertNotEquals(building1, building2);
    }

    @Test
    public void buildingWithTheSameNameAndIdAndPlaceMustEqual() throws Exception {
        Building building1 = new Building(BUILDING_UUID, BUILDING_NAME);
        building1.setPlace(place);
        Building building2 = new Building(BUILDING_UUID, BUILDING_NAME);
        building2.setPlace(place);
        assertEquals(building1, building2);
    }
}
@@ -482,16 +482,99 @@
 %E0%B9%80%E0%B8%A1%E0%B8%A3%E0%B8%B5%E0%B9%88%22);
+%0A    private final Building building1 = new Building(BUILDING_UUID, BUILDING_NAME);
 %0A%0A    @T
@@ -832,88 +832,16 @@
     
-Building building = new Building(BUILDING_UUID, BUILDING_NAME);%0A        
 building
 .set
@@ -832,24 +832,25 @@
     building
+1
 .setPlace(pl
@@ -887,24 +887,25 @@
 ce, building
+1
 .getPlace())
@@ -976,80 +976,8 @@
 n %7B%0A
-        Building building = new Building(BUILDING_UUID, BUILDING_NAME);%0A
     
@@ -1008,32 +1008,33 @@
 G_NAME, building
+1
 .getName());%0A   
@@ -1115,88 +1115,16 @@
     
-Building building = new Building(BUILDING_UUID, BUILDING_NAME);%0A        
 building
 .set
@@ -1119,16 +1119,17 @@
 building
+1
 .setName
@@ -1177,32 +1177,33 @@
 %E0%B9%8C%E0%B9%80%E0%B8%A5%E0%B9%87%E0%B8%81%22, building
+1
 .getName());%0A   
@@ -1267,80 +1267,8 @@
 n %7B%0A
-        Building building = new Building(BUILDING_UUID, BUILDING_NAME);%0A
     
@@ -1303,24 +1303,25 @@
 ID, building
+1
 .getId());%0A 
@@ -1413,81 +1413,8 @@
 n %7B%0A
-        Building building1 = new Building(BUILDING_UUID, BUILDING_NAME);%0A
     
@@ -1699,81 +1699,8 @@
 n %7B%0A
-        Building building1 = new Building(BUILDING_UUID, BUILDING_NAME);%0A
     
@@ -1980,81 +1980,8 @@
 n %7B%0A
-        Building building1 = new Building(BUILDING_UUID, BUILDING_NAME);%0A
     
@@ -2301,81 +2301,8 @@
 n %7B%0A
-        Building building1 = new Building(BUILDING_UUID, BUILDING_NAME);%0A
     

refactor test สำหรับ entity Building