### Question:
ContractCheckingIndexProxy extends DelegatingIndexProxy { @Override public void drop() { if ( state.compareAndSet( State.INIT, State.CLOSED ) ) { super.drop(); return; } if ( State.STARTING == state.get() ) { throw new IllegalStateException( "Concurrent drop while creating index" ); } if ( state.compareAndSet( State.STARTED, State.CLOSED ) ) { waitOpenCallsToClose(); super.drop(); return; } throw new IllegalStateException( "IndexProxy already closed" ); } ContractCheckingIndexProxy( IndexProxy delegate, boolean started ); @Override void start(); @Override IndexUpdater newUpdater( IndexUpdateMode mode ); @Override void force( IOLimiter ioLimiter ); @Override void drop(); @Override void close();  }### Answer:
@Test( expected = IllegalStateException.class ) public void shouldNotDropIndexTwice() throws IOException { IndexProxy inner = mockIndexProxy(); IndexProxy outer = newContractCheckingIndexProxy( inner ); outer.drop(); outer.drop(); }
@Test( expected = IllegalStateException.class ) public void shouldNotDropWhileCreating() throws IOException { final DoubleLatch latch = new DoubleLatch(); final IndexProxy inner = new IndexProxyAdapter() { @Override public void start() { latch.startAndWaitForAllToStartAndFinish(); } }; final IndexProxy outer = newContractCheckingIndexProxy( inner ); runInSeparateThread( outer::start ); try { latch.waitForAllToStart(); outer.drop(); } finally { latch.finish(); } }