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-lang.git
The following commit(s) were added to refs/heads/master by this push:
new 24060d01b Add a Map-based test
new c8bfb687e Merge branch 'master' of
https://gitbox.apache.org/repos/asf/commons-lang.git
24060d01b is described below
commit 24060d01b95ce960a682b081e63b46447218e35d
Author: Gary Gregory <[email protected]>
AuthorDate: Fri Apr 12 10:38:14 2024 -0400
Add a Map-based test
---
.../commons/lang3/stream/FailableStreamTest.java | 26 ++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git
a/src/test/java/org/apache/commons/lang3/stream/FailableStreamTest.java
b/src/test/java/org/apache/commons/lang3/stream/FailableStreamTest.java
index d15714cdc..857f46665 100644
--- a/src/test/java/org/apache/commons/lang3/stream/FailableStreamTest.java
+++ b/src/test/java/org/apache/commons/lang3/stream/FailableStreamTest.java
@@ -22,7 +22,10 @@ import static
org.junit.jupiter.api.Assertions.assertArrayEquals;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
+import java.util.LinkedHashMap;
import java.util.Locale;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import org.apache.commons.lang3.stream.Streams.FailableStream;
@@ -33,6 +36,13 @@ import org.junit.jupiter.api.Test;
*/
public class FailableStreamTest {
+ private Integer failable(final Map.Entry<String, AtomicInteger> value)
throws IOException {
+ if (value == new Object()) {
+ throw new IOException();
+ }
+ return Integer.valueOf(value.getValue().incrementAndGet());
+ }
+
private String failable(final String value) throws IOException {
if (value == new Object()) {
throw new IOException();
@@ -56,6 +66,18 @@ public class FailableStreamTest {
assertArrayEquals(new String[] { "a", "b", "c" },
toArray(Arrays.asList("A", "B", "C")));
}
+ @Test
+ public void testFailableStreamOfMap() {
+ final Map<String, AtomicInteger> map = new LinkedHashMap<>();
+ assertArrayEquals(new Integer[] {}, toArrayMap(map));
+ map.put("a", new AtomicInteger(1));
+ assertArrayEquals(new Integer[] { 2 }, toArrayMap(map));
+ map.put("b", new AtomicInteger(2));
+ assertArrayEquals(new Integer[] { 3, 3 }, toArrayMap(map));
+ map.put("c", new AtomicInteger(3));
+ assertArrayEquals(new Integer[] { 4, 4, 4 }, toArrayMap(map));
+ }
+
private String[] toArray(final Collection<String> strings) {
return
Streams.failableStream(strings).map(this::failable).collect(Collectors.toList()).toArray(new
String[0]);
}
@@ -67,4 +89,8 @@ public class FailableStreamTest {
private String[] toArray(final String... strings) {
return
Streams.failableStream(strings).map(this::failable).collect(Collectors.toList()).toArray(new
String[0]);
}
+
+ private Integer[] toArrayMap(final Map<String, AtomicInteger> map) {
+ return
Streams.failableStream(map.entrySet()).map(this::failable).collect(Collectors.toList()).toArray(new
Integer[0]);
+ }
}