Debian Codegraph @

src/test/java/ezvcard/ValidationWarningsTest.java

raw symbols SCIP
1 package ezvcard;
2
3 import static ezvcard.util.TestUtils.assertSetEquals;
4 import static org.junit.Assert.assertEquals;
5 import static org.junit.Assert.assertFalse;
6 import static org.junit.Assert.assertTrue;
7
8 import java.util.Arrays;
9 import java.util.Collections;
10 import java.util.HashSet;
11 import java.util.List;
12
13 import org.junit.Test;
14
15 import ezvcard.property.VCardProperty;
16 import ezvcard.util.StringUtils;
17
18 /*
19 Copyright (c) 2012-2023, Michael Angstadt
20 All rights reserved.
21
22 Redistribution and use in source and binary forms, with or without
23 modification, are permitted provided that the following conditions are met:
24
25 1. Redistributions of source code must retain the above copyright notice, this
26 list of conditions and the following disclaimer.
27 2. Redistributions in binary form must reproduce the above copyright notice,
28 this list of conditions and the following disclaimer in the documentation
29 and/or other materials provided with the distribution.
30
31 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
32 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
33 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
34 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
35 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
38 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
40 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 */
42
43 /**
44 * @author Michael Angstadt
45 */
46 public class ValidationWarningsTest {
47 @Test
48 public void isEmpty() {
49 ValidationWarnings warnings = new ValidationWarnings();
50 assertTrue(warnings.isEmpty());
51
52 warnings.add(null, new ValidationWarning(0));
53 assertFalse(warnings.isEmpty());
54 }
55
56 @Test
57 public void getByProperty() {
58 ValidationWarnings warnings = new ValidationWarnings();
59
60 ValidationWarning v0 = new ValidationWarning(0);
61 ValidationWarning v1 = new ValidationWarning(1);
62 ValidationWarning v2 = new ValidationWarning(2);
63 ValidationWarning v3 = new ValidationWarning(3);
64
65 warnings.add(new TestProperty1(), v0);
66 warnings.add(new TestProperty1(), v1);
67 warnings.add(new TestProperty2(), v2);
68 warnings.add(null, v3);
69
70 assertSetEquals(new HashSet<>(warnings.getByProperty(TestProperty1.class)), v0, v1);
71 assertEquals(Arrays.asList(v2), warnings.getByProperty(TestProperty2.class));
72 assertEquals(Arrays.asList(v3), warnings.getByProperty(null));
73 assertEquals(Arrays.asList(), warnings.getByProperty(TestProperty3.class));
74 }
75
76 @Test
77 public void toString_() {
78 ValidationWarnings warnings = new ValidationWarnings();
79
80 warnings.add(null, new ValidationWarning("one"));
81 warnings.add(null, new ValidationWarning(2, "two"));
82 warnings.add(new TestProperty1(), new ValidationWarning("three"));
83 warnings.add(new TestProperty1(), new ValidationWarning(4, "four"));
84
85 //@formatter:off
86 List<String> expectedLines = Arrays.asList(
87 "one",
88 "W02: " + Messages.INSTANCE.getValidationWarning(2, "two"),
89 "[TestProperty1] | three",
90 "[TestProperty1] | W04: " + Messages.INSTANCE.getValidationWarning(4, "four")
91 );
92 //@formatter:on
93 Collections.sort(expectedLines);
94
95 String actual = warnings.toString();
96 List<String> actualLines = Arrays.asList(actual.split(StringUtils.NEWLINE));
97 Collections.sort(actualLines);
98
99 assertEquals(expectedLines, actualLines);
100 }
101
102 private class TestProperty1 extends VCardProperty {
103 //empty
104 }
105
106 private class TestProperty2 extends VCardProperty {
107 //empty
108 }
109
110 private class TestProperty3 extends VCardProperty {
111 //empty
112 }
113 }