1
1
package tools .jackson .databind .node ;
2
2
3
- import java .io .*;
4
3
import java .math .BigDecimal ;
5
4
import java .math .BigInteger ;
5
+ import java .util .Arrays ;
6
+ import java .util .stream .Collectors ;
6
7
import java .util .ArrayList ;
7
8
8
9
import org .junit .jupiter .api .Test ;
13
14
import tools .jackson .databind .testutil .DatabindTestUtil ;
14
15
import tools .jackson .databind .util .RawValue ;
15
16
16
- import static java .util .Arrays .asList ;
17
-
18
17
import static org .junit .jupiter .api .Assertions .*;
19
18
20
19
/**
@@ -24,7 +23,7 @@ public class ArrayNodeTest
24
23
extends DatabindTestUtil
25
24
{
26
25
@ Test
27
- public void testDirectCreation () throws IOException
26
+ public void testDirectCreation () throws Exception
28
27
{
29
28
ArrayNode n = new ArrayNode (JsonNodeFactory .instance );
30
29
@@ -108,7 +107,7 @@ public void testDirectCreation() throws IOException
108
107
}
109
108
110
109
@ Test
111
- public void testDirectCreation2 () throws IOException
110
+ public void testDirectCreation2 () throws Exception
112
111
{
113
112
JsonNodeFactory f = objectMapper ().getNodeFactory ();
114
113
ArrayList <JsonNode > list = new ArrayList <>();
@@ -139,7 +138,7 @@ public void testDirectCreation2() throws IOException
139
138
}
140
139
141
140
@ Test
142
- public void testArraySet () throws IOException {
141
+ public void testArraySet () throws Exception {
143
142
final ArrayNode array = JsonNodeFactory .instance .arrayNode ();
144
143
for (int i = 0 ; i < 20 ; i ++) {
145
144
array .add ("Original Data" );
@@ -267,7 +266,7 @@ public void testAddAllWithNullInCollection()
267
266
final ArrayNode array = JsonNodeFactory .instance .arrayNode ();
268
267
269
268
// test
270
- array .addAll (asList (null , JsonNodeFactory .instance .objectNode ()));
269
+ array .addAll (Arrays . asList (null , JsonNodeFactory .instance .objectNode ()));
271
270
272
271
// assertions
273
272
assertEquals (2 , array .size ());
@@ -478,4 +477,28 @@ public void testSimpleMismatch() throws Exception
478
477
verifyException (e , "from Integer value (token `JsonToken.VALUE_NUMBER_INT`)" );
479
478
}
480
479
}
480
+
481
+ // [databind#4863]: valueStream(), entryStream(), forEachEntry()
482
+ @ Test
483
+ public void testStreamMethods ()
484
+ {
485
+ ObjectMapper mapper = objectMapper ();
486
+ ArrayNode arr = mapper .createArrayNode ();
487
+ arr .add (1 ).add ("foo" );
488
+ JsonNode n1 = arr .get (0 );
489
+ JsonNode n2 = arr .get (1 );
490
+
491
+ // First, valueStream() testing
492
+ assertEquals (2 , arr .valueStream ().count ());
493
+ assertEquals (Arrays .asList (n1 , n2 ),
494
+ arr .valueStream ().collect (Collectors .toList ()));
495
+
496
+ // And then entryStream() (empty)
497
+ assertEquals (0 , arr .entryStream ().count ());
498
+ assertEquals (Arrays .asList (),
499
+ arr .entryStream ().collect (Collectors .toList ()));
500
+
501
+ // And then empty forEachEntry()
502
+ arr .forEachEntry ((k , v ) -> { throw new UnsupportedOperationException (); });
503
+ }
481
504
}
0 commit comments