### Question:
OptimisticEventStoreService implements EventStore { @Override public WritableEventStream openStreamForWriting( String bucketId, String streamId, long version) { NotifyingPersistenceDecorator deco = new NotifyingPersistenceDecorator(persistence, persistenceNotifier); return OptimisticEventStream.createWritable(bucketId, streamId, version, deco); }  @Override ReadableEventStream openStreamForReading(String bucketId, String streamId); @Override ReadableEventStream openStreamForReading(String bucketId, String streamId, long version); @Override WritableEventStream createStream(String bucketId, String streamId); @Override WritableEventStream openStreamForWriting(
            String bucketId, String streamId, long version); @Override boolean existsStream(String bucketId, String streamId);  }### Answer:
@Test public void testOpenStreamForWriting() throws Exception { cleanup(); fill(BUCKET_ID, "FOO", 10); WritableEventStream wes = eventStore.openStreamForWriting(BUCKET_ID, "FOO", 10); assertEquals(wes.version(), 10); testWriting(wes); assertEquals(BUCKET_ID, wes.bucketId()); assertEquals("FOO", wes.streamId()); }
@Test public void testOpenStreamForWritingConcurrency() throws Exception { cleanup(); fill(BUCKET_ID, "FOO", 10); caught = false; caughtCS = null; WritableEventStream wes = eventStore.openStreamForWriting(BUCKET_ID, "FOO", 8); wes.append("bla"); try { wes.commit(UUID.randomUUID().toString()); fail("Should have failed by now"); } catch (ConcurrencyException e) { } assertTrue(!caught); assertTrue(caughtCS == null); assertEquals(BUCKET_ID, wes.bucketId()); assertEquals("FOO", wes.streamId()); }