Search in sources :

Example 1 with HomelessUser

use of com.example.peter.homelessapp.model.HomelessUser 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)

Example 2 with HomelessUser

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

the class RegisterScreenActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register_screen);
    name = findViewById(R.id.regName);
    username = findViewById(R.id.regUserName);
    password1 = findViewById(R.id.regPass1);
    password2 = findViewById(R.id.regPass2);
    adminBox = findViewById(R.id.checkBox);
    Button cancel = findViewById(R.id.cancel2);
    cancel.setOnClickListener((view) -> finish());
    Button register = findViewById(R.id.registerUser);
    register.setOnClickListener((view) -> {
        if ((name.getText().length() == 0) || (username.getText().length() == 0) || (password1.getText().length() == 0) || (password2.getText().length() == 0)) {
            showEmptyFieldsAlert();
        } else if (password1.getText().toString().equals(password2.getText().toString())) {
            if (validUserName(username.getText().toString())) {
                if (adminBox.isChecked()) {
                    Administer newUser = new Administer(name.getText().toString(), username.getText().toString(), password1.getText().toString());
                    Intent intent = new Intent(RegisterScreenActivity.this, AdminScreenActivity.class);
                    intent.putExtra("admin", username.getText().toString());
                    startActivity(intent);
                } else {
                    HomelessUser newUser = new HomelessUser(name.getText().toString(), username.getText().toString(), password1.getText().toString());
                    Intent intent = new Intent(RegisterScreenActivity.this, ApplicationScreenActivity.class);
                    intent.putExtra("username", username.getText().toString());
                    startActivity(intent);
                }
            } else {
                showTakenUsernameAlert();
            }
        } else {
            showMismatchedPasswordsAlert();
        }
    });
}
Also used : HomelessUser(com.example.peter.homelessapp.model.HomelessUser) Button(android.widget.Button) Administer(com.example.peter.homelessapp.model.Administer) Intent(android.content.Intent)

Example 3 with HomelessUser

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

the class checkOutTest method test.

@Test
public void test() throws Exception {
    HomelessUser test = new HomelessUser();
    Shelter s = new Shelter();
    s.setCapacity(1);
    s.checkIn(test, 1);
    assert (s.checkOut(test));
    assert (!s.checkOut(test));
}
Also used : HomelessUser(com.example.peter.homelessapp.model.HomelessUser) Shelter(com.example.peter.homelessapp.model.Shelter) Test(org.junit.Test)

Example 4 with HomelessUser

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

the class UserUnitTest method testCheckIn.

/**
 * Sanjana Raman's JUnit Test
 */
@Test
public void testCheckIn() {
    HomelessUser user = new HomelessUser();
    assertTrue("".equals(user.getCurrentShelter()));
    assertTrue(user.checkIn("SwagVille"));
    assertTrue("SwagVille".equals(user.getCurrentShelter()));
    assertFalse(user.checkIn("YourMomsHouse"));
}
Also used : HomelessUser(com.example.peter.homelessapp.model.HomelessUser) Test(org.junit.Test)

Aggregations

HomelessUser (com.example.peter.homelessapp.model.HomelessUser)4 Test (org.junit.Test)3 Shelter (com.example.peter.homelessapp.model.Shelter)2 Intent (android.content.Intent)1 Button (android.widget.Button)1 Administer (com.example.peter.homelessapp.model.Administer)1 User (com.example.peter.homelessapp.model.User)1