1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.util;
15
16 import java.util.ArrayList;
17 import java.util.Arrays;
18 import java.util.Collection;
19 import java.util.List;
20
21 import org.junit.jupiter.api.Test;
22
23 import static org.junit.jupiter.api.Assertions.assertTrue;
24
25
26
27
28
29
30 public class StringCollectionUtilTest {
31
32 @Test
33 public void testRetainMatchingWithNoPatterns() throws Exception {
34 Collection<String> values = stringToList("A");
35 StringCollectionUtil.retainMatching(values);
36 assertTrue(values.contains("A"));
37 }
38
39 @Test
40 public void testRetainMatchingWithMatchingPattern() throws Exception {
41 Collection<String> values = stringToList("A");
42 StringCollectionUtil.retainMatching(values, "A");
43 assertTrue(values.contains("A"));
44 }
45
46 @Test
47 public void testRetainMatchingWithNoMatchingPattern() throws Exception {
48 Collection<String> values = stringToList("A");
49 StringCollectionUtil.retainMatching(values, "B");
50 assertTrue(values.isEmpty());
51 }
52
53 @Test
54 public void testRemoveMatchingWithNoPatterns() throws Exception {
55 Collection<String> values = stringToList("A");
56 StringCollectionUtil.removeMatching(values);
57 assertTrue(values.contains("A"));
58 }
59
60 @Test
61 public void testRemoveMatchingWithMatchingPattern() throws Exception {
62 Collection<String> values = stringToList("A");
63 StringCollectionUtil.removeMatching(values, "A");
64 assertTrue(values.isEmpty());
65 }
66
67 @Test
68 public void testRemoveMatchingWithNoMatchingPattern() throws Exception {
69 Collection<String> values = stringToList("A");
70 StringCollectionUtil.removeMatching(values, "B");
71 assertTrue(values.contains("A"));
72 }
73
74 private List<String> stringToList(String... values) {
75 List<String> result = new ArrayList<String>(values.length);
76 result.addAll(Arrays.asList(values));
77 return result;
78 }
79
80 }