### Question:
DBAuthenticator implements IAuthenticator { @Override public synchronized boolean checkValid(String clientId, String username, byte[] password) { if (username == null || password == null) { LOG.info("username or password was null"); return false; } ResultSet resultSet = null; PreparedStatement preparedStatement = null; Connection conn = null; try { conn = this.dataSource.getConnection(); preparedStatement = conn.prepareStatement(this.sqlQuery); preparedStatement.setString(1, username); resultSet = preparedStatement.executeQuery(); if (resultSet.next()) { final String foundPwq = resultSet.getString(1); messageDigest.update(password); byte[] digest = messageDigest.digest(); String encodedPasswd = new String(Hex.encodeHex(digest)); return foundPwq.equals(encodedPasswd); } } catch (SQLException sqlex) { LOG.error("Error quering DB for username: {}", username, sqlex); } finally { try { if (resultSet != null) { resultSet.close(); } if (preparedStatement != null) { preparedStatement.close(); } if (conn != null) { conn.close(); } } catch (SQLException e) { LOG.error("Error releasing connection to the datasource", username, e); } } return false; } DBAuthenticator(IConfig conf);  DBAuthenticator(String driver, String jdbcUrl, String sqlQuery, String digestMethod); @Override synchronized boolean checkValid(String clientId, String username, byte[] password);  }### Answer:
@Test public void Db_verifyInvalidLogin() { final DBAuthenticator dbAuthenticator = new DBAuthenticator( ORG_H2_DRIVER, JDBC_H2_MEM_TEST, "SELECT PASSWORD FROM ACCOUNT WHERE LOGIN=?", SHA_256); assertFalse(dbAuthenticator.checkValid(null, "dbuser2", "password".getBytes(UTF_8))); }
@Test public void Db_verifyInvalidPassword() { final DBAuthenticator dbAuthenticator = new DBAuthenticator( ORG_H2_DRIVER, JDBC_H2_MEM_TEST, "SELECT PASSWORD FROM ACCOUNT WHERE LOGIN=?", SHA_256); assertFalse(dbAuthenticator.checkValid(null, "dbuser", "wrongPassword".getBytes(UTF_8))); }
@Test public void Db_verifyValid() { final DBAuthenticator dbAuthenticator = new DBAuthenticator( ORG_H2_DRIVER, JDBC_H2_MEM_TEST, "SELECT PASSWORD FROM ACCOUNT WHERE LOGIN=?", SHA_256); assertTrue(dbAuthenticator.checkValid(null, "dbuser", "password".getBytes(UTF_8))); }