Skip to content

Commit

Permalink
Merge pull request #501 from metafacture/fixCountOnFileWriterReset
Browse files Browse the repository at this point in the history
Increment count before starting new file in ObjectFileWriter
  • Loading branch information
fsteeg authored Oct 5, 2023
2 parents 9cf783f + b45391a commit 4bfe2d0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ public void process(final T obj) {
@Override
public void resetStream() {
closeStream();
startNewFile();
++count;
startNewFile();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String>(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<String> getWriter() {
return writer;
Expand Down

0 comments on commit 4bfe2d0

Please sign in to comment.