1
1
/*
2
- * Copyright 2020-2021 the original author or authors.
2
+ * Copyright 2020-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
20
20
import java .util .Arrays ;
21
21
import java .util .Iterator ;
22
22
import java .util .stream .Collectors ;
23
+ import java .util .stream .IntStream ;
23
24
24
25
import org .junit .jupiter .api .Test ;
25
26
@@ -33,18 +34,48 @@ class CloseableIteratorUnitTests {
33
34
@ Test // DATACMNS-1637
34
35
void shouldCreateStream () {
35
36
36
- var iterator = new CloseableIteratorImpl <String >(Arrays .asList ("1" , "2" , "3" ).iterator ());
37
+ var iterator = new CloseableIteratorImpl <>(Arrays .asList ("1" , "2" , "3" ).iterator ());
37
38
38
39
var collection = iterator .stream ().map (it -> "hello " + it ).collect (Collectors .toList ());
39
40
40
41
assertThat (collection ).contains ("hello 1" , "hello 2" , "hello 3" );
41
42
assertThat (iterator .closed ).isFalse ();
42
43
}
43
44
45
+ @ Test // GH-2519
46
+ void shouldCount () {
47
+
48
+ var iterator = new CloseableIteratorImpl <>(Arrays .asList ("1" , "2" , "3" ).iterator ());
49
+
50
+ var count = iterator .stream ().count ();
51
+
52
+ assertThat (count ).isEqualTo (3 );
53
+ }
54
+
55
+ @ Test // GH-2519
56
+ void shouldCountLargeStream () {
57
+
58
+ var iterator = new CloseableIteratorImpl <>(IntStream .range (0 , 2048 ).boxed ().iterator ());
59
+
60
+ var count = iterator .stream ().count ();
61
+
62
+ assertThat (count ).isEqualTo (2048 );
63
+ }
64
+
65
+ @ Test // GH-2519
66
+ void shouldApplyToList () {
67
+
68
+ var iterator = new CloseableIteratorImpl <>(Arrays .asList ("1" , "2" , "3" ).iterator ());
69
+
70
+ var list = iterator .stream ().toList ();
71
+
72
+ assertThat (list ).isEqualTo (Arrays .asList ("1" , "2" , "3" ));
73
+ }
74
+
44
75
@ Test // DATACMNS-1637
45
76
void closeStreamShouldCloseIterator () {
46
77
47
- var iterator = new CloseableIteratorImpl <String >(Arrays .asList ("1" , "2" , "3" ).iterator ());
78
+ var iterator = new CloseableIteratorImpl <>(Arrays .asList ("1" , "2" , "3" ).iterator ());
48
79
49
80
try (var stream = iterator .stream ()) {
50
81
assertThat (stream .findFirst ()).hasValue ("1" );
0 commit comments