Debian Codegraph @

src/test/java/ezvcard/io/scribe/EmailScribeTest.java

raw symbols SCIP
1 package ezvcard.io.scribe;
2
3 import static ezvcard.VCardVersion.V2_1;
4 import static ezvcard.VCardVersion.V3_0;
5 import static ezvcard.VCardVersion.V4_0;
6
7 import org.junit.Test;
8
9 import ezvcard.VCard;
10 import ezvcard.parameter.EmailType;
11 import ezvcard.property.Email;
12
13 /*
14 Copyright (c) 2012-2023, Michael Angstadt
15 All rights reserved.
16
17 Redistribution and use in source and binary forms, with or without
18 modification, are permitted provided that the following conditions are met:
19
20 1. Redistributions of source code must retain the above copyright notice, this
21 list of conditions and the following disclaimer.
22 2. Redistributions in binary form must reproduce the above copyright notice,
23 this list of conditions and the following disclaimer in the documentation
24 and/or other materials provided with the distribution.
25
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
27 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
30 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
33 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
37 The views and conclusions contained in the software and documentation are those
38 of the authors and should not be interpreted as representing official policies,
39 either expressed or implied, of the FreeBSD Project.
40 */
41
42 /**
43 * @author Michael Angstadt
44 */
45 public class EmailScribeTest {
46 private final EmailScribe scribe = new EmailScribe();
47 private final Sensei<Email> sensei = new Sensei<>(scribe);
48
49 @Test
50 public void prepareParameters_type_pref() {
51 Email property = new Email("[email protected]");
52 property.getTypes().add(EmailType.PREF);
53
54 sensei.assertPrepareParams(property).versions(V2_1, V3_0).expected("TYPE", "pref").run();
55 sensei.assertPrepareParams(property).versions(V4_0).expected("PREF", "1").run();
56 }
57
58 @Test
59 public void prepareParameters_pref_parameter() {
60 Email property = new Email("[email protected]");
61 property.setPref(1);
62
63 VCard vcard = new VCard();
64 vcard.addEmail(property);
65
66 sensei.assertPrepareParams(property).versions(V2_1, V3_0).vcard(vcard).expected("TYPE", "pref").run();
67 sensei.assertPrepareParams(property).versions(V4_0).vcard(vcard).expected("PREF", "1").run();
68 }
69
70 @Test
71 public void parseText() {
72 Email expected = new Email("[email protected]");
73 sensei.assertParseText("[email protected]").run(expected);
74 }
75
76 @Test
77 public void parseHtml() {
78 Email expected = new Email("[email protected]");
79
80 //@formatter:off
81 sensei.assertParseHtml(
82 "<a href=\"mailto:[email protected]\">Email Me</a>"
83 ).run(expected);
84
85 sensei.assertParseHtml(
86 "<a href=\"MAILTO:[email protected]\">Email Me</a>"
87 ).run(expected);
88
89 sensei.assertParseHtml(
90 "<a href=\"http://www.example.com\">[email protected]</a>"
91 ).run(expected);
92
93 sensei.assertParseHtml(
94 "<div>[email protected]</div>"
95 ).run(expected);
96 //@formatter:on
97 }
98
99 @Test
100 public void parseHtml_types() {
101 Email expected = new Email("[email protected]");
102 expected.getTypes().add(EmailType.HOME);
103
104 //@formatter:off
105 sensei.assertParseHtml(
106 "<a href=\"mailto:[email protected]\">" +
107 "<span class=\"type\">Home</span> Email" +
108 "</a>"
109 ).run(expected);
110 //@formatter:on
111 }
112 }