diff --git a/metafacture-io/src/main/java/org/metafacture/io/ObjectFileWriter.java b/metafacture-io/src/main/java/org/metafacture/io/ObjectFileWriter.java index 7e6003cf7..f74629827 100644 --- a/metafacture-io/src/main/java/org/metafacture/io/ObjectFileWriter.java +++ b/metafacture-io/src/main/java/org/metafacture/io/ObjectFileWriter.java @@ -108,8 +108,8 @@ public void process(final T obj) { @Override public void resetStream() { closeStream(); - startNewFile(); ++count; + startNewFile(); } @Override diff --git a/metafacture-io/src/test/java/org/metafacture/io/ObjectFileWriterTest.java b/metafacture-io/src/test/java/org/metafacture/io/ObjectFileWriterTest.java index 213ba6aec..64d877fb2 100644 --- a/metafacture-io/src/test/java/org/metafacture/io/ObjectFileWriterTest.java +++ b/metafacture-io/src/test/java/org/metafacture/io/ObjectFileWriterTest.java @@ -17,6 +17,7 @@ package org.metafacture.io; import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeFalse; import java.io.File; @@ -93,6 +94,17 @@ public void shouldAppendToExistingFile() throws IOException { assertOutput(DATA + "\n" + DATA + "\n"); } + @Test + public void shouldIncrementCountOnResetBeforeStartingNewFile() throws IOException { + final String pathWithVar = tempFolder.getRoot() + "/test-${i}"; + writer = new ObjectFileWriter(pathWithVar); + writer.process(DATA); + assertTrue(new File(tempFolder.getRoot(), "test-0").exists()); + writer.resetStream(); // increments count, starts new file + writer.process(DATA); + assertTrue(new File(tempFolder.getRoot(), "test-1").exists()); + } + @Override protected ConfigurableObjectWriter getWriter() { return writer;