@Test
  public void testGetUserEntry() {
    spyUserDao.insertUser("testUser2", 1, "testUsername2", "testPassword2", 3);
    ResultSet rs = spyUserDao.getUserEntry("testUsername2");

    assertNotNull(rs);
    try {
      assertEquals("fullname", rs.getString(colFullName), "testUser2");
      assertEquals("roles", rs.getInt(colRoles), 1);
      assertEquals("username", rs.getString(colUserName), "testUsername2");
      assertEquals(
          "password", rs.getString(colPassword), new HashProvider().encrypt("testPassword2"));
    } catch (Exception e) {
      e.printStackTrace();
    }

    deleteEntry("testUsername2");
  }
  @Test
  public void testInsertUser() {
    int userId = spyUserDao.insertUser("testUser", 1, "testUsername", "testPassword", 3);

    assertNotNull(userId);
    assertNotEquals("userId", userId, -1);

    deleteEntry("testUsername");
  }
  @Test
  public void testCarerAuthentication() {
    Carer mockCarer = mock(Carer.class);
    when(mockCarer.getFullName()).thenReturn("testCarerUser2");
    when(mockCarer.getRole()).thenReturn(2);
    when(mockCarer.getUserName()).thenReturn("testCarer2");
    when(mockCarer.getPassword()).thenReturn("carerPassword2");
    spyUserDao.createCarer(mockCarer);

    Carer result = spyUserDao.carerAuthentication("testCarer2", "carerPassword2");

    assertNotNull(result);
    assertEquals("fullname", result.getFullName(), "testCarerUser2");
    assertEquals("roles", result.getRole(), 2);
    assertEquals("username", result.getUserName(), "testCarer2");

    deleteEntry("testCarer2");
  }
  @Test
  public void testPatientAuthentication() {
    Patient mockPatient = mock(Patient.class);
    when(mockPatient.getFullName()).thenReturn("testPatientUser2");
    when(mockPatient.getRole()).thenReturn(1);
    when(mockPatient.getUserName()).thenReturn("testPatient2");
    when(mockPatient.getPassword()).thenReturn("patientPassword2");
    when(mockPatient.getCarer_id()).thenReturn(3);
    spyUserDao.createPatient(mockPatient);

    Patient result = spyUserDao.patientAuthentication("testPatient2", "patientPassword2");

    assertNotNull(result);
    assertEquals("fullname", result.getFullName(), "testPatientUser2");
    assertEquals("roles", result.getRole(), 1);
    assertEquals("username", result.getUserName(), "testPatient2");
    assertEquals("carer_id", result.getCarer_id(), 3);

    deleteEntry("testPatient2");
  }
 public void deleteEntry(String userName) {
   Connection conn = null;
   PreparedStatement ps = null;
   try {
     conn = spyUserDao.getConnection();
     String query = "DELETE FROM user WHERE username = ?";
     PreparedStatement preparedStmt = conn.prepareStatement(query);
     preparedStmt.setString(1, userName);
     preparedStmt.executeUpdate();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  @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);
  }