At last update to JUnit 4.x
[zxing.git] / core / test / src / com / google / zxing / client / result / CalendarParsedResultTestCase.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 /**
25  * Tests {@link CalendarParsedResult}.
26  *
27  * @author Sean Owen
28  */
29 public final class CalendarParsedResultTestCase extends Assert {
30
31   @Test
32   public void testStartEnd() {
33     doTest(
34         "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
35         "DTSTART:20080504T123456Z\r\n" +
36         "DTEND:20080505T234555Z\r\n" +
37         "END:VEVENT\r\nEND:VCALENDAR",
38         null, null, null, "20080504T123456Z", "20080505T234555Z", null);
39   }
40
41   @Test
42   public void testStart() {
43     doTest(
44         "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
45         "DTSTART:20080504T123456Z\r\n" +
46         "END:VEVENT\r\nEND:VCALENDAR",
47         null, null, null, "20080504T123456Z", "20080504T123456Z", null);
48   }
49
50   @Test
51   public void testSummary() {
52     doTest(
53         "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
54         "SUMMARY:foo\r\n" +
55         "DTSTART:20080504T123456Z\r\n" +
56         "END:VEVENT\r\nEND:VCALENDAR",
57         null, "foo", null, "20080504T123456Z", "20080504T123456Z", null);
58   }
59
60   @Test
61   public void testLocation() {
62     doTest(
63         "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
64         "LOCATION:Miami\r\n" +
65         "DTSTART:20080504T123456Z\r\n" +
66         "END:VEVENT\r\nEND:VCALENDAR",
67         null, null, "Miami", "20080504T123456Z", "20080504T123456Z", null);
68   }
69
70   @Test
71   public void testDescription() {
72     doTest(
73         "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
74         "DTSTART:20080504T123456Z\r\n" +
75         "DESCRIPTION:This is a test\r\n" +
76         "END:VEVENT\r\nEND:VCALENDAR",
77         "This is a test", null, null, "20080504T123456Z", "20080504T123456Z", null);
78     doTest(
79         "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
80         "DTSTART:20080504T123456Z\r\n" +
81         "DESCRIPTION:This is a test\r\n\t with a continuation\r\n" +        
82         "END:VEVENT\r\nEND:VCALENDAR",
83         "This is a test with a continuation", null, null, "20080504T123456Z", "20080504T123456Z", null);
84   }
85
86   private static void doTest(String contents,
87                              String description,
88                              String summary,
89                              String location,
90                              String start,
91                              String end,
92                              String attendee) {
93     Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
94     ParsedResult result = ResultParser.parseResult(fakeResult);
95     assertSame(ParsedResultType.CALENDAR, result.getType());
96     CalendarParsedResult calResult = (CalendarParsedResult) result;
97     assertEquals(description, calResult.getDescription());
98     assertEquals(summary, calResult.getSummary());
99     assertEquals(location, calResult.getLocation());
100     assertEquals(start, calResult.getStart());
101     assertEquals(end, calResult.getEnd());
102     assertEquals(attendee, calResult.getAttendee());
103   }
104
105 }