DefaultSchemaMapper implements SchemaMapper, OperationExecutor { @Override public boolean exists(JdbcIndex<?> index) { boolean headExists = headTableEngine.exists(index); boolean histExists = historyTableEngine.exists(index); if (headExists ^ histExists) { throw new IllegalStateException("Index is inconsitent. Head: " + headExists + ", history: " + histExists); } return headExists; } DefaultSchemaMapper(TableEngine headTableEngine, TableEngine historyTableEngine); @Override boolean exists(JdbcIndex<?> index); @Override void create(JdbcIndex<?> index); @Override void drop(JdbcIndex<?> index); @Override void execute(Operation operation); @Override void execute(InsertOperation operation); @Override void execute(UpdateOperation operation); @Override void execute(DeleteOperation operation);  }
@Test public void exists_onNonExistingIndex_returnsFalse() throws Exception { JdbcIndex<?> index = new JdbcIndex<>(); when(headTableEngine.exists(index)).thenReturn(false); when(historyTableEngine.exists(index)).thenReturn(false); assertFalse(mapper.exists(index)); }
@Test public void exists_onExistingIndex_returnsTrue() throws Exception { JdbcIndex<?> index = new JdbcIndex<>(); when(headTableEngine.exists(index)).thenReturn(true); when(historyTableEngine.exists(index)).thenReturn(true); assertTrue(mapper.exists(index)); }
@Test(expected = IllegalStateException.class) public void exists_onInconsistentIndex_throwsException() throws Exception { JdbcIndex<?> index = new JdbcIndex<>(); when(headTableEngine.exists(index)).thenReturn(true); when(historyTableEngine.exists(index)).thenReturn(false); mapper.exists(index); }