JdbcMessageRepository extends AbstractMessageRepository implements MessageRepository { @Override public void remove(Plaintext message) { try (Connection connection = config.getConnection()) { connection.setAutoCommit(false); try (Statement stmt = connection.createStatement()) { stmt.executeUpdate("DELETE FROM Message_Label WHERE message_id = " + message.getId()); stmt.executeUpdate("DELETE FROM Message WHERE id = " + message.getId()); connection.commit(); } catch (SQLException e) { try { connection.rollback(); } catch (SQLException e1) { LOG.debug(e1.getMessage(), e); } LOG.error(e.getMessage(), e); } } catch (SQLException e) { LOG.error(e.getMessage(), e); } } JdbcMessageRepository(JdbcConfig config); @Override int countUnread(Label label); @Override void save(Plaintext message); @Override void remove(Plaintext message);  }
@Test public void ensureMessageIsRemoved() throws Exception { Plaintext toRemove = repo.findMessages(Plaintext.Status.DRAFT, contactB).get(0); List<Plaintext> messages = repo.findMessages(Plaintext.Status.DRAFT); assertEquals(2, messages.size()); repo.remove(toRemove); messages = repo.findMessages(Plaintext.Status.DRAFT); assertThat(messages, hasSize(1)); }