At last update to JUnit 4.x
[zxing.git] / core / test / src / com / google / zxing / client / result / AddressBookParsedResultTestCase.java
1 /*
2  * Copyright 2007 ZXing authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package com.google.zxing.client.result;
18
19 import com.google.zxing.BarcodeFormat;
20 import com.google.zxing.Result;
21 import org.junit.Assert;
22 import org.junit.Test;
23
24 import java.util.Arrays;
25
26 /**
27  * Tests {@link AddressBookParsedResult}.
28  *
29  * @author Sean Owen
30  */
31 public final class AddressBookParsedResultTestCase extends Assert {
32
33   @Test
34   public void testAddressBookDocomo() {
35     doTest("MECARD:N:Sean Owen;;", null, new String[] {"Sean Owen"}, null, null, null, null, null, null, null, null);
36     doTest("MECARD:NOTE:ZXing Team;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;;",
37         null, new String[] {"Sean Owen"}, null, null, new String[] {"srowen@example.org"}, null, null,
38         "google.com", null, "ZXing Team");
39   }
40
41   @Test
42   public void testAddressBookAU() {
43     doTest("MEMORY:foo\r\nNAME1:Sean\r\nTEL1:+12125551212\r\n",
44         null, new String[] {"Sean"}, null, null, null, new String[] {"+12125551212"}, null, null, null, "foo");
45   }
46
47   @Test
48   public void testVCard() {
49     doTest("BEGIN:VCARD\r\nADR;HOME:123 Main St\r\nVERSION:2.1\r\nN:Owen;Sean\r\nEND:VCARD",
50            null, new String[] {"Sean Owen"}, null, new String[] {"123 Main St"}, null, null, null, null, null, null);
51   }
52
53   @Test
54   public void testBizcard() {
55     doTest("BIZCARD:N:Sean;X:Owen;C:Google;A:123 Main St;M:+12125551212;E:srowen@example.org;",
56         null, new String[] {"Sean Owen"}, null, new String[] {"123 Main St"}, new String[] {"srowen@example.org"},
57         new String[] {"+12125551212"}, "Google", null, null, null);
58   }
59
60   @Test
61   public void testSeveralAddresses() {
62     doTest("MECARD:N:Foo Bar;ORG:Company;TEL:5555555555;EMAIL:foo.bar@xyz.com;ADR:City, 10001;" +
63            "ADR:City, 10001;NOTE:This is the memo.;;",
64            null, new String[] {"Foo Bar"}, null, new String[] {"City, 10001", "City, 10001"},
65            new String[] {"foo.bar@xyz.com"},
66            new String[] {"5555555555" }, "Company", null, null, "This is the memo.");
67   }
68
69   @Test
70   public void testQuotedPrintable() {
71     doTest("BEGIN:VCARD\r\nADR;HOME;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:;;" +
72            "=35=38=20=4C=79=6E=62=72=6F=6F=6B=0D=0A=43=\r\n" +
73            "=4F=20=36=39=39=\r\n" +
74            "=32=36;;;\r\nEND:VCARD",
75            null, null, null, new String[] {"58 Lynbrook\r\nCO 69926"},
76            null, null, null, null, null, null);
77   }
78
79   private static void doTest(String contents,
80                              String title,
81                              String[] names,
82                              String pronunciation,
83                              String[] addresses,
84                              String[] emails,
85                              String[] phoneNumbers,
86                              String org,
87                              String url,
88                              String birthday,
89                              String note) {
90     Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
91     ParsedResult result = ResultParser.parseResult(fakeResult);
92     assertSame(ParsedResultType.ADDRESSBOOK, result.getType());
93     AddressBookParsedResult addressResult = (AddressBookParsedResult) result;
94     assertEquals(title, addressResult.getTitle());
95     assertTrue(Arrays.equals(names, addressResult.getNames()));
96     assertEquals(pronunciation, addressResult.getPronunciation());
97     assertTrue(Arrays.equals(addresses, addressResult.getAddresses()));
98     assertTrue(Arrays.equals(emails, addressResult.getEmails()));
99     assertTrue(Arrays.equals(phoneNumbers, addressResult.getPhoneNumbers()));
100     assertEquals(org, addressResult.getOrg());
101     assertEquals(url, addressResult.getURL());
102     assertEquals(birthday, addressResult.getBirthday());
103     assertEquals(note, addressResult.getNote());
104   }
105
106 }