@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);
    // save new content for an existing version
    final byte[] content2 = "XXX".getBytes(StandardCharsets.UTF_8);
    try {
        fileSystemFlowProvider.saveFlowContent(context, content2);
        Assert.fail("Should have thrown exception");
    } catch (Exception e) {
    }
    // verify the new content wasn't written
    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));
    }
}