ElectionTermImpl implements ElectionTerm { @Override public void updateAndPersist(long newTerm, String newVotedFor) { update(newTerm, newVotedFor); persistence.persist(new UpdateElectionTerm(this.currentTerm, this.votedFor), NoopProcedure.instance()); } ElectionTermImpl(DataPersistenceProvider persistence, String logId, Logger log); @Override long getCurrentTerm(); @Override String getVotedFor(); @Override void update(long newTerm, String newVotedFor); @Override void updateAndPersist(long newTerm, String newVotedFor);  }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testUpdateAndPersist() throws Exception { ElectionTermImpl impl = new ElectionTermImpl(mockPersistence, "test", LOG); impl.updateAndPersist(10, "member-1"); assertEquals("getCurrentTerm", 10, impl.getCurrentTerm()); assertEquals("getVotedFor", "member-1", impl.getVotedFor()); ArgumentCaptor<Object> message = ArgumentCaptor.forClass(Object.class); ArgumentCaptor<Procedure> procedure = ArgumentCaptor.forClass(Procedure.class); verify(mockPersistence).persist(message.capture(), procedure.capture()); assertEquals("Message type", UpdateElectionTerm.class, message.getValue().getClass()); UpdateElectionTerm update = (UpdateElectionTerm)message.getValue(); assertEquals("getCurrentTerm", 10, update.getCurrentTerm()); assertEquals("getVotedFor", "member-1", update.getVotedFor()); procedure.getValue().apply(null); }