Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increment count before starting new file in ObjectFileWriter #501

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading