### Question:
FileSystemFlowPersistenceProvider implements FlowPersistenceProvider { @Override public synchronized void saveFlowContent(final FlowSnapshotContext context, final byte[] content) throws FlowPersistenceException { final File bucketDir = new File(flowStorageDir, context.getBucketId()); try { FileUtils.ensureDirectoryExistAndCanReadAndWrite(bucketDir); } catch (IOException e) { throw new FlowPersistenceException("Error accessing bucket directory at " + bucketDir.getAbsolutePath(), e); } final File flowDir = new File(bucketDir, context.getFlowId()); try { FileUtils.ensureDirectoryExistAndCanReadAndWrite(flowDir); } catch (IOException e) { throw new FlowPersistenceException("Error accessing flow directory at " + flowDir.getAbsolutePath(), e); } final String versionString = String.valueOf(context.getVersion()); final File versionDir = new File(flowDir, versionString); try { FileUtils.ensureDirectoryExistAndCanReadAndWrite(versionDir); } catch (IOException e) { throw new FlowPersistenceException("Error accessing version directory at " + versionDir.getAbsolutePath(), e); } final File versionFile = new File(versionDir, versionString + SNAPSHOT_EXTENSION); if (versionFile.exists()) { throw new FlowPersistenceException("Unable to save, a snapshot already exists with version " + versionString); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Saving snapshot with filename {}", new Object[] {versionFile.getAbsolutePath()}); } try (final OutputStream out = new FileOutputStream(versionFile)) { out.write(content); out.flush(); } catch (Exception e) { throw new FlowPersistenceException("Unable to write snapshot to disk due to " + e.getMessage(), e); } }  @Override void onConfigured(final ProviderConfigurationContext configurationContext); @Override synchronized void saveFlowContent(final FlowSnapshotContext context, final byte[] content); @Override synchronized byte[] getFlowContent(final String bucketId, final String flowId, final int version); @Override synchronized void deleteAllFlowContent(final String bucketId, final String flowId); @Override synchronized void deleteFlowContent(final String bucketId, final String flowId, final int version);  }### Answer:
@Test public void testSaveWithExistingVersion() throws IOException { final FlowSnapshotContext context = Mockito.mock(FlowSnapshotContext.class); when(context.getBucketId()).thenReturn("bucket1"); when(context.getFlowId()).thenReturn("flow1"); when(context.getVersion()).thenReturn(1); final byte[] content = "flow1v1".getBytes(StandardCharsets.UTF_8); fileSystemFlowProvider.saveFlowContent(context, content); final byte[] content2 = "XXX".getBytes(StandardCharsets.UTF_8); try { fileSystemFlowProvider.saveFlowContent(context, content2); Assert.fail("Should have thrown exception"); } catch (Exception e) { } final File flowSnapshotFile = new File(flowStorageDir, "bucket1/flow1/1/1" + FileSystemFlowPersistenceProvider.SNAPSHOT_EXTENSION); try (InputStream in = new FileInputStream(flowSnapshotFile)) { Assert.assertEquals("flow1v1", IOUtils.toString(in, StandardCharsets.UTF_8)); } }