| 1 |
package ezvcard.parameter; |
| 2 |
|
| 3 |
import static ezvcard.util.TestUtils.assertEqualsAndHash; |
| 4 |
import static ezvcard.util.TestUtils.assertEqualsMethodEssentials; |
| 5 |
import static ezvcard.util.TestUtils.assertIntEquals; |
| 6 |
import static ezvcard.util.TestUtils.assertNothingIsEqual; |
| 7 |
import static org.junit.Assert.assertEquals; |
| 8 |
import static org.junit.Assert.assertNull; |
| 9 |
|
| 10 |
import org.junit.Test; |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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 |
public class PidTest { |
| 41 |
@Test(expected = NullPointerException.class) |
| 42 |
public void null_local_id() { |
| 43 |
new Pid(null); |
| 44 |
} |
| 45 |
|
| 46 |
@Test |
| 47 |
public void constructor() { |
| 48 |
Pid pid = new Pid(1); |
| 49 |
assertIntEquals(1, pid.getLocalId()); |
| 50 |
assertNull(pid.getClientPidMapReference()); |
| 51 |
|
| 52 |
pid = new Pid(1, 2); |
| 53 |
assertIntEquals(1, pid.getLocalId()); |
| 54 |
assertIntEquals(2, pid.getClientPidMapReference()); |
| 55 |
} |
| 56 |
|
| 57 |
@Test |
| 58 |
public void toString_() { |
| 59 |
Pid pid = new Pid(1, 2); |
| 60 |
assertEquals("1.2", pid.toString()); |
| 61 |
|
| 62 |
pid = new Pid(1); |
| 63 |
assertEquals("1", pid.toString()); |
| 64 |
} |
| 65 |
|
| 66 |
@Test |
| 67 |
public void valueOf() { |
| 68 |
Pid expected = new Pid(1, 2); |
| 69 |
Pid actual = Pid.valueOf("1.2"); |
| 70 |
assertEquals(expected, actual); |
| 71 |
|
| 72 |
expected = new Pid(1); |
| 73 |
actual = Pid.valueOf("1."); |
| 74 |
assertEquals(expected, actual); |
| 75 |
|
| 76 |
expected = new Pid(1); |
| 77 |
actual = Pid.valueOf("1"); |
| 78 |
assertEquals(expected, actual); |
| 79 |
} |
| 80 |
|
| 81 |
@Test(expected = NumberFormatException.class) |
| 82 |
public void valueOf_invalid() { |
| 83 |
Pid.valueOf("1.foo"); |
| 84 |
} |
| 85 |
|
| 86 |
@Test(expected = NumberFormatException.class) |
| 87 |
public void valueOf_more_than_one_dot() { |
| 88 |
Pid.valueOf("1.2.2"); |
| 89 |
} |
| 90 |
|
| 91 |
@Test |
| 92 |
public void equals() { |
| 93 |
Pid pid = new Pid(1, 2); |
| 94 |
assertEqualsMethodEssentials(pid); |
| 95 |
|
| 96 |
|
| 97 |
assertNothingIsEqual( |
| 98 |
new Pid(1), |
| 99 |
new Pid(2), |
| 100 |
new Pid(1,2), |
| 101 |
new Pid(2,2), |
| 102 |
new Pid(2,3) |
| 103 |
); |
| 104 |
|
| 105 |
|
| 106 |
Pid one = new Pid(1); |
| 107 |
Pid two = new Pid(1); |
| 108 |
assertEqualsAndHash(one, two); |
| 109 |
|
| 110 |
one = new Pid(1, 2); |
| 111 |
two = new Pid(1, 2); |
| 112 |
assertEqualsAndHash(one, two); |
| 113 |
} |
| 114 |
} |