2 * Copyright (c) 2009, Ben Fortuna
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * o Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * o Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * o Neither the name of Ben Fortuna nor the names of any other contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 package net
.fortuna
.ical4j
.model
;
34 import java
.text
.ParseException
;
35 import java
.util
.Calendar
;
37 import junit
.framework
.TestCase
;
38 import junit
.framework
.TestSuite
;
39 import net
.fortuna
.ical4j
.util
.TimeZones
;
42 * $Id: DateTest.java,v 1.13 2009/05/07 10:36:09 fortuna Exp $
44 * Created on 30/06/2005
49 public class DateTest
extends TestCase
{
53 private java
.util
.Date date2
;
55 private String expectedString
;
59 * @param expectedString
61 public DateTest(Date date
, String expectedString
) {
62 super("testToString");
64 this.expectedString
= expectedString
;
71 public DateTest(Date date
, java
.util
.Date date2
) {
80 public void testToString() {
81 assertEquals(expectedString
, date
.toString());
87 public void testEquals() {
88 assertEquals(date2
, date
);
92 * @see junit.framework.TestCase#getName()
94 public String
getName() {
95 return super.getName() + " [" + date
.toString() + "]";
100 * @throws ParseException
102 public static TestSuite
suite() throws ParseException
{
103 TestSuite suite
= new TestSuite();
104 suite
.addTest(new DateTest(new Date(0l), "19700101"));
106 Calendar cal
= Calendar
.getInstance(TimeZones
.getDateTimeZone());
108 cal
.set(Calendar
.YEAR
, 1984);
109 // months are zero-based..
110 cal
.set(Calendar
.MONTH
, 3);
111 cal
.set(Calendar
.DAY_OF_MONTH
, 17);
112 suite
.addTest(new DateTest(new Date(cal
.getTime()), "19840417"));
114 suite
.addTest(new DateTest(new Date("20050630"), "20050630"));
117 * Unless CompatabilityHints.KEY_RELAXED_PARSING is enabled, it looks like this
120 suite
.addTest(new DateTest(new Date("20100431"), "20100431"));
122 // Test equality of Date instances created using different constructors..
123 Calendar calendar
= Calendar
.getInstance(TimeZones
.getDateTimeZone());
125 calendar
.set(2005, 0, 1);
126 calendar
.set(Calendar
.MILLISECOND
, 1);
127 suite
.addTest(new DateTest(new Date(calendar
.getTime()), new Date("20050101").toString()));
128 suite
.addTest(new DateTest(new Date(calendar
.getTime()), new Date("20050101")));
130 calendar
= Calendar
.getInstance(TimeZones
.getDateTimeZone());
132 calendar
.set(2005, 0, 1);
133 calendar
.clear(Calendar
.HOUR_OF_DAY
);
134 calendar
.clear(Calendar
.MINUTE
);
135 calendar
.clear(Calendar
.SECOND
);
136 calendar
.clear(Calendar
.MILLISECOND
);
137 suite
.addTest(new DateTest(new Date("20050101"), calendar
.getTime()));