Skip to content

Commit 52c8a27

Browse files
author
Gary Gregory
committed
Add some missing tests.
1 parent af77aa8 commit 52c8a27

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

src/test/java/org/apache/commons/io/function/IOConsumerTest.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@
1818
package org.apache.commons.io.function;
1919

2020
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
21-
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
2222
import java.io.Closeable;
2323
import java.io.IOException;
2424
import java.io.StringReader;
25+
import java.nio.file.Files;
26+
import java.util.concurrent.atomic.AtomicReference;
2527

2628
import org.apache.commons.io.IOUtils;
29+
import org.apache.commons.io.Uncheck;
30+
import org.apache.commons.io.file.PathUtils;
2731
import org.apache.commons.io.test.ThrowOnCloseReader;
2832
import org.junit.jupiter.api.Test;
2933

@@ -33,12 +37,34 @@
3337
public class IOConsumerTest {
3438

3539
@Test
36-
public void testNoopIOConsumer() {
40+
void testAccept() throws IOException {
41+
IOConsumer.noop().accept(null);
42+
IOConsumer.noop().accept(".");
43+
Uncheck.accept(Files::size, PathUtils.current());
44+
//
45+
final AtomicReference<String> ref = new AtomicReference<>();
46+
final IOConsumer<String> consumer = s -> ref.set(s + "1");
47+
consumer.accept("A");
48+
assertEquals("A1", ref.get());
49+
}
50+
51+
@Test
52+
void testAndThen() throws IOException {
53+
final AtomicReference<String> ref = new AtomicReference<>();
54+
final IOConsumer<String> consumer1 = s -> ref.set(s + "1");
55+
final IOConsumer<String> consumer2 = s -> ref.set(ref.get() + "2" + s);
56+
consumer1.andThen(consumer2).accept("B");
57+
assertEquals("B12B", ref.get());
58+
}
59+
60+
@Test
61+
public void testNoop() {
3762
final Closeable nullCloseable = null;
3863
final IOConsumer<IOException> noopConsumer = IOConsumer.noop(); // noop consumer doesn't throw
3964
assertDoesNotThrow(() -> IOUtils.close(nullCloseable, noopConsumer));
4065
assertDoesNotThrow(() -> IOUtils.close(new StringReader("s"), noopConsumer));
4166
assertDoesNotThrow(() -> IOUtils.close(new ThrowOnCloseReader(new StringReader("s")), noopConsumer));
4267
}
4368

69+
4470
}

0 commit comments

Comments
 (0)