Debian Codegraph @

src/test/java/ezvcard/parameter/VCardParameterTest.java

raw symbols SCIP
1 package ezvcard.parameter;
2
3 import static org.junit.Assert.assertArrayEquals;
4 import static org.junit.Assert.assertEquals;
5 import static org.junit.Assert.assertFalse;
6 import static org.junit.Assert.assertNull;
7 import static org.junit.Assert.assertTrue;
8 import nl.jqno.equalsverifier.EqualsVerifier;
9
10 import org.junit.Test;
11
12 import ezvcard.SupportedVersions;
13 import ezvcard.VCardVersion;
14
15 /*
16 Copyright (c) 2012-2023, Michael Angstadt
17 All rights reserved.
18
19 Redistribution and use in source and binary forms, with or without
20 modification, are permitted provided that the following conditions are met:
21
22 1. Redistributions of source code must retain the above copyright notice, this
23 list of conditions and the following disclaimer.
24 2. Redistributions in binary form must reproduce the above copyright notice,
25 this list of conditions and the following disclaimer in the documentation
26 and/or other materials provided with the distribution.
27
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
29 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
32 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
33 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 /**
41 * @author Michael Angstadt
42 */
43 public class VCardParameterTest {
44 @Test
45 public void getSupportedVersions() {
46 assertArrayEquals(new VCardVersion[] { VCardVersion.V2_1 }, VCardParameterImpl.ONE.getSupportedVersions());
47 assertArrayEquals(VCardVersion.values(), VCardParameterImpl.TWO.getSupportedVersions());
48 assertArrayEquals(VCardVersion.values(), new VCardParameterImpl("three").getSupportedVersions());
49 }
50
51 @Test
52 public void isSupportedBy() {
53 assertTrue(VCardParameterImpl.ONE.isSupportedBy(VCardVersion.V2_1));
54 assertFalse(VCardParameterImpl.ONE.isSupportedBy(VCardVersion.V3_0));
55 assertFalse(VCardParameterImpl.ONE.isSupportedBy(VCardVersion.V4_0));
56
57 for (VCardVersion version : VCardVersion.values()) {
58 assertTrue(VCardParameterImpl.TWO.isSupportedBy(version));
59 }
60
61 VCardParameterImpl three = new VCardParameterImpl("three");
62 for (VCardVersion version : VCardVersion.values()) {
63 assertTrue(three.isSupportedBy(version));
64 }
65 }
66
67 @Test
68 public void value_to_lowercase() {
69 VCardParameterImpl three = new VCardParameterImpl("THREE");
70 assertEquals("three", three.getValue());
71 }
72
73 @Test
74 public void value_null() {
75 VCardParameterImpl parameter = new VCardParameterImpl(null);
76 assertNull(parameter.getValue());
77 }
78
79 @Test
80 public void equals_contract() {
81 EqualsVerifier.forClass(VCardParameter.class).usingGetClass().verify();
82 }
83
84 private static class VCardParameterImpl extends VCardParameter {
85 @SupportedVersions(VCardVersion.V2_1)
86 public static VCardParameterImpl ONE = new VCardParameterImpl("one");
87
88 @SuppressWarnings("unused")
89 public String instanceField = "value";
90
91 public static VCardParameterImpl TWO = new VCardParameterImpl("two");
92
93 public VCardParameterImpl() {
94 super("value");
95 }
96
97 public VCardParameterImpl(String value) {
98 super(value);
99 }
100 }
101 }