Add method that allows to reset the line suppression.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 27 Jan 2014 05:27:08 +0000 (06:27 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 27 Jan 2014 05:27:08 +0000 (06:27 +0100)
src/main/java/net/pterodactylus/xdcc/util/io/DuplicateLineSuppressingWriter.java
src/test/java/net/pterodactylus/xdcc/util/io/DuplicateLineSuppressingWriterTest.java

index 85e90eb..1610678 100644 (file)
@@ -91,6 +91,10 @@ public class DuplicateLineSuppressingWriter extends Writer {
                writeCollectedLines();
        }
 
+       public void reset() {
+               lastLine = null;
+       }
+
        private void writeCollectedLines() throws IOException {
                while (currentLineContainsLineBreak()) {
                        String nextLine = cutNextLine();
index e923d69..de6455d 100644 (file)
@@ -66,4 +66,13 @@ public class DuplicateLineSuppressingWriterTest {
                assertThat(stringWriter.toString(), is("First Line.\nSecond Line.\nFirst Line.\n"));
        }
 
+       @Test
+       public void resettingTheWriterAllowsADuplicateLine() throws IOException {
+               duplicateLineSuppressingWriter.write("First Line.\n");
+               duplicateLineSuppressingWriter.write("Second Line.\n");
+               duplicateLineSuppressingWriter.reset();
+               duplicateLineSuppressingWriter.write("Second Line.\n");
+               assertThat(stringWriter.toString(), is("First Line.\nSecond Line.\nSecond Line.\n"));
+       }
+
 }