### Question:
DisposableBatchTransactionExecutor implements BatchTransactionExecutor { @Override public final void execute() { if (alreadyExecuted.compareAndSet(false, true)) { doExecute(); } else { throw new IllegalStateException("DisposableBatchExecutor must only ever be executed once!"); } }  @Override final void execute();  }### Answer:
@Test public void shouldExecuteForTheFirstTime() { DummyDisposableBatchTransactionExecutor executor = new DummyDisposableBatchTransactionExecutor(); executor.execute(); assertEquals(1, executor.getNoTimesExecuted()); }
@Test public void shouldNotExecuteMoreThanOnce() { DummyDisposableBatchTransactionExecutor executor = new DummyDisposableBatchTransactionExecutor(); executor.execute(); try { executor.execute(); fail(); } catch (IllegalStateException e) { } assertEquals(1, executor.getNoTimesExecuted()); }