| 1 |
package ezvcard.property; |
| 2 |
|
| 3 |
import static org.junit.Assert.assertEquals; |
| 4 |
import static org.junit.Assert.assertTrue; |
| 5 |
import static org.junit.Assert.fail; |
| 6 |
|
| 7 |
import java.util.Arrays; |
| 8 |
import java.util.List; |
| 9 |
|
| 10 |
import org.junit.Test; |
| 11 |
|
| 12 |
import ezvcard.parameter.Pid; |
| 13 |
import ezvcard.parameter.VCardParameters; |
| 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 |
|
| 41 |
|
| 42 |
|
| 43 |
public class PidParameterListTest { |
| 44 |
@Test |
| 45 |
public void get_set() { |
| 46 |
PidParameterListProperty property = new PidParameterListProperty(); |
| 47 |
VCardParameters parameters = property.getParameters(); |
| 48 |
List<Pid> pids = property.getPids(); |
| 49 |
|
| 50 |
pids.add(new Pid(1, 1)); |
| 51 |
parameters.put(VCardParameters.PID, "2"); |
| 52 |
assertEquals(Arrays.asList("1.1", "2"), parameters.get(VCardParameters.PID)); |
| 53 |
assertEquals(Arrays.asList(new Pid(1, 1), new Pid(2)), pids); |
| 54 |
} |
| 55 |
|
| 56 |
@Test |
| 57 |
public void invalid_value() { |
| 58 |
PidParameterListProperty property = new PidParameterListProperty(); |
| 59 |
VCardParameters parameters = property.getParameters(); |
| 60 |
List<Pid> pids = property.getPids(); |
| 61 |
|
| 62 |
parameters.put(VCardParameters.PID, "foobar"); |
| 63 |
try { |
| 64 |
pids.get(0); |
| 65 |
fail(); |
| 66 |
} catch (IllegalStateException e) { |
| 67 |
assertTrue(e.getCause() instanceof NumberFormatException); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
private static class PidParameterListProperty extends VCardProperty { |
| 72 |
@Override |
| 73 |
public List<Pid> getPids() { |
| 74 |
return super.getPids(); |
| 75 |
} |
| 76 |
} |
| 77 |
} |