| 1 |
package ezvcard.property; |
| 2 |
|
| 3 |
import static ezvcard.property.PropertySensei.assertCopy; |
| 4 |
import static ezvcard.property.PropertySensei.assertEqualsMethod; |
| 5 |
import static ezvcard.property.PropertySensei.assertNothingIsEqual; |
| 6 |
import static ezvcard.property.PropertySensei.assertValidate; |
| 7 |
import static org.junit.Assert.assertEquals; |
| 8 |
import static org.junit.Assert.assertFalse; |
| 9 |
import static org.junit.Assert.assertNull; |
| 10 |
|
| 11 |
import java.util.ArrayList; |
| 12 |
import java.util.Arrays; |
| 13 |
import java.util.List; |
| 14 |
|
| 15 |
import org.junit.Test; |
| 16 |
|
| 17 |
import ezvcard.VCardVersion; |
| 18 |
import ezvcard.parameter.TelephoneType; |
| 19 |
import ezvcard.util.TelUri; |
| 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 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public class TelephoneTest { |
| 54 |
@Test |
| 55 |
public void constructors() throws Exception { |
| 56 |
Telephone property = new Telephone((String) null); |
| 57 |
assertNull(property.getText()); |
| 58 |
assertNull(property.getUri()); |
| 59 |
assertEquals(Arrays.asList(), property.getTypes()); |
| 60 |
|
| 61 |
property = new Telephone("text"); |
| 62 |
assertEquals("text", property.getText()); |
| 63 |
assertNull(property.getUri()); |
| 64 |
assertEquals(Arrays.asList(), property.getTypes()); |
| 65 |
|
| 66 |
property = new Telephone(new TelUri.Builder("+1").build()); |
| 67 |
assertNull(property.getText()); |
| 68 |
assertEquals(new TelUri.Builder("+1").build(), property.getUri()); |
| 69 |
assertEquals(Arrays.asList(), property.getTypes()); |
| 70 |
} |
| 71 |
|
| 72 |
@Test |
| 73 |
public void set_value() { |
| 74 |
Telephone property = new Telephone((String) null); |
| 75 |
|
| 76 |
property.setText("text"); |
| 77 |
assertEquals("text", property.getText()); |
| 78 |
assertNull(property.getUri()); |
| 79 |
assertEquals(Arrays.asList(), property.getTypes()); |
| 80 |
|
| 81 |
property.setUri(new TelUri.Builder("+1").build()); |
| 82 |
assertNull(property.getText()); |
| 83 |
assertEquals(new TelUri.Builder("+1").build(), property.getUri()); |
| 84 |
assertEquals(Arrays.asList(), property.getTypes()); |
| 85 |
|
| 86 |
property.setText("text"); |
| 87 |
assertEquals("text", property.getText()); |
| 88 |
assertNull(property.getUri()); |
| 89 |
assertEquals(Arrays.asList(), property.getTypes()); |
| 90 |
|
| 91 |
property.getTypes().add(TelephoneType.WORK); |
| 92 |
assertEquals("text", property.getText()); |
| 93 |
assertNull(property.getUri()); |
| 94 |
assertEquals(Arrays.asList(TelephoneType.WORK), property.getTypes()); |
| 95 |
|
| 96 |
property.getTypes().add(TelephoneType.HOME); |
| 97 |
assertEquals("text", property.getText()); |
| 98 |
assertNull(property.getUri()); |
| 99 |
assertEquals(Arrays.asList(TelephoneType.WORK, TelephoneType.HOME), property.getTypes()); |
| 100 |
|
| 101 |
property.getTypes().remove(TelephoneType.HOME); |
| 102 |
assertEquals("text", property.getText()); |
| 103 |
assertNull(property.getUri()); |
| 104 |
assertEquals(Arrays.asList(TelephoneType.WORK), property.getTypes()); |
| 105 |
} |
| 106 |
|
| 107 |
@Test |
| 108 |
public void validate() { |
| 109 |
Telephone empty = new Telephone((String) null); |
| 110 |
assertValidate(empty).run(8); |
| 111 |
|
| 112 |
Telephone withText = new Telephone("(800) 555-5555"); |
| 113 |
assertValidate(withText).run(); |
| 114 |
|
| 115 |
Telephone withUri = new Telephone(new TelUri.Builder("+1-800-555-5555").extension("101").build()); |
| 116 |
assertValidate(withUri).versions(VCardVersion.V2_1).run(19); |
| 117 |
assertValidate(withUri).versions(VCardVersion.V3_0).run(19); |
| 118 |
assertValidate(withUri).versions(VCardVersion.V4_0).run(); |
| 119 |
|
| 120 |
Telephone withTypes = new Telephone("(800) 555-5555"); |
| 121 |
withTypes.getTypes().add(TelephoneType.TEXTPHONE); |
| 122 |
withTypes.getTypes().add(TelephoneType.PREF); |
| 123 |
assertValidate(withTypes).versions(VCardVersion.V2_1, VCardVersion.V3_0).run(9); |
| 124 |
assertValidate(withTypes).versions(VCardVersion.V4_0).run(); |
| 125 |
} |
| 126 |
|
| 127 |
@Test |
| 128 |
public void toStringValues() { |
| 129 |
Telephone property = new Telephone("text"); |
| 130 |
assertFalse(property.toStringValues().isEmpty()); |
| 131 |
} |
| 132 |
|
| 133 |
@Test |
| 134 |
public void copy() { |
| 135 |
Telephone original = new Telephone((String) null); |
| 136 |
assertCopy(original); |
| 137 |
|
| 138 |
original = new Telephone("text"); |
| 139 |
assertCopy(original); |
| 140 |
|
| 141 |
original = new Telephone(new TelUri.Builder("+1").build()); |
| 142 |
assertCopy(original); |
| 143 |
|
| 144 |
original = new Telephone("text"); |
| 145 |
original.getTypes().add(TelephoneType.HOME); |
| 146 |
assertCopy(original); |
| 147 |
} |
| 148 |
|
| 149 |
@Test |
| 150 |
public void equals() { |
| 151 |
List<VCardProperty> properties = new ArrayList<>(); |
| 152 |
|
| 153 |
Telephone property = new Telephone((String) null); |
| 154 |
properties.add(property); |
| 155 |
|
| 156 |
property = new Telephone("text"); |
| 157 |
properties.add(property); |
| 158 |
|
| 159 |
property = new Telephone("text"); |
| 160 |
property.getTypes().add(TelephoneType.HOME); |
| 161 |
properties.add(property); |
| 162 |
|
| 163 |
property = new Telephone("text2"); |
| 164 |
properties.add(property); |
| 165 |
|
| 166 |
property = new Telephone(new TelUri.Builder("+1").build()); |
| 167 |
properties.add(property); |
| 168 |
|
| 169 |
property = new Telephone(new TelUri.Builder("+1").build()); |
| 170 |
property.getTypes().add(TelephoneType.HOME); |
| 171 |
properties.add(property); |
| 172 |
|
| 173 |
property = new Telephone(new TelUri.Builder("+2").build()); |
| 174 |
properties.add(property); |
| 175 |
|
| 176 |
assertNothingIsEqual(properties); |
| 177 |
|
| 178 |
|
| 179 |
assertEqualsMethod(Telephone.class, "text") |
| 180 |
.constructor(new Class<?>[]{String.class}, (String)null).test() |
| 181 |
.constructor("text").test() |
| 182 |
.constructor(new TelUri.Builder("+1").build()).test(); |
| 183 |
|
| 184 |
} |
| 185 |
} |