11package com .github .lokic .javaplus ;
22
3+ import com .github .lokic .javaplus .functional .tuple .TupleFlattened ;
4+ import com .github .lokic .javaplus .functional .tuple .TupleFunctional ;
35import com .github .lokic .javaplus .tuple .Tuple ;
46import com .github .lokic .javaplus .tuple .Tuple2 ;
5- import org .assertj .core .api .Assertions ;
6- import org .junit .Test ;
7-
7+ import com .github .lokic .javaplus .tuple .Tuple3 ;
88import java .util .List ;
99import java .util .function .Function ;
1010import java .util .stream .Collectors ;
1111import java .util .stream .Stream ;
12+ import org .assertj .core .api .Assertions ;
13+ import org .junit .Test ;
1214
1315public class JoinTest {
1416
1517 @ Test
1618 public void test_innerJoin () {
17- List <Tuple2 <Integer , String >> list = Join .innerJoin (Stream .of (1 , 2 , 3 , 4 ), Stream .of ("2" , "3" , "5" ))
18- .on (String ::valueOf , Function .identity ())
19+ List <Tuple2 <Integer , String >> list = Join .innerJoin (Stream .of (1 , 2 , 3 , 4 ),
20+ Stream .of ("2" , "3" , "5" ))
21+ .on (String ::valueOf , Function .identity ())
22+ .stream ()
1923 .collect (Collectors .toList ());
2024
2125 Assertions .assertThat (list )
@@ -24,8 +28,10 @@ public void test_innerJoin() {
2428
2529 @ Test
2630 public void test_innerJoin_repeatKey () {
27- List <Tuple2 <Integer , String >> list = Join .innerJoin (Stream .of (1 , 2 , 2 , 3 , 4 ), Stream .of ("2" , "3" , "5" ))
28- .on (String ::valueOf , Function .identity ())
31+ List <Tuple2 <Integer , String >> list = Join .innerJoin (Stream .of (1 , 2 , 2 , 3 , 4 ),
32+ Stream .of ("2" , "3" , "5" ))
33+ .on (String ::valueOf , Function .identity ())
34+ .stream ()
2935 .collect (Collectors .toList ());
3036
3137 Assertions .assertThat (list )
@@ -34,8 +40,10 @@ public void test_innerJoin_repeatKey() {
3440
3541 @ Test
3642 public void test_leftOuterJoin () {
37- List <Tuple2 <Integer , String >> list = Join .leftOuterJoin (Stream .of (1 , 2 , 3 , 4 ), Stream .of ("2" , "3" , "5" ))
38- .on (String ::valueOf , Function .identity ())
43+ List <Tuple2 <Integer , String >> list = Join .leftOuterJoin (Stream .of (1 , 2 , 3 , 4 ),
44+ Stream .of ("2" , "3" , "5" ))
45+ .on (String ::valueOf , Function .identity ())
46+ .stream ()
3947 .collect (Collectors .toList ());
4048
4149 Assertions .assertThat (list )
@@ -44,8 +52,10 @@ public void test_leftOuterJoin() {
4452
4553 @ Test
4654 public void test_leftOuterJoin_empty () {
47- List <Tuple2 <Integer , String >> list = Join .leftOuterJoin (Stream .of (1 , 2 , 3 , 4 ), Stream .<String >empty ())
48- .on (String ::valueOf , Function .identity ())
55+ List <Tuple2 <Integer , String >> list = Join .leftOuterJoin (Stream .of (1 , 2 , 3 , 4 ),
56+ Stream .<String >empty ())
57+ .on (String ::valueOf , Function .identity ())
58+ .stream ()
4959 .collect (Collectors .toList ());
5060
5161 Assertions .assertThat (list )
@@ -54,8 +64,10 @@ public void test_leftOuterJoin_empty() {
5464
5565 @ Test
5666 public void test_rightOuterJoin () {
57- List <Tuple2 <Integer , String >> list = Join .rightOuterJoin (Stream .of (1 , 2 , 3 , 4 ), Stream .of ("2" , "3" , "5" ))
58- .on (String ::valueOf , Function .identity ())
67+ List <Tuple2 <Integer , String >> list = Join .rightOuterJoin (Stream .of (1 , 2 , 3 , 4 ),
68+ Stream .of ("2" , "3" , "5" ))
69+ .on (String ::valueOf , Function .identity ())
70+ .stream ()
5971 .collect (Collectors .toList ());
6072
6173 Assertions .assertThat (list )
@@ -65,12 +77,32 @@ public void test_rightOuterJoin() {
6577
6678 @ Test
6779 public void test_fullOuterJoin () {
68- List <Tuple2 <Integer , String >> list = Join .fullOuterJoin (Stream .of (1 , 2 , 3 , 4 ), Stream .of ("2" , "3" , "5" ))
80+ List <Tuple2 <Integer , String >> list = Join .fullOuterJoin (Stream .of (1 , 2 , 3 , 4 ),
81+ Stream .of ("2" , "3" , "5" ))
82+ .on (String ::valueOf , Function .identity ())
83+ .stream ()
84+ .collect (Collectors .toList ());
85+
86+ Assertions .assertThat (list )
87+ .containsExactly (Tuple .of (1 , null ), Tuple .of (2 , "2" ), Tuple .of (3 , "3" ),
88+ Tuple .of (4 , null ), Tuple .of (null , "5" ));
89+ }
90+
91+ @ Test
92+ public void test_joinStream_leftOuterJoin () {
93+ List <Tuple3 <Integer , String , String >> list =
94+ Join .leftOuterJoin (Stream .of (1 , 2 , 3 , 4 ), Stream .of ("2" , "3" , "5" ))
6995 .on (String ::valueOf , Function .identity ())
96+ .leftOuterJoin (Stream .of ("1" ))
97+ .on (TupleFunctional .function ((a , b ) -> String .valueOf (a )), Function .identity ())
98+ .flattenStream (TupleFlattened ::flatten3 )
7099 .collect (Collectors .toList ());
71100
72101 Assertions .assertThat (list )
73- .containsExactly (Tuple .of (1 , null ), Tuple .of (2 , "2" ), Tuple .of (3 , "3" ), Tuple .of (4 , null ), Tuple .of (null , "5" ));
102+ .containsExactly (
103+ Tuple .of (1 , null , "1" ),
104+ Tuple .of (2 , "2" , null ),
105+ Tuple .of (3 , "3" , null ),
106+ Tuple .of (4 , null , null ));
74107 }
75-
76108}
0 commit comments