You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/07/25 20:22:44 UTC
[commons-io] 01/04: Add some missing tests.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git
commit 52c8a27b1b4a22dab65032d621adc471f89bfb08
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Jul 25 15:45:40 2022 -0400
Add some missing tests.
---
.../apache/commons/io/function/IOConsumerTest.java | 30 ++++++++++++++++++++--
1 file changed, 28 insertions(+), 2 deletions(-)
diff --git a/src/test/java/org/apache/commons/io/function/IOConsumerTest.java b/src/test/java/org/apache/commons/io/function/IOConsumerTest.java
index 4b557c14..79c421e9 100644
--- a/src/test/java/org/apache/commons/io/function/IOConsumerTest.java
+++ b/src/test/java/org/apache/commons/io/function/IOConsumerTest.java
@@ -18,12 +18,16 @@
package org.apache.commons.io.function;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
-
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.Closeable;
import java.io.IOException;
import java.io.StringReader;
+import java.nio.file.Files;
+import java.util.concurrent.atomic.AtomicReference;
import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.Uncheck;
+import org.apache.commons.io.file.PathUtils;
import org.apache.commons.io.test.ThrowOnCloseReader;
import org.junit.jupiter.api.Test;
@@ -33,7 +37,28 @@ import org.junit.jupiter.api.Test;
public class IOConsumerTest {
@Test
- public void testNoopIOConsumer() {
+ void testAccept() throws IOException {
+ IOConsumer.noop().accept(null);
+ IOConsumer.noop().accept(".");
+ Uncheck.accept(Files::size, PathUtils.current());
+ //
+ final AtomicReference<String> ref = new AtomicReference<>();
+ final IOConsumer<String> consumer = s -> ref.set(s + "1");
+ consumer.accept("A");
+ assertEquals("A1", ref.get());
+ }
+
+ @Test
+ void testAndThen() throws IOException {
+ final AtomicReference<String> ref = new AtomicReference<>();
+ final IOConsumer<String> consumer1 = s -> ref.set(s + "1");
+ final IOConsumer<String> consumer2 = s -> ref.set(ref.get() + "2" + s);
+ consumer1.andThen(consumer2).accept("B");
+ assertEquals("B12B", ref.get());
+ }
+
+ @Test
+ public void testNoop() {
final Closeable nullCloseable = null;
final IOConsumer<IOException> noopConsumer = IOConsumer.noop(); // noop consumer doesn't throw
assertDoesNotThrow(() -> IOUtils.close(nullCloseable, noopConsumer));
@@ -41,4 +66,5 @@ public class IOConsumerTest {
assertDoesNotThrow(() -> IOUtils.close(new ThrowOnCloseReader(new StringReader("s")), noopConsumer));
}
+
}