Refactor of Intersection class
[vid.git] / vid-app-common / src / test / java / org / onap / vid / testUtils / IntersectionTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2018 Nokia. All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.vid.testUtils;
23
24 import org.junit.Test;
25 import org.onap.vid.utils.Intersection;
26
27 import java.util.List;
28
29 import static org.assertj.core.api.Assertions.assertThat;
30 import static org.assertj.core.util.Lists.emptyList;
31 import static org.assertj.core.util.Lists.list;
32
33 public class IntersectionTest {
34
35     @Test
36     public void testFourArrays() {
37         // given
38         List<List<String>> input = list(
39                 list("1", "2"),
40                 list("2", "3"),
41                 list("2", "4"),
42                 list("2", "5")
43         );
44         // when
45         List<String> output = Intersection.of(input);
46         // then
47         assertThat(output).containsExactlyInAnyOrder("2");
48
49     }
50
51     @Test
52     public void testTwoArrays() {
53         // given
54         List<List<String>> input = list(
55                 list("1", "2"),
56                 list("2", "3")
57         );
58         // when
59         List<String> output = Intersection.of(input);
60         // then
61         assertThat(output).containsExactlyInAnyOrder("2");
62
63     }
64
65
66     @Test
67     public void testNoIntersection() {
68         // given
69         List<List<String>> input = list(
70                 list("1", "2"),
71                 list("3", "4")
72         );
73         // when
74         List<String> output = Intersection.of(input);
75         // then
76         assertThat(output).isEmpty();
77
78     }
79
80     @Test
81     public void testOneArray() {
82         // given
83         List<List<String>> input = list(list("1", "2"));
84         // when
85         List<String> output = Intersection.of(input);
86         // then
87         assertThat(output).containsExactlyInAnyOrder("1", "2");
88     }
89
90     @Test
91     public void testEmptyInput() {
92         // when
93         List<String> output = Intersection.of(emptyList());
94         // then
95         assertThat(output).isEmpty();
96     }
97
98     @Test
99     public void shouldIgnoreRepetitions() {
100         // when
101         List<String> output = Intersection.of(list(
102                 list("1", "1"),
103                 list("1", "1")
104         ));
105         // then
106         assertThat(output).containsExactly("1");
107     }
108 }