@Test
public void testUpdateUnrefreshedCertificatesNotificationTimestamp() throws Exception {

    JDBCCertRecordStoreConnection jdbcConn = new JDBCCertRecordStoreConnection(mockConn);
    Mockito.when(mockPrepStmt.executeUpdate())
            .thenReturn(3) // 3 members updated
            .thenReturn(0); // On second call, no members were updated
    long currentTime = System.currentTimeMillis();
    Timestamp ts = new Timestamp(currentTime);
    Mockito.when(mockResultSet.getTimestamp(JDBCCertRecordStoreConnection.DB_COLUMN_LAST_NOTIFIED_TIME))
            .thenReturn(ts)
            .thenReturn(ts)
            .thenReturn(ts);
    Mockito.when(mockResultSet.getString(JDBCCertRecordStoreConnection.DB_COLUMN_LAST_NOTIFIED_SERVER))
            .thenReturn("server0")
            .thenReturn("server1")
            .thenReturn("server2");
    Mockito.when(mockResultSet.next())
            .thenReturn(true) // this one is for server1
            .thenReturn(true) // this one is for server2
            .thenReturn(true) // this one is for server3
            .thenReturn(false); // end
    Mockito.when(mockResultSet.getString(JDBCCertRecordStoreConnection.DB_COLUMN_SERVICE)).thenReturn(null);
    Mockito.when(mockResultSet.getString(JDBCCertRecordStoreConnection.DB_COLUMN_HOSTNAME)).thenReturn(null);
    Mockito.when(mockResultSet.getString(JDBCCertRecordStoreConnection.DB_COLUMN_INSTANCE_ID)).thenReturn(null);
    Mockito.when(mockResultSet.getTimestamp(JDBCCertRecordStoreConnection.DB_COLUMN_EXPIRY_TIME)).thenReturn(ts);
    Mockito.when(mockResultSet.getBoolean(JDBCCertRecordStoreConnection.DB_COLUMN_CLIENT_CERT)).thenReturn(false);
    Mockito.when(mockResultSet.getTimestamp(JDBCCertRecordStoreConnection.DB_COLUMN_CURRENT_TIME)).thenReturn(ts);
    Mockito.when(mockResultSet.getTimestamp(JDBCCertRecordStoreConnection.DB_COLUMN_PREV_TIME)).thenReturn(ts);
    List<X509CertRecord> unrefreshedCertificateRecords = jdbcConn.updateUnrefreshedCertificatesNotificationTimestamp("localhost", currentTime, "provider");
    assertNotNull(unrefreshedCertificateRecords);
    assertEquals(unrefreshedCertificateRecords.size(), 3);
    for (int i = 0; i < unrefreshedCertificateRecords.size(); ++i) {
        assertEquals(unrefreshedCertificateRecords.get(i).getLastNotifiedServer(), "server" + i);
        assertEquals(unrefreshedCertificateRecords.get(i).getLastNotifiedTime(), new Date(currentTime));
    }
    jdbcConn.close();
}