001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Elena V. Sayapina
019: * @version $Revision: 1.3 $
020: */package javax.print.attribute;
021:
022: import java.util.Date;
023:
024: import junit.framework.TestCase;
025:
026: public class DateTimeSyntaxTest extends TestCase {
027:
028: public static void main(String[] args) {
029: junit.textui.TestRunner.run(DateTimeSyntaxTest.class);
030: }
031:
032: static {
033: System.out.println("DateTimeSyntax testing...");
034: }
035:
036: private DateTimeSyntax dts1, dts2;
037: private Date date;
038:
039: /*
040: * DateTimeSyntax(Date date) constructor testing.
041: */
042: public final void testDateTimeSyntax() {
043:
044: date = null;
045: try {
046: dts1 = new dateTimeSyntax(date);
047: fail("DateTimeSyntax(Date date) doesn't throw "
048: + "NullPointerException if date is null");
049: } catch (NullPointerException e) {
050:
051: }
052: }
053:
054: /*
055: * hashCode() method testing. Tests if two object are equal they must have
056: * the same hash code.
057: */
058: public final void testHashCode() {
059: date = new Date((long) Math.pow(10, 12));
060: dts1 = new dateTimeSyntax(date);
061: dts2 = new dateTimeSyntax(date);
062: assertTrue(dts1.hashCode() == dts2.hashCode());
063: }
064:
065: /*
066: * hashCode() method testing. Tests if two object aren't equal they should
067: * have different hash codes.
068: */
069: public final void testHashCode1() {
070: date = new Date((long) Math.pow(10, 12));
071: dts1 = new dateTimeSyntax(date);
072: date = new Date();
073: dts2 = new dateTimeSyntax(date);
074: assertFalse(dts1.hashCode() == dts2.hashCode());
075: }
076:
077: /*
078: * equals(Object object) method testing. Tests if two DateTimeSyntax
079: * objects aren't equal equals() return false.
080: */
081: public final void testEquals() {
082:
083: date = new Date((long) Math.pow(10, 12));
084: dts1 = new dateTimeSyntax(date);
085: date = new Date((long) Math.pow(10, 12) - 1);
086: dts2 = new dateTimeSyntax(date);
087: assertFalse(dts1.equals(dts2));
088:
089: dts2 = null;
090: assertFalse(dts1.equals(dts2));
091: }
092:
093: /*
094: * equals(Object object) method testing. Tests if two DateTimeSyntax
095: * objects are equal equals() return true.
096: */
097: public final void testEquals1() {
098:
099: date = new Date();
100: dts1 = new dateTimeSyntax(date);
101: dts2 = new dateTimeSyntax(date);
102: assertTrue(dts1.equals(dts2));
103: }
104:
105: /*
106: * getValue() method testing.
107: */
108: public final void testGetValue() {
109: date = new Date();
110: dts1 = new dateTimeSyntax(date);
111: assertEquals(date, dts1.getValue());
112:
113: date = new Date((long) Math.pow(10, 12));
114: dts2 = new dateTimeSyntax(date);
115: assertEquals(date, dts2.getValue());
116: }
117:
118: /*
119: * Auxiliary class
120: */
121: public class dateTimeSyntax extends DateTimeSyntax {
122:
123: public dateTimeSyntax(Date value) {
124: super(value);
125: }
126: }
127:
128: }
|