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 2021/05/16 13:54:42 UTC
[commons-io] 02/07: Sort members.
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 c89d9daed4679a5169ce8e2442ddfe78e12ab43b
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun May 16 08:06:09 2021 -0400
Sort members.
---
.../apache/commons/io/function/IOFunctionTest.java | 136 ++++++++++-----------
1 file changed, 68 insertions(+), 68 deletions(-)
diff --git a/src/test/java/org/apache/commons/io/function/IOFunctionTest.java b/src/test/java/org/apache/commons/io/function/IOFunctionTest.java
index 8dcf478..c16d249 100644
--- a/src/test/java/org/apache/commons/io/function/IOFunctionTest.java
+++ b/src/test/java/org/apache/commons/io/function/IOFunctionTest.java
@@ -31,6 +31,64 @@ import org.junit.jupiter.api.Test;
public class IOFunctionTest {
+ private static class Holder<T> {
+ T value;
+ }
+
+ @Test
+ public void testAndThenConsumer() throws IOException {
+ final Holder<Integer> holder = new Holder<>();
+ final IOFunction<InputStream, Integer> readByte = InputStream::read;
+ final Consumer<Integer> sinkInteger = i -> {
+ holder.value = i * i;
+ };
+ final IOConsumer<InputStream> productFunction = readByte.andThen(sinkInteger);
+
+ final InputStream is = new ByteArrayInputStream(new byte[] {2, 3});
+ productFunction.accept(is);
+ assertEquals(4, holder.value);
+ productFunction.accept(is);
+ assertEquals(9, holder.value);
+ }
+
+ @Test
+ public void testAndThenFunction() throws IOException {
+ final IOFunction<InputStream, Integer> readByte = InputStream::read;
+ final Function<Integer, Integer> squareInteger = i -> i * i;
+ final IOFunction<InputStream, Integer> productFunction = readByte.andThen(squareInteger);
+
+ final InputStream is = new ByteArrayInputStream(new byte[] {2, 3});
+ assertEquals(4, productFunction.apply(is));
+ assertEquals(9, productFunction.apply(is));
+ }
+
+ @Test
+ public void testAndThenIOConsumer() throws IOException {
+ final Holder<Integer> holder = new Holder<>();
+ final IOFunction<InputStream, Integer> readByte = InputStream::read;
+ final IOConsumer<Integer> sinkInteger = i -> {
+ holder.value = i * i;
+ };
+ final IOConsumer<InputStream> productFunction = readByte.andThen(sinkInteger);
+
+ final InputStream is = new ByteArrayInputStream(new byte[] {2, 3});
+ productFunction.accept(is);
+ assertEquals(4, holder.value);
+ productFunction.accept(is);
+ assertEquals(9, holder.value);
+ }
+
+ @Test
+ public void testAndThenIOFunction() throws IOException {
+ final IOFunction<InputStream, Integer> readByte = InputStream::read;
+ final IOFunction<Integer, Integer> squareInteger = i -> i * i;
+ final IOFunction<InputStream, Integer> productFunction = readByte.andThen(squareInteger);
+
+ final InputStream is = new ByteArrayInputStream(new byte[] {2, 3});
+ assertEquals(4, productFunction.apply(is));
+ assertEquals(9, productFunction.apply(is));
+ }
+
@Test
public void testApply() throws IOException {
final IOFunction<InputStream, Integer> readByte = InputStream::read;
@@ -54,25 +112,25 @@ public class IOFunctionTest {
}
@Test
- public void testComposeIOFunction() throws IOException {
- final IOFunction<InputStream, Integer> readByte = InputStream::read;
+ public void testComposeFunction() throws IOException {
+ final Function<InputStream, Integer> alwaysSeven = is -> 7;
final IOFunction<Integer, Integer> squareInteger = i -> i * i;
- final IOFunction<InputStream, Integer> productFunction = squareInteger.compose(readByte);
+ final IOFunction<InputStream, Integer> productFunction = squareInteger.compose(alwaysSeven);
final InputStream is = new ByteArrayInputStream(new byte[] {2, 3});
- assertEquals(4, productFunction.apply(is));
- assertEquals(9, productFunction.apply(is));
+ assertEquals(49, productFunction.apply(is));
+ assertEquals(49, productFunction.apply(is));
}
@Test
- public void testComposeFunction() throws IOException {
- final Function<InputStream, Integer> alwaysSeven = is -> 7;
+ public void testComposeIOFunction() throws IOException {
+ final IOFunction<InputStream, Integer> readByte = InputStream::read;
final IOFunction<Integer, Integer> squareInteger = i -> i * i;
- final IOFunction<InputStream, Integer> productFunction = squareInteger.compose(alwaysSeven);
+ final IOFunction<InputStream, Integer> productFunction = squareInteger.compose(readByte);
final InputStream is = new ByteArrayInputStream(new byte[] {2, 3});
- assertEquals(49, productFunction.apply(is));
- assertEquals(49, productFunction.apply(is));
+ assertEquals(4, productFunction.apply(is));
+ assertEquals(9, productFunction.apply(is));
}
@Test
@@ -98,68 +156,10 @@ public class IOFunctionTest {
}
@Test
- public void testAndThenIOFunction() throws IOException {
- final IOFunction<InputStream, Integer> readByte = InputStream::read;
- final IOFunction<Integer, Integer> squareInteger = i -> i * i;
- final IOFunction<InputStream, Integer> productFunction = readByte.andThen(squareInteger);
-
- final InputStream is = new ByteArrayInputStream(new byte[] {2, 3});
- assertEquals(4, productFunction.apply(is));
- assertEquals(9, productFunction.apply(is));
- }
-
- @Test
- public void testAndThenFunction() throws IOException {
- final IOFunction<InputStream, Integer> readByte = InputStream::read;
- final Function<Integer, Integer> squareInteger = i -> i * i;
- final IOFunction<InputStream, Integer> productFunction = readByte.andThen(squareInteger);
-
- final InputStream is = new ByteArrayInputStream(new byte[] {2, 3});
- assertEquals(4, productFunction.apply(is));
- assertEquals(9, productFunction.apply(is));
- }
-
- @Test
- public void testAndThenIOConsumer() throws IOException {
- final Holder<Integer> holder = new Holder<>();
- final IOFunction<InputStream, Integer> readByte = InputStream::read;
- final IOConsumer<Integer> sinkInteger = i -> {
- holder.value = i * i;
- };
- final IOConsumer<InputStream> productFunction = readByte.andThen(sinkInteger);
-
- final InputStream is = new ByteArrayInputStream(new byte[] {2, 3});
- productFunction.accept(is);
- assertEquals(4, holder.value);
- productFunction.accept(is);
- assertEquals(9, holder.value);
- }
-
- @Test
- public void testAndThenConsumer() throws IOException {
- final Holder<Integer> holder = new Holder<>();
- final IOFunction<InputStream, Integer> readByte = InputStream::read;
- final Consumer<Integer> sinkInteger = i -> {
- holder.value = i * i;
- };
- final IOConsumer<InputStream> productFunction = readByte.andThen(sinkInteger);
-
- final InputStream is = new ByteArrayInputStream(new byte[] {2, 3});
- productFunction.accept(is);
- assertEquals(4, holder.value);
- productFunction.accept(is);
- assertEquals(9, holder.value);
- }
-
- @Test
public void testIdentity() throws IOException {
final IOFunction<InputStream, InputStream> identityFunction = IOFunction.identity();
try (final InputStream is = new ByteArrayInputStream(new byte[] { (byte) 0xa, (byte) 0xb, (byte) 0xc })) {
assertEquals(is, identityFunction.apply(is));
}
}
-
- private static class Holder<T> {
- T value;
- }
}