| 1 |
package ezvcard.issue; |
| 2 |
|
| 3 |
import static org.junit.Assert.assertEquals; |
| 4 |
import static org.junit.Assert.assertTrue; |
| 5 |
|
| 6 |
import org.junit.Test; |
| 7 |
|
| 8 |
import ezvcard.VCard; |
| 9 |
import ezvcard.VCardDataType; |
| 10 |
import ezvcard.VCardVersion; |
| 11 |
import ezvcard.io.ParseContext; |
| 12 |
import ezvcard.io.scribe.VCardPropertyScribe; |
| 13 |
import ezvcard.io.text.VCardReader; |
| 14 |
import ezvcard.io.text.WriteContext; |
| 15 |
import ezvcard.parameter.VCardParameters; |
| 16 |
import ezvcard.property.VCardProperty; |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
public class Issue136 { |
| 23 |
@Test |
| 24 |
public void test() throws Exception { |
| 25 |
String vcardStr = |
| 26 |
"BEGIN:VCARD\r\n" + |
| 27 |
"VERSION:3.0\r\n" + |
| 28 |
"ADR:foo;bar\r\n" + |
| 29 |
"END:VCARD"; |
| 30 |
|
| 31 |
VCard vcard; |
| 32 |
try (VCardReader reader = new VCardReader(vcardStr)) { |
| 33 |
reader.registerScribe(new MarioAddressScribe()); |
| 34 |
vcard = reader.readNext(); |
| 35 |
} |
| 36 |
|
| 37 |
assertTrue(vcard.getAddresses().isEmpty()); |
| 38 |
assertEquals("foo;bar", vcard.getProperty(MarioAddress.class).value); |
| 39 |
} |
| 40 |
|
| 41 |
private static class MarioAddressScribe extends VCardPropertyScribe<MarioAddress> { |
| 42 |
public MarioAddressScribe() { |
| 43 |
super(MarioAddress.class, "ADR"); |
| 44 |
} |
| 45 |
|
| 46 |
@Override |
| 47 |
protected VCardDataType _defaultDataType(VCardVersion version) { |
| 48 |
return null; |
| 49 |
} |
| 50 |
|
| 51 |
@Override |
| 52 |
protected String _writeText(MarioAddress property, WriteContext context) { |
| 53 |
return property.value; |
| 54 |
} |
| 55 |
|
| 56 |
@Override |
| 57 |
protected MarioAddress _parseText(String value, VCardDataType dataType, VCardParameters parameters, ParseContext context) { |
| 58 |
return new MarioAddress(value); |
| 59 |
} |
| 60 |
|
| 61 |
} |
| 62 |
|
| 63 |
private static class MarioAddress extends VCardProperty { |
| 64 |
public String value; |
| 65 |
|
| 66 |
public MarioAddress(String value) { |
| 67 |
this.value = value; |
| 68 |
} |
| 69 |
} |
| 70 |
} |