Skip to content

Commit c89d9da

Browse files
author
Gary Gregory
committed
Sort members.
1 parent e193348 commit c89d9da

1 file changed

Lines changed: 68 additions & 68 deletions

File tree

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

Lines changed: 68 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,64 @@
3131

3232
public class IOFunctionTest {
3333

34+
private static class Holder<T> {
35+
T value;
36+
}
37+
38+
@Test
39+
public void testAndThenConsumer() throws IOException {
40+
final Holder<Integer> holder = new Holder<>();
41+
final IOFunction<InputStream, Integer> readByte = InputStream::read;
42+
final Consumer<Integer> sinkInteger = i -> {
43+
holder.value = i * i;
44+
};
45+
final IOConsumer<InputStream> productFunction = readByte.andThen(sinkInteger);
46+
47+
final InputStream is = new ByteArrayInputStream(new byte[] {2, 3});
48+
productFunction.accept(is);
49+
assertEquals(4, holder.value);
50+
productFunction.accept(is);
51+
assertEquals(9, holder.value);
52+
}
53+
54+
@Test
55+
public void testAndThenFunction() throws IOException {
56+
final IOFunction<InputStream, Integer> readByte = InputStream::read;
57+
final Function<Integer, Integer> squareInteger = i -> i * i;
58+
final IOFunction<InputStream, Integer> productFunction = readByte.andThen(squareInteger);
59+
60+
final InputStream is = new ByteArrayInputStream(new byte[] {2, 3});
61+
assertEquals(4, productFunction.apply(is));
62+
assertEquals(9, productFunction.apply(is));
63+
}
64+
65+
@Test
66+
public void testAndThenIOConsumer() throws IOException {
67+
final Holder<Integer> holder = new Holder<>();
68+
final IOFunction<InputStream, Integer> readByte = InputStream::read;
69+
final IOConsumer<Integer> sinkInteger = i -> {
70+
holder.value = i * i;
71+
};
72+
final IOConsumer<InputStream> productFunction = readByte.andThen(sinkInteger);
73+
74+
final InputStream is = new ByteArrayInputStream(new byte[] {2, 3});
75+
productFunction.accept(is);
76+
assertEquals(4, holder.value);
77+
productFunction.accept(is);
78+
assertEquals(9, holder.value);
79+
}
80+
81+
@Test
82+
public void testAndThenIOFunction() throws IOException {
83+
final IOFunction<InputStream, Integer> readByte = InputStream::read;
84+
final IOFunction<Integer, Integer> squareInteger = i -> i * i;
85+
final IOFunction<InputStream, Integer> productFunction = readByte.andThen(squareInteger);
86+
87+
final InputStream is = new ByteArrayInputStream(new byte[] {2, 3});
88+
assertEquals(4, productFunction.apply(is));
89+
assertEquals(9, productFunction.apply(is));
90+
}
91+
3492
@Test
3593
public void testApply() throws IOException {
3694
final IOFunction<InputStream, Integer> readByte = InputStream::read;
@@ -54,25 +112,25 @@ public void testApplyRaisesException() {
54112
}
55113

56114
@Test
57-
public void testComposeIOFunction() throws IOException {
58-
final IOFunction<InputStream, Integer> readByte = InputStream::read;
115+
public void testComposeFunction() throws IOException {
116+
final Function<InputStream, Integer> alwaysSeven = is -> 7;
59117
final IOFunction<Integer, Integer> squareInteger = i -> i * i;
60-
final IOFunction<InputStream, Integer> productFunction = squareInteger.compose(readByte);
118+
final IOFunction<InputStream, Integer> productFunction = squareInteger.compose(alwaysSeven);
61119

62120
final InputStream is = new ByteArrayInputStream(new byte[] {2, 3});
63-
assertEquals(4, productFunction.apply(is));
64-
assertEquals(9, productFunction.apply(is));
121+
assertEquals(49, productFunction.apply(is));
122+
assertEquals(49, productFunction.apply(is));
65123
}
66124

67125
@Test
68-
public void testComposeFunction() throws IOException {
69-
final Function<InputStream, Integer> alwaysSeven = is -> 7;
126+
public void testComposeIOFunction() throws IOException {
127+
final IOFunction<InputStream, Integer> readByte = InputStream::read;
70128
final IOFunction<Integer, Integer> squareInteger = i -> i * i;
71-
final IOFunction<InputStream, Integer> productFunction = squareInteger.compose(alwaysSeven);
129+
final IOFunction<InputStream, Integer> productFunction = squareInteger.compose(readByte);
72130

73131
final InputStream is = new ByteArrayInputStream(new byte[] {2, 3});
74-
assertEquals(49, productFunction.apply(is));
75-
assertEquals(49, productFunction.apply(is));
132+
assertEquals(4, productFunction.apply(is));
133+
assertEquals(9, productFunction.apply(is));
76134
}
77135

78136
@Test
@@ -97,69 +155,11 @@ public void testComposeSupplier() throws IOException {
97155
assertEquals(81, productFunction.get());
98156
}
99157

100-
@Test
101-
public void testAndThenIOFunction() throws IOException {
102-
final IOFunction<InputStream, Integer> readByte = InputStream::read;
103-
final IOFunction<Integer, Integer> squareInteger = i -> i * i;
104-
final IOFunction<InputStream, Integer> productFunction = readByte.andThen(squareInteger);
105-
106-
final InputStream is = new ByteArrayInputStream(new byte[] {2, 3});
107-
assertEquals(4, productFunction.apply(is));
108-
assertEquals(9, productFunction.apply(is));
109-
}
110-
111-
@Test
112-
public void testAndThenFunction() throws IOException {
113-
final IOFunction<InputStream, Integer> readByte = InputStream::read;
114-
final Function<Integer, Integer> squareInteger = i -> i * i;
115-
final IOFunction<InputStream, Integer> productFunction = readByte.andThen(squareInteger);
116-
117-
final InputStream is = new ByteArrayInputStream(new byte[] {2, 3});
118-
assertEquals(4, productFunction.apply(is));
119-
assertEquals(9, productFunction.apply(is));
120-
}
121-
122-
@Test
123-
public void testAndThenIOConsumer() throws IOException {
124-
final Holder<Integer> holder = new Holder<>();
125-
final IOFunction<InputStream, Integer> readByte = InputStream::read;
126-
final IOConsumer<Integer> sinkInteger = i -> {
127-
holder.value = i * i;
128-
};
129-
final IOConsumer<InputStream> productFunction = readByte.andThen(sinkInteger);
130-
131-
final InputStream is = new ByteArrayInputStream(new byte[] {2, 3});
132-
productFunction.accept(is);
133-
assertEquals(4, holder.value);
134-
productFunction.accept(is);
135-
assertEquals(9, holder.value);
136-
}
137-
138-
@Test
139-
public void testAndThenConsumer() throws IOException {
140-
final Holder<Integer> holder = new Holder<>();
141-
final IOFunction<InputStream, Integer> readByte = InputStream::read;
142-
final Consumer<Integer> sinkInteger = i -> {
143-
holder.value = i * i;
144-
};
145-
final IOConsumer<InputStream> productFunction = readByte.andThen(sinkInteger);
146-
147-
final InputStream is = new ByteArrayInputStream(new byte[] {2, 3});
148-
productFunction.accept(is);
149-
assertEquals(4, holder.value);
150-
productFunction.accept(is);
151-
assertEquals(9, holder.value);
152-
}
153-
154158
@Test
155159
public void testIdentity() throws IOException {
156160
final IOFunction<InputStream, InputStream> identityFunction = IOFunction.identity();
157161
try (final InputStream is = new ByteArrayInputStream(new byte[] { (byte) 0xa, (byte) 0xb, (byte) 0xc })) {
158162
assertEquals(is, identityFunction.apply(is));
159163
}
160164
}
161-
162-
private static class Holder<T> {
163-
T value;
164-
}
165165
}

0 commit comments

Comments
 (0)