Debian Codegraph @

src/test/java/ezvcard/io/html/HCardParserTest.java

raw symbols SCIP
1 package ezvcard.io.html;
2
3 import static ezvcard.VCardVersion.V3_0;
4 import static ezvcard.util.TestUtils.assertNoMoreVCards;
5 import static ezvcard.util.TestUtils.assertParseWarnings;
6 import static ezvcard.util.TestUtils.assertPropertyCount;
7 import static ezvcard.util.TestUtils.assertVersion;
8 import static org.junit.Assert.assertEquals;
9
10 import java.util.List;
11
12 import org.junit.Test;
13
14 import ezvcard.VCard;
15 import ezvcard.io.LuckyNumProperty;
16 import ezvcard.io.LuckyNumProperty.LuckyNumScribe;
17 import ezvcard.io.MyFormattedNameProperty;
18 import ezvcard.io.MyFormattedNameProperty.MyFormattedNameScribe;
19 import ezvcard.io.scribe.CannotParseScribe;
20 import ezvcard.io.scribe.SkipMeScribe;
21 import ezvcard.parameter.AddressType;
22 import ezvcard.parameter.TelephoneType;
23 import ezvcard.property.Categories;
24 import ezvcard.property.FormattedName;
25 import ezvcard.property.Label;
26 import ezvcard.property.Nickname;
27 import ezvcard.property.Organization;
28 import ezvcard.property.Source;
29 import ezvcard.property.Url;
30 import ezvcard.property.asserter.VCardAsserter;
31 import ezvcard.util.TelUri;
32
33 /*
34 Copyright (c) 2012-2023, Michael Angstadt
35 All rights reserved.
36
37 Redistribution and use in source and binary forms, with or without
38 modification, are permitted provided that the following conditions are met:
39
40 1. Redistributions of source code must retain the above copyright notice, this
41 list of conditions and the following disclaimer.
42 2. Redistributions in binary form must reproduce the above copyright notice,
43 this list of conditions and the following disclaimer in the documentation
44 and/or other materials provided with the distribution.
45
46 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
47 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
48 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
49 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
50 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
51 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
52 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
53 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
54 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
55 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56
57 The views and conclusions contained in the software and documentation are those
58 of the authors and should not be interpreted as representing official policies,
59 either expressed or implied, of the FreeBSD Project.
60 */
61
62 /**
63 * @author Michael Angstadt
64 */
65 public class HCardParserTest {
66 @Test
67 public void html_without_vcard() throws Exception {
68 //@formatter:off
69 VCardAsserter asserter = readHtml(
70 "<html>" +
71 "<body></body>" +
72 "</html>"
73 );
74 //@formatter:on
75
76 asserter.done();
77 }
78
79 @Test
80 public void empty_vcard() throws Exception {
81 //@formatter:off
82 VCardAsserter asserter = readHtml(
83 "<html>" +
84 "<body>" +
85 "<div class=\"vcard\" />" +
86 "</body>" +
87 "</html>"
88 );
89 //@formatter:on
90
91 asserter.next(V3_0);
92 asserter.done();
93 }
94
95 @Test
96 public void vcard_element_has_other_classes() throws Exception {
97 //@formatter:off
98 VCardAsserter asserter = readHtml(
99 "<html>" +
100 "<body>" +
101 "<div class=\"foo bar vcard\">" +
102 "<span class=\"fn\">John Doe</span>" +
103 "</div>" +
104 "</body>" +
105 "</html>"
106 );
107
108 asserter.next(V3_0);
109
110 asserter.simpleProperty(FormattedName.class)
111 .value("John Doe")
112 .noMore();
113
114 asserter.done();
115 //@formatter:on
116 }
117
118 @Test
119 public void case_insensitive_property_names() throws Exception {
120 //@formatter:off
121 VCardAsserter asserter = readHtml(
122 "<html>" +
123 "<body>" +
124 "<div class=\"vcard\">" +
125 "<span class=\"fN\">John Doe</span>" +
126 "</div>" +
127 "</body>" +
128 "</html>"
129 );
130
131 asserter.next(V3_0);
132
133 asserter.simpleProperty(FormattedName.class)
134 .value("John Doe")
135 .noMore();
136
137 asserter.done();
138 //@formatter:on
139 }
140
141 @Test
142 public void single_tag_with_multiple_properties() throws Exception {
143 //@formatter:off
144 VCardAsserter asserter = readHtml(
145 "<html>" +
146 "<body>" +
147 "<div class=\"vcard\">" +
148 "<a class=\"fn url\" href=\"http://johndoe.com\">John Doe</span>" +
149 "</div>" +
150 "</body>" +
151 "</html>"
152 );
153
154 asserter.next(V3_0);
155
156 asserter.simpleProperty(FormattedName.class)
157 .value("John Doe")
158 .noMore();
159
160 asserter.simpleProperty(Url.class)
161 .value("http://johndoe.com")
162 .noMore();
163
164 asserter.done();
165 //@formatter:on
166 }
167
168 @Test
169 public void property_tags_are_not_direct_children_of_root_tag() throws Exception {
170 //@formatter:off
171 VCardAsserter asserter = readHtml(
172 "<html>" +
173 "<body>" +
174 "<div class=\"vcard\">" +
175 "<h1>Welcome to my webpage</h1>" +
176 "<table>" +
177 "<tr>" +
178 "<td>" +
179 "<a class=\"fn url\" href=\"http://johndoe.com\">John Doe</span>" +
180 "</td>" +
181 "<td>" +
182 "<span class=\"tel\">(555) 555-1234</span>" +
183 "</td>" +
184 "</tr>" +
185 "</table>" +
186 "</div>" +
187 "</body>" +
188 "</html>"
189 );
190
191 asserter.next(V3_0);
192
193 asserter.simpleProperty(FormattedName.class)
194 .value("John Doe")
195 .noMore();
196
197 asserter.simpleProperty(Url.class)
198 .value("http://johndoe.com")
199 .noMore();
200
201 asserter.telephone()
202 .text("(555) 555-1234")
203 .noMore();
204
205 asserter.done();
206 //@formatter:on
207 }
208
209 @Test
210 public void property_tags_within_other_property_tags() throws Exception {
211 //@formatter:off
212 VCardAsserter asserter = readHtml(
213 "<html>" +
214 "<body>" +
215 "<div class=\"vcard\">" +
216 "<div class=\"n\">" +
217 "<span class=\"family-name org\">Smith</span>" +
218 "</div>" +
219 "</div>" +
220 "</body>" +
221 "</html>"
222 );
223
224 asserter.next(V3_0);
225
226 asserter.structuredName()
227 .family("Smith")
228 .noMore();
229
230 asserter.listProperty(Organization.class)
231 .values("Smith")
232 .noMore();
233
234 asserter.done();
235 //@formatter:on
236 }
237
238 @Test
239 public void read_multiple() throws Exception {
240 //@formatter:off
241 VCardAsserter asserter = readHtml(
242 "<html>" +
243 "<body>" +
244 "<div class=\"vcard\">" +
245 "<span class=\"fn\">John Doe</span>" +
246 "</div>" +
247 "<div class=\"vcard\">" +
248 "<span class=\"fn\">Jane Doe</span>" +
249 "</div>" +
250 "</body>" +
251 "</html>"
252 );
253
254 asserter.next(V3_0);
255 asserter.simpleProperty(FormattedName.class)
256 .value("John Doe")
257 .noMore();
258
259 asserter.next(V3_0);
260 asserter.simpleProperty(FormattedName.class)
261 .value("Jane Doe")
262 .noMore();
263
264 asserter.done();
265 //@formatter:on
266 }
267
268 @Test
269 public void embedded_vcards() {
270 //@formatter:off
271 String html =
272 "<html>" +
273 "<body>" +
274 "<div class=\"vcard\">" +
275 "<div class=\"fn\">John Doe</div>" +
276 "<div class=\"agent vcard\">" +
277 "<span class=\"fn\">Jane Doe</span>" +
278 "<div class=\"agent vcard\">" +
279 "<span class=\"fn\">Joseph Doe</span>" +
280 "</div>" +
281 "</div>" +
282 "</div>" +
283 "</body>" +
284 "</html>";
285 //@formatter:on
286
287 HCardParser parser = new HCardParser(html);
288
289 VCard vcard = parser.readNext();
290 assertVersion(V3_0, vcard);
291 assertPropertyCount(2, vcard);
292 assertEquals("John Doe", vcard.getFormattedName().getValue());
293 {
294 VCard embedded = vcard.getAgent().getVCard();
295 assertVersion(V3_0, embedded);
296 assertPropertyCount(2, embedded);
297 assertEquals("Jane Doe", embedded.getFormattedName().getValue());
298 {
299 VCard embedded2 = embedded.getAgent().getVCard();
300 assertVersion(V3_0, embedded2);
301 assertPropertyCount(1, embedded2);
302 assertEquals("Joseph Doe", embedded2.getFormattedName().getValue());
303 }
304 }
305
306 assertParseWarnings(parser);
307
308 assertNoMoreVCards(parser);
309 }
310
311 @Test
312 public void url_of_vcard_specified() throws Exception {
313 //@formatter:off
314 String html =
315 "<html>" +
316 "<body>" +
317 "<div class=\"vcard\">" +
318 "<a class=\"fn url\" href=\"index.html\">John Doe</span>" +
319 "</div>" +
320 "</body>" +
321 "</html>";
322
323 HCardParser parser = new HCardParser(html, "http://johndoe.com/vcard.html");
324 VCardAsserter asserter = new VCardAsserter(parser);
325
326 asserter.next(V3_0);
327
328 asserter.simpleProperty(FormattedName.class)
329 .value("John Doe")
330 .noMore();
331
332 asserter.simpleProperty(Url.class)
333 .value("http://johndoe.com/index.html")
334 .noMore();
335
336 asserter.simpleProperty(Source.class)
337 .value("http://johndoe.com/vcard.html")
338 .noMore();
339
340 asserter.done();
341 //@formatter:on
342 }
343
344 @Test
345 public void convert_instant_messenging_urls_to_impp_types() throws Exception {
346 //@formatter:off
347 VCardAsserter asserter = readHtml(
348 "<html>" +
349 "<body>" +
350 "<div class=\"vcard\">" +
351 "<a class=\"url\" href=\"aim:goim?screenname=ShoppingBuddy\">IM with the AIM ShoppingBuddy</a>" +
352 "</div>" +
353 "</body>" +
354 "</html>"
355 );
356
357 asserter.next(V3_0);
358
359 asserter.impp()
360 .uri("aim:ShoppingBuddy")
361 .noMore();
362
363 asserter.done();
364 //@formatter:on
365 }
366
367 @Test
368 public void convert_mailto_urls_to_email_types() throws Exception {
369 //@formatter:off
370 VCardAsserter asserter = readHtml(
371 "<html>" +
372 "<body>" +
373 "<div class=\"vcard\">" +
374 "<a class=\"url\" href=\"mailto:[email protected]\">Email me</a>" +
375 "</div>" +
376 "</body>" +
377 "</html>"
378 );
379
380 asserter.next(V3_0);
381
382 asserter.email()
383 .value("[email protected]")
384 .noMore();
385
386 asserter.done();
387 //@formatter:on
388 }
389
390 @Test
391 public void convert_tel_urls_to_tel_types() throws Exception {
392 //@formatter:off
393 VCardAsserter asserter = readHtml(
394 "<html>" +
395 "<body>" +
396 "<div class=\"vcard\">" +
397 "<a class=\"url\" href=\"tel:+15555551234\">Call me</a>" +
398 "</div>" +
399 "</body>" +
400 "</html>"
401 );
402
403 asserter.next(V3_0);
404
405 asserter.telephone()
406 .uri(new TelUri.Builder("+15555551234").build())
407 .noMore();
408
409 asserter.done();
410 //@formatter:on
411 }
412
413 @Test
414 public void mailto_url_with_email_and_url_class_names() throws Exception {
415 //@formatter:off
416 VCardAsserter asserter = readHtml(
417 "<html>" +
418 "<body>" +
419 "<div class=\"vcard\">" +
420 "<a class=\"email url\" href=\"mailto:[email protected]\">Email me</a>" +
421 "</div>" +
422 "</body>" +
423 "</html>"
424 );
425
426 asserter.next(V3_0);
427
428 asserter.simpleProperty(Url.class)
429 .value("mailto:[email protected]")
430 .noMore();
431
432 asserter.email()
433 .value("[email protected]")
434 .noMore();
435
436 asserter.done();
437 //@formatter:on
438 }
439
440 @Test
441 public void tel_url_with_tel_and_url_class_names() throws Exception {
442 //@formatter:off
443 VCardAsserter asserter = readHtml(
444 "<html>" +
445 "<body>" +
446 "<div class=\"vcard\">" +
447 "<a class=\"tel url\" href=\"tel:+15555551234\">Call me</a>" +
448 "</div>" +
449 "</body>" +
450 "</html>"
451 );
452
453 asserter.next(V3_0);
454
455 asserter.simpleProperty(Url.class)
456 .value("tel:+15555551234")
457 .noMore();
458
459 asserter.telephone()
460 .uri(new TelUri.Builder("+15555551234").build())
461 .noMore();
462
463 asserter.done();
464 //@formatter:on
465 }
466
467 @Test
468 public void assign_labels_to_addresses() throws Exception {
469 //@formatter:off
470 VCardAsserter asserter = readHtml(
471 "<html>" +
472 "<body>" +
473 "<div class=\"vcard\">" +
474 "<div class=\"adr\">" +
475 "<span class=\"type\">Home</span>:<br>" +
476 "<span class=\"street-address\">123 Main St.</span><br>" +
477 "<span class=\"locality\">Austin</span>, <span class=\"region\">TX</span> <span class=\"postal-code\">12345</span>" +
478 "</div>" +
479 "<div class=\"label\"><abbr class=\"type\" title=\"home\"></abbr>123 Main St.\nAustin, TX 12345</div>" +
480 "<abbr class=\"label\" title=\"456 Wall St., New York, NY 67890\"><abbr class=\"type\" title=\"work\"></abbr></abbr>" +
481 "</div>" +
482 "</body>" +
483 "</html>"
484 );
485
486 asserter.next(V3_0);
487
488 asserter.address()
489 .streetAddress("123 Main St.")
490 .locality("Austin")
491 .region("TX")
492 .postalCode("12345")
493 .label("123 Main St. Austin, TX 12345")
494 .types(AddressType.HOME)
495 .noMore();
496
497 asserter.simpleProperty(Label.class)
498 .value("456 Wall St., New York, NY 67890")
499 .param("TYPE", "work")
500 .noMore();
501
502 asserter.done();
503 //@formatter:on
504 }
505
506 @Test
507 public void anchor_in_url() throws Exception {
508 //@formatter:off
509 String html =
510 "<html>" +
511 "<body>" +
512 "<div class=\"vcard\">" +
513 "<span class=\"fn\">John Doe</span>" +
514 "</div>" +
515 "<div id=\"anchor\">" +
516 "<div class=\"vcard\">" +
517 "<span class=\"fn\">Jane Doe</span>" +
518 "</div>" +
519 "</div>" +
520 "</body>" +
521 "</html>";
522
523 HCardParser parser = new HCardParser(html, "http://johndoe.com/vcard.html#anchor");
524 VCardAsserter asserter = new VCardAsserter(parser);
525
526 asserter.next(V3_0);
527
528 asserter.simpleProperty(FormattedName.class)
529 .value("Jane Doe")
530 .noMore();
531
532 asserter.simpleProperty(Source.class)
533 .value("http://johndoe.com/vcard.html#anchor")
534 .noMore();
535
536 asserter.done();
537 //@formatter:on
538 }
539
540 @Test
541 public void non_existant_anchor() throws Exception {
542 //@formatter:off
543 String html =
544 "<html>" +
545 "<body>" +
546 "<div class=\"vcard\">" +
547 "<span class=\"fn\">John Doe</span>" +
548 "</div>" +
549 "<div id=\"anchor\">" +
550 "<div class=\"vcard\">" +
551 "<span class=\"fn\">Jane Doe</span>" +
552 "</div>" +
553 "</div>" +
554 "</body>" +
555 "</html>";
556
557 HCardParser parser = new HCardParser(html, "http://johndoe.com/vcard.html#non-existant");
558 VCardAsserter asserter = new VCardAsserter(parser);
559
560 asserter.next(V3_0);
561
562 asserter.simpleProperty(FormattedName.class)
563 .value("John Doe")
564 .noMore();
565
566 asserter.simpleProperty(Source.class)
567 .value("http://johndoe.com/vcard.html#non-existant")
568 .noMore();
569
570 asserter.next(V3_0);
571
572 asserter.simpleProperty(FormattedName.class)
573 .value("Jane Doe")
574 .noMore();
575
576 asserter.simpleProperty(Source.class)
577 .value("http://johndoe.com/vcard.html#non-existant")
578 .noMore();
579
580 asserter.done();
581 //@formatter:on
582 }
583
584 @Test
585 public void add_all_nicknames_to_the_same_object() throws Exception {
586 //@formatter:off
587 VCardAsserter asserter = readHtml(
588 "<html>" +
589 "<body>" +
590 "<div class=\"vcard\">" +
591 "<span class=\"fn\">John Doe</span>" +
592 "<span class=\"nickname\">Johnny</span>" +
593 "<span class=\"nickname\">Johnny 5</span>" +
594 "<span class=\"nickname\">Johnster</span>" +
595 "</div>" +
596 "</body>" +
597 "</html>"
598 );
599
600 asserter.next(V3_0);
601
602 asserter.simpleProperty(FormattedName.class)
603 .value("John Doe")
604 .noMore();
605
606 asserter.listProperty(Nickname.class)
607 .values("Johnny", "Johnny 5", "Johnster")
608 .noMore();
609
610 asserter.done();
611 //@formatter:on
612 }
613
614 @Test
615 public void add_all_categories_to_the_same_object() throws Exception {
616 //@formatter:off
617 VCardAsserter asserter = readHtml(
618 "<html>" +
619 "<body>" +
620 "<div class=\"vcard\">" +
621 "<span class=\"fn\">John Doe</span>" +
622 "<span class=\"category\">programmer</span>" +
623 "<span class=\"category\">swimmer</span>" +
624 "<span class=\"category\" rel=\"singer\">I also sing</span>" +
625 "</div>" +
626 "</body>" +
627 "</html>"
628 );
629
630 asserter.next(V3_0);
631
632 asserter.simpleProperty(FormattedName.class)
633 .value("John Doe")
634 .noMore();
635
636 asserter.listProperty(Categories.class)
637 .values("programmer", "swimmer", "singer")
638 .noMore();
639
640 asserter.done();
641 //@formatter:on
642 }
643
644 @Test
645 public void complete_vcard() throws Exception {
646 //@formatter:off
647 VCardAsserter asserter = readHtml(
648 "<html>" +
649 "<body>" +
650 "<div class=\"vcard\">" +
651 "<a class=\"fn org url\" href=\"http://www.commerce.net/\">CommerceNet</a>" +
652 "<div class=\"adr\">" +
653 "<span class=\"type\">Work</span>:" +
654 "<div class=\"street-address\">169 University Avenue</div>" +
655 "<span class=\"locality\">Palo Alto</span>, " +
656 "<abbr class=\"region\" title=\"California\">CA</abbr>&nbsp;&nbsp;" +
657 "<span class=\"postal-code\">94301</span>" +
658 "<div class=\"country-name\">USA</div>" +
659 "</div>" +
660 "<div class=\"tel\">" +
661 "<span class=\"type\">Work</span> +1-650-289-4040" +
662 "</div>" +
663 "<div class=\"tel\">" +
664 "<span class=\"type\">Fax</span> +1-650-289-4041" +
665 "</div>" +
666 "<div>Email:" +
667 "<span class=\"email\">[email protected]</span>" +
668 "</div>" +
669 "</div>" +
670 "</body>" +
671 "</html>"
672 );
673
674 asserter.next(V3_0);
675
676 asserter.simpleProperty(FormattedName.class)
677 .value("CommerceNet")
678 .noMore();
679
680 asserter.listProperty(Organization.class)
681 .values("CommerceNet")
682 .noMore();
683
684 asserter.simpleProperty(Url.class)
685 .value("http://www.commerce.net/")
686 .noMore();
687
688 asserter.address()
689 .types(AddressType.WORK)
690 .streetAddress("169 University Avenue")
691 .locality("Palo Alto")
692 .region("California")
693 .postalCode("94301")
694 .country("USA")
695 .noMore();
696
697 asserter.telephone()
698 .types(TelephoneType.WORK)
699 .text("+1-650-289-4040")
700 .next()
701 .types(TelephoneType.FAX)
702 .text("+1-650-289-4041")
703 .noMore();
704
705 asserter.email()
706 .value("[email protected]")
707 .noMore();
708
709 asserter.done();
710 //@formatter:on
711 }
712
713 @Test
714 public void registerExtendedProperty() throws Exception {
715 //@formatter:off
716 String html =
717 "<html>" +
718 "<body>" +
719 "<div class=\"vcard\">" +
720 "<span class=\"x-lucky-num\">24</span>" +
721 "<span class=\"x-lucky-num\">22</span>" +
722 "<span class=\"x-gender\">male</span>" +
723 "</div>" +
724 "</body>" +
725 "</html>";
726 //@formatter:on
727
728 HCardParser parser = new HCardParser(html);
729 parser.registerScribe(new LuckyNumScribe());
730
731 VCard vcard = parser.readNext();
732 assertVersion(V3_0, vcard);
733 assertPropertyCount(3, vcard);
734
735 //read a type that has a type class
736 List<LuckyNumProperty> luckyNumTypes = vcard.getProperties(LuckyNumProperty.class);
737 assertEquals(2, luckyNumTypes.size());
738 assertEquals(24, luckyNumTypes.get(0).luckyNum);
739 assertEquals(22, luckyNumTypes.get(1).luckyNum);
740
741 //read a type without a type class
742 assertEquals("male", vcard.getExtendedProperty("X-GENDER").getValue());
743
744 assertParseWarnings(parser);
745
746 assertNoMoreVCards(parser);
747 }
748
749 @Test
750 public void registerExtendedProperty_overrides_standard_type_classes() throws Exception {
751 //@formatter:off
752 String html =
753 "<html>" +
754 "<body>" +
755 "<div class=\"vcard\">" +
756 "<span class=\"fn\">John Doe</span>" +
757 "</div>" +
758 "</body>" +
759 "</html>";
760 //@formatter:on
761
762 HCardParser parser = new HCardParser(html);
763 parser.registerScribe(new MyFormattedNameScribe());
764
765 VCard vcard = parser.readNext();
766 assertVersion(V3_0, vcard);
767 assertPropertyCount(1, vcard);
768
769 //read a type that has a type class
770 assertEquals("JOHN DOE", vcard.getProperty(MyFormattedNameProperty.class).value);
771
772 assertParseWarnings(parser);
773
774 assertNoMoreVCards(parser);
775 }
776
777 @Test
778 public void skipMeException() throws Exception {
779 //@formatter:off
780 String html =
781 "<html>" +
782 "<body>" +
783 "<div class=\"vcard\">" +
784 "<span class=\"skipme\">value</span>" +
785 "<span class=\"x-foo\">value</span>" +
786 "</div>" +
787 "</body>" +
788 "</html>";
789
790 HCardParser parser = new HCardParser(html);
791 parser.registerScribe(new SkipMeScribe());
792 VCardAsserter asserter = new VCardAsserter(parser);
793
794 asserter.next(V3_0);
795
796 asserter.rawProperty("x-foo")
797 .value("value")
798 .noMore();
799
800 asserter.warnings(22);
801 asserter.done();
802 //@formatter:on
803 }
804
805 @Test
806 public void cannotParseException() throws Exception {
807 //@formatter:off
808 String html =
809 "<html>" +
810 "<body>" +
811 "<div class=\"vcard\">" +
812 "<span class=\"cannotparse\">value</span>" +
813 "<span class=\"x-foo\">value</span>" +
814 "</div>" +
815 "</body>" +
816 "</html>";
817
818 HCardParser parser = new HCardParser(html);
819 parser.registerScribe(new CannotParseScribe());
820 VCardAsserter asserter = new VCardAsserter(parser);
821
822 asserter.next(V3_0);
823
824 asserter.rawProperty("x-foo")
825 .value("value")
826 .noMore();
827
828 asserter.rawProperty("cannotparse")
829 .value("<span class=\"cannotparse\">value</span>")
830 .noMore();
831
832 asserter.warnings(25);
833 asserter.done();
834 //@formatter:on
835 }
836
837 private static VCardAsserter readHtml(String html) {
838 HCardParser parser = new HCardParser(html);
839 return new VCardAsserter(parser);
840 }
841 }