Try to get tests to pass on Java 8, 11, 17 on Windows, mac, and Ubuntu
on GitHub.
This commit passes on Windows and macOS with Java 8, 11, and 17.
MODIFY
src/test/java/org/apache/commons/io/function/IOStreamTest.java
src/test/java/org/apache/commons/io/function/IOStreamTest.java
package org.apache.commons.io.function;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import java.io.IOException;
import java.util.Arrays;
import java.util.stream.LongStream;
import java.util.stream.Stream;
+import org.apache.commons.lang3.JavaVersion;
+import org.apache.commons.lang3.SystemUtils;
import org.junit.jupiter.api.Test;
/**
*/
public class IOStreamTest {
+ private static final boolean AT_LEAST_JAVA_11 = SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_11);
+ private static final boolean AT_LEAST_JAVA_17 = SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_17);
+
private void compareAndSetIO(final AtomicReference<String> ref, final String expected, final String update) throws IOException {
TestUtils.compareAndSetThrowsIO(ref, expected, update);
}
@@ -97,12 +103,17 @@ public void testCollectCollectorOfQsuperTAR() {
@Test
public void testCollectSupplierOfRBiConsumerOfRQsuperTBiConsumerOfRR() throws IOException {
// TODO Need an IOCollector?
- IOStream.of("A", "B").collect(() -> "A", (t, u) -> {}, (t, u) -> {});
+ IOStream.of("A", "B").collect(() -> "A", (t, u) -> {
+ }, (t, u) -> {
+ });
assertEquals("AB", Stream.of("A", "B").collect(StringBuilder::new, StringBuilder::append, StringBuilder::append).toString());
assertEquals("AB", IOStream.of("A", "B").collect(StringBuilder::new, StringBuilder::append, StringBuilder::append).toString());
// Exceptions
- assertThrows(IOException.class, () -> IOStream.of("A", "B").collect(TestUtils.throwingIOSupplier(), (t, u) -> {}, (t, u) -> {}));
- assertThrows(IOException.class, () -> IOStream.of("A", "B").collect(() -> "A", TestUtils.throwingIOBiConsumer(), (t, u) -> {}));
+ assertThrows(IOException.class, () -> IOStream.of("A", "B").collect(TestUtils.throwingIOSupplier(), (t, u) -> {
+ }, (t, u) -> {
+ }));
+ assertThrows(IOException.class, () -> IOStream.of("A", "B").collect(() -> "A", TestUtils.throwingIOBiConsumer(), (t, u) -> {
+ }));
}
@SuppressWarnings("resource") // custom stream not recognized by compiler warning machinery
@@ -443,9 +454,21 @@ public void testParallel() {
@Test
public void testPeek() throws IOException {
final AtomicReference<String> ref = new AtomicReference<>();
- assertEquals(1, IOStream.of("A").peek(e -> compareAndSetIO(ref, null, e)).count());
+ // Stream sanity check
+ assertEquals(1, Stream.of("A").peek(e -> compareAndSetRE(ref, null, e)).count());
+ // TODO Resolve, abstract or document these differences?
+ assertEquals(AT_LEAST_JAVA_11 ? null : "A", ref.get());
+ if (AT_LEAST_JAVA_11) {
+ assertEquals(1, IOStream.of("B").peek(e -> compareAndSetRE(ref, null, e)).count());
+ assertEquals(1, IOStream.of("B").peek(e -> compareAndSetIO(ref, null, e)).count());
+ assertEquals(null, ref.get());
+ } else {
+ // Java 8
+ assertThrows(RuntimeException.class, () -> IOStream.of("B").peek(e -> compareAndSetRE(ref, null, e)).count());
+ assertThrows(IOException.class, () -> IOStream.of("B").peek(e -> compareAndSetIO(ref, null, e)).count());
assertEquals("A", ref.get());
}
+ }
@SuppressWarnings("resource") // custom stream not recognized by compiler warning machinery
@Test
@@ -481,8 +504,22 @@ public void testSequential() {
@Test
public void testSkip() throws IOException {
final AtomicReference<String> ref = new AtomicReference<>();
- assertEquals(1, IOStream.of("A", "B").skip(1).peek(e -> compareAndSetIO(ref, null, e)).count());
+ assertEquals(1, Stream.of("A", "B").skip(1).peek(e -> compareAndSetRE(ref, null, e)).count());
+ // TODO Resolve, abstract or document these differences?
+ assertEquals(AT_LEAST_JAVA_17 ? null : "B", ref.get());
+ if (AT_LEAST_JAVA_17) {
+ assertEquals(1, IOStream.of("C", "D").skip(1).peek(e -> compareAndSetRE(ref, null, e)).count());
+ assertEquals(1, IOStream.of("C", "D").skip(1).peek(e -> compareAndSetIO(ref, null, e)).count());
+ assertNull(ref.get());
+ } else if (AT_LEAST_JAVA_11) {
+ assertThrows(RuntimeException.class, () -> IOStream.of("C", "D").skip(1).peek(e -> compareAndSetRE(ref, null, e)).count());
+ assertThrows(IOException.class, () -> IOStream.of("C", "D").skip(1).peek(e -> compareAndSetIO(ref, null, e)).count());
assertEquals("B", ref.get());
+ } else {
+ assertThrows(RuntimeException.class, () -> IOStream.of("C", "D").skip(1).peek(e -> compareAndSetRE(ref, null, e)).count());
+ assertThrows(IOException.class, () -> IOStream.of("C", "D").skip(1).peek(e -> compareAndSetIO(ref, null, e)).count());
+ assertEquals("B", ref.get());
+ }
}
@SuppressWarnings("resource") // custom stream not recognized by compiler warning machinery

Try to get tests to pass on Java 8, 11, 17 on Windows, mac, and Ubuntu
on GitHub.

This commit passes on Windows and macOS with Java 8, 11, and 17.