コード例 #1
0
  @Test
  public void testCreateCarer() {
    Carer mockCarer = mock(Carer.class);
    when(mockCarer.getFullName()).thenReturn("testCarerUser");
    when(mockCarer.getRole()).thenReturn(2);
    when(mockCarer.getUserName()).thenReturn("testCarer");
    when(mockCarer.getPassword()).thenReturn("carerPassword");
    Carer result = spyUserDao.createCarer(mockCarer);

    assertNotNull(result);
    assertEquals("fullname", result.getFullName(), "testCarerUser");
    assertEquals("roles", result.getRole(), 2);
    assertEquals("username", result.getUserName(), "testCarer");
    assertEquals("password", result.getPassword(), "carerPassword");

    deleteEntry("testCarer");
  }
コード例 #2
0
  @Test
  public void testUpdateUserAssignment() {
    Carer mockCarer = mock(Carer.class);
    when(mockCarer.getFullName()).thenReturn("testCarerUser3");
    when(mockCarer.getRole()).thenReturn(2);
    when(mockCarer.getUserName()).thenReturn("testCarer3");
    when(mockCarer.getPassword()).thenReturn("carerPassword3");
    Carer resultCarer = spyUserDao.createCarer(mockCarer);
    int carer_id = resultCarer.getId();

    Patient mockPatient = mock(Patient.class);
    when(mockPatient.getFullName()).thenReturn("testPatientUser3");
    when(mockPatient.getRole()).thenReturn(1);
    when(mockPatient.getUserName()).thenReturn("testPatient3");
    when(mockPatient.getPassword()).thenReturn("patientPassword3");
    when(mockPatient.getCarer_id()).thenReturn(3);
    Patient patient = spyUserDao.createPatient(mockPatient);
    List<String> patientIds = new ArrayList<String>();
    patientIds.add(String.valueOf(patient.getId()));

    boolean updateSuccess = spyUserDao.updateUserAssignment(carer_id, patientIds);

    assertEquals("updateSuccess", updateSuccess, true);
  }