Debian Codegraph @

src/test/java/ezvcard/issue/Issue119.java

raw symbols SCIP
1 package ezvcard.issue;
2
3 import static org.junit.Assert.assertEquals;
4
5 import java.util.ArrayList;
6 import java.util.Arrays;
7 import java.util.List;
8
9 import org.junit.Test;
10
11 import ezvcard.VCard;
12 import ezvcard.VCardVersion;
13 import ezvcard.io.scribe.ScribeIndex;
14 import ezvcard.io.scribe.VCardPropertyScribe;
15 import ezvcard.io.text.WriteContext;
16 import ezvcard.property.Address;
17 import ezvcard.property.FormattedName;
18 import ezvcard.property.VCardProperty;
19
20 /**
21 * @author Michael Angstadt
22 * @see "https://github.com/mangstadt/ez-vcard/issues/119"
23 */
24 @SuppressWarnings({ "rawtypes", "unchecked" })
25 public class Issue119 {
26 @Test
27 public void faq_code_sample() throws Exception {
28 VCard vcard = new VCard();
29 vcard.setFormattedName("value");
30
31 ScribeIndex index = new ScribeIndex();
32 WriteContext context = new WriteContext(VCardVersion.V3_0, null, true);
33
34 List<String> actual = new ArrayList<>();
35 for (VCardProperty property : vcard) {
36 VCardPropertyScribe scribe = index.getPropertyScribe(property); //compiler: raw type warning
37 String name = scribe.getPropertyName();
38 String value = scribe.writeText(property, context); //compiler: type safety warning
39 actual.add(name + " = " + value);
40 }
41
42 List<String> expected = Arrays.asList("FN = value");
43 assertEquals(expected, actual);
44 }
45
46 @Test(expected = ClassCastException.class)
47 public void class_cast_exception() {
48 ScribeIndex index = new ScribeIndex();
49 WriteContext context = new WriteContext(VCardVersion.V3_0, null, true);
50 VCardProperty property = new FormattedName("value");
51 VCardPropertyScribe scribe = index.getPropertyScribe(Address.class); //compiler: raw type warning
52 scribe.writeText(property, context); //compiler: type safety warning; ClassCastException thrown at runtime
53 }
54 }