| 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 org.junit.Test; |
| 12 |
|
| 13 |
import ezvcard.VCard; |
| 14 |
import ezvcard.VCardVersion; |
| 15 |
|
| 16 |
|
| 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 |
|
| 47 |
|
| 48 |
public class AgentTest { |
| 49 |
@Test |
| 50 |
public void set_value() { |
| 51 |
VCard vcard = new VCard(); |
| 52 |
Agent agent = new Agent(); |
| 53 |
|
| 54 |
agent.setUrl("one"); |
| 55 |
assertEquals("one", agent.getUrl()); |
| 56 |
assertNull(agent.getVCard()); |
| 57 |
|
| 58 |
agent.setVCard(vcard); |
| 59 |
assertNull(agent.getUrl()); |
| 60 |
assertEquals(vcard, agent.getVCard()); |
| 61 |
|
| 62 |
agent.setUrl("one"); |
| 63 |
assertEquals("one", agent.getUrl()); |
| 64 |
assertNull(agent.getVCard()); |
| 65 |
} |
| 66 |
|
| 67 |
@Test |
| 68 |
public void constructors() { |
| 69 |
VCard vcard = new VCard(); |
| 70 |
Agent agent = new Agent(); |
| 71 |
assertNull(agent.getUrl()); |
| 72 |
assertNull(agent.getVCard()); |
| 73 |
|
| 74 |
agent = new Agent("one"); |
| 75 |
assertEquals("one", agent.getUrl()); |
| 76 |
assertNull(agent.getVCard()); |
| 77 |
|
| 78 |
agent = new Agent(vcard); |
| 79 |
assertNull(agent.getUrl()); |
| 80 |
assertEquals(vcard, agent.getVCard()); |
| 81 |
} |
| 82 |
|
| 83 |
@Test |
| 84 |
public void validate() { |
| 85 |
Agent property = new Agent(); |
| 86 |
assertValidate(property).versions(VCardVersion.V2_1, VCardVersion.V3_0).run(8); |
| 87 |
assertValidate(property).versions(VCardVersion.V4_0).run(8, 2); |
| 88 |
|
| 89 |
VCard agentVCard = new VCard(); |
| 90 |
property.setVCard(agentVCard); |
| 91 |
assertValidate(property).versions(VCardVersion.V2_1).run(10); |
| 92 |
assertValidate(property).versions(VCardVersion.V3_0).run(10, 10); |
| 93 |
assertValidate(property).versions(VCardVersion.V4_0).run(10, 2); |
| 94 |
|
| 95 |
property.setUrl("http://example.com"); |
| 96 |
assertValidate(property).versions(VCardVersion.V2_1, VCardVersion.V3_0).run(); |
| 97 |
assertValidate(property).versions(VCardVersion.V4_0).run(2); |
| 98 |
} |
| 99 |
|
| 100 |
@Test |
| 101 |
public void toStringValues() { |
| 102 |
Agent property = new Agent(); |
| 103 |
assertFalse(property.toStringValues().isEmpty()); |
| 104 |
} |
| 105 |
|
| 106 |
@Test |
| 107 |
public void copy() { |
| 108 |
Agent original = new Agent(); |
| 109 |
assertCopy(original); |
| 110 |
|
| 111 |
original = new Agent("url"); |
| 112 |
assertCopy(original); |
| 113 |
|
| 114 |
original = new Agent(new VCard()); |
| 115 |
assertCopy(original).notSame("getVCard"); |
| 116 |
} |
| 117 |
|
| 118 |
@Test |
| 119 |
public void equals() { |
| 120 |
VCard vcard = new VCard(); |
| 121 |
VCard vcard2 = new VCard(); |
| 122 |
vcard2.setVersion(VCardVersion.V4_0); |
| 123 |
|
| 124 |
|
| 125 |
assertNothingIsEqual( |
| 126 |
new Agent(), |
| 127 |
new Agent("url"), |
| 128 |
new Agent("url2"), |
| 129 |
new Agent(vcard), |
| 130 |
new Agent(vcard2) |
| 131 |
); |
| 132 |
|
| 133 |
assertEqualsMethod(Agent.class) |
| 134 |
.constructor().test() |
| 135 |
.constructor("url") |
| 136 |
.test() |
| 137 |
.test(new Agent(new VCard()), new Agent(new VCard())); |
| 138 |
|
| 139 |
} |
| 140 |
} |