JDBCStore extends JDBCBase implements Store { @Override public synchronized @Nullable String getVotedFor(final long term) throws StorageException { try { return executeQuery("SELECT server FROM voted_for WHERE term=?", new StatementWithReturnBlock<String>() { @Override public @Nullable String use(PreparedStatement statement) throws Exception { statement.setLong(1, term); return withResultSet(statement, new ResultSetBlock<String>() { @Override public String use(ResultSet resultSet) throws Exception { String server = null; if (resultSet.next()) { server = resultSet.getString(1); } checkState(!resultSet.next(), "too many rows for voted_for in term %s", term); return server; } }); } }); } catch (Exception e) { throw new StorageException(String.format("fail get votedFor in term %d", term), e); } } JDBCStore(String url, String username, @Nullable String password); @Override synchronized long getCurrentTerm(); @Override synchronized void setCurrentTerm(final long term); @Override synchronized long getCommitIndex(); @Override synchronized void setCommitIndex(final long logIndex); @Override synchronized @Nullable String getVotedFor(final long term); @Override synchronized void setVotedFor(final long term, final String server); @Override void clearVotedFor();  }
@Test public void shouldReturnNullIfNoOneWasVotedFor() throws StorageException { long term = getRandomLong(); assertThat(jdbcStore.getVotedFor(term), nullValue()); }