package th.or.nectec.tanrabad.entity;

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

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

@RunWith(JUnit4.class)
public class UserTest {

    public static final String AUSTIN_USERNAME = "austin1023";
    public static final String AUSTIN_FIRSTNAME = "Austin";
    public static final String AUSTIN_LASTNAME = "Kydd";
    public static final String AUSTIN_EMAIL = "austin.k@gmail.com";
    public static final int AUSTIN_ORGANIZATION_ID = 201;

    @Test
    public void testSetFirstname() throws Exception {
        User austin = new User(AUSTIN_USERNAME);
        austin.setFirstname(AUSTIN_FIRSTNAME);
        assertEquals(AUSTIN_FIRSTNAME, austin.getFirstname());
    }

    @Test
    public void testSetLastname() throws Exception {
        User austin = new User(AUSTIN_USERNAME);
        austin.setLastname(AUSTIN_LASTNAME);
        assertEquals(AUSTIN_LASTNAME, austin.getLastname());
    }

    @Test
    public void setThenGetEmail() throws Exception {
        User austin = new User(AUSTIN_USERNAME);
        austin.setEmail(AUSTIN_EMAIL);
        assertEquals(AUSTIN_EMAIL, austin.getEmail());
    }

    @Test
    public void testSetOrganizationId() throws Exception {
        User austin = new User(AUSTIN_USERNAME);
        austin.setOrganizationId(AUSTIN_ORGANIZATION_ID);
        assertEquals(AUSTIN_ORGANIZATION_ID, austin.getOrganizationId());
    }

    @Test
    public void getUsername() throws Exception {
        User austin = new User(AUSTIN_USERNAME);
        assertEquals(AUSTIN_USERNAME, austin.getUsername());
    }

    @Test
    public void testFromUsername() throws Exception {
        User austin = User.fromUsername(AUSTIN_USERNAME);
        assertEquals(AUSTIN_USERNAME, austin.getUsername());
    }

    @Test
    public void userWithDifferentFirstnameMustNotEqual() throws Exception {
        User austin1 = new User(AUSTIN_USERNAME);
        austin1.setFirstname(AUSTIN_FIRSTNAME);
        User austin2 = new User(AUSTIN_USERNAME);
        austin2.setFirstname("Austinno");
        assertNotEquals(austin1, austin2);
    }

    @Test
    public void userWithDiffrentLastnameMustNotEqual() throws Exception {
        User austin1 = new User(AUSTIN_USERNAME);
        austin1.setLastname(AUSTIN_LASTNAME);
        User austin2 = new User(AUSTIN_USERNAME);
        austin2.setLastname("Butler");
        assertNotEquals(austin1, austin2);
    }
}
@@ -574,80 +574,85 @@
 01;%0A
-%0A    @Test%0A    public void testSetFirstname() throws Exception %7B%0A       
+    private final User austin1 = new User(AUSTIN_USERNAME);%0A    private final
  Use
@@ -651,32 +651,33 @@
 inal User austin
+2
  = new User(AUST
@@ -681,32 +681,104 @@
 USTIN_USERNAME);
+%0A%0A    @Test%0A    public void testSetThenGetFirstname() throws Exception %7B
 %0A        austin.
@@ -772,24 +772,25 @@
       austin
+1
 .setFirstnam
@@ -851,24 +851,25 @@
 NAME, austin
+1
 .getFirstnam
@@ -914,16 +914,23 @@
  testSet
+ThenGet
 Lastname
@@ -963,63 +963,15 @@
     
-User 
 austin
- = new User(AUSTIN_USERNAME);%0A        austin
+1
 .set
@@ -1037,24 +1037,25 @@
 NAME, austin
+1
 .getLastname
@@ -1141,63 +1141,15 @@
     
-User 
 austin
- = new User(AUSTIN_USERNAME);%0A        austin
+1
 .set
@@ -1206,24 +1206,25 @@
 MAIL, austin
+1
 .getEmail())
@@ -1265,16 +1265,23 @@
  testSet
+ThenGet
 Organiza
@@ -1320,63 +1320,15 @@
     
-User 
 austin
- = new User(AUSTIN_USERNAME);%0A        austin
+1
 .set
@@ -1414,24 +1414,25 @@
 N_ID, austin
+1
 .getOrganiza
@@ -1512,57 +1512,8 @@
 n %7B%0A
-        User austin = new User(AUSTIN_USERNAME);%0A
     
@@ -1544,32 +1544,33 @@
 USERNAME, austin
+1
 .getUsername());
@@ -1865,141 +1865,41 @@
     
-User austin1 = new User(AUSTIN_USERNAME);%0A        austin1.setFirstname(AUSTIN_FIRSTNAME);%0A        User austin2 = new User(AUSTIN_USER
+austin1.setFirstname(AUSTIN_FIRST
 NAME
@@ -2089,43 +2089,524 @@
     
-User austin1 = new User(AUSTIN_USER
+austin1.setLastname(AUSTIN_LASTNAME);%0A        austin2.setLastname(%22Butler%22);%0A        assertNotEquals(austin1, austin2);%0A    %7D%0A%0A    @Test%0A    public void userWithDiffrentOrganizationMustNotEqual() throws Exception %7B%0A        austin1.setOrganizationId(AUSTIN_ORGANIZATION_ID);%0A        austin2.setOrganizationId(408);%0A        assertNotEquals(austin1, austin2);%0A    %7D%0A%0A    @Test%0A    public void userWithTheSameUsernameFirstnameLastnameOrganizationIdMustEqual() throws Exception %7B%0A        austin1.setFirstname(AUSTIN_FIRST
 NAME
@@ -2666,105 +2666,242 @@
     
-User 
 austin
-2 = new User(AUSTIN_USERNAME);%0A        austin2.setLastname(%22Butler%22);%0A        assertNo
+1.setOrganizationId(AUSTIN_ORGANIZATION_ID);%0A        austin2.setFirstname(austin1.getFirstname());%0A        austin2.setLastname(austin1.getLastname());%0A        austin2.setOrganizationId(austin1.getOrganizationId());%0A        asser
 tEqu

refactor test สำหรับ entiry User