| 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 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 104 |
} |
| 105 |
|
| 106 |
private class TestProperty2 extends VCardProperty { |
| 107 |
|
| 108 |
} |
| 109 |
|
| 110 |
private class TestProperty3 extends VCardProperty { |
| 111 |
|
| 112 |
} |
| 113 |
} |