Search in sources :

Example 1 with User

use of com.example.peter.homelessapp.model.User in project FindMyHome by DjangoBlockchained.

the class UserUnitTest method testEquals.

@Test
public void testEquals() {
    User a = new HomelessUser();
    User b = new HomelessUser();
    // if both usernames are null, return false
    assertFalse(a.equals(b));
    // different names, null usernames - still false (obv)
    a.setName("Sanjana");
    b.setName("Peter");
    assertFalse((a.equals(b)));
    // same names, null usernames - still false
    b.setName("Sanjana");
    // a.getName() = sanjana
    assertFalse(a.equals(b));
    // same names, one username null - false
    b.setUsername("pzupke3");
    // a.getUsername() = NULL
    assertFalse((a.equals(b)));
    // same names, different non-null usernames - false
    a.setUsername("skadivet6");
    // b.getUsername() = pzupke3
    assertFalse((a.equals(b)));
    // same names, same non-null usernames - true!
    a.setUsername("pzupke3");
    // b.getUsername() = pzupke3
    assertTrue(a.equals(b));
    // different names, same non-null usernames - true!
    b.setName("Peter");
    assertTrue((a.equals(b)));
    // same objects, true!
    b = a;
    assertTrue(a.equals(b));
    // one of the objects is null - false
    b = null;
    assertFalse((a.equals(b)));
    // one of the objects not an instance of user - false
    Shelter x = new Shelter();
    assertFalse((a.equals(x)));
}
Also used : HomelessUser(com.example.peter.homelessapp.model.HomelessUser) HomelessUser(com.example.peter.homelessapp.model.HomelessUser) User(com.example.peter.homelessapp.model.User) Shelter(com.example.peter.homelessapp.model.Shelter) Test(org.junit.Test)

Aggregations

HomelessUser (com.example.peter.homelessapp.model.HomelessUser)1 Shelter (com.example.peter.homelessapp.model.Shelter)1 User (com.example.peter.homelessapp.model.User)1 Test (org.junit.Test)1