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 javax.print.attribute.standard.Copies;
023: import javax.print.attribute.standard.NumberUp;
024: import javax.print.attribute.standard.PagesPerMinute;
025:
026: import junit.framework.TestCase;
027:
028: public class IntegerSyntaxTest extends TestCase {
029:
030: public static void main(String[] args) {
031: junit.textui.TestRunner.run(IntegerSyntaxTest.class);
032: }
033:
034: static {
035: System.out.println("IntegerSyntax testing...");
036: }
037:
038: IntegerSyntax is1, is2;
039:
040: /*
041: * IntegerSyntax(int value) constructor testing.
042: */
043: public final void testIntegerSyntax_Int() {
044: is1 = new integerSyntax(300);
045: assertEquals(300, is1.getValue());
046: }
047:
048: /*
049: * IntegerSyntax(int value, int lowerBound, int upperBound) constructor testing.
050: */
051: public final void testIntegerSyntax_IntIntInt() {
052: try {
053: is1 = new integerSyntax(-1, 1, 1);
054: fail("Constructor IntegerSyntax(int value, int lowerBound, int upperBound) "
055: + "doesn't throw IllegalArgumentException "
056: + "if value is less than lowerBound");
057: } catch (IllegalArgumentException e) {
058:
059: }
060:
061: try {
062: is1 = new integerSyntax(2, 1, 1);
063: fail("Constructor IntegerSyntax(int value, int lowerBound, int upperBound) "
064: + "doesn't throw IllegalArgumentException "
065: + "if value is greater than upperBound");
066: } catch (IllegalArgumentException e) {
067:
068: }
069:
070: is1 = new integerSyntax(300, 1, 400);
071: assertEquals(300, is1.getValue());
072: }
073:
074: /*
075: * hashCode() method testing. Tests if two object aren't equal they should
076: * have different hash codes.
077: */
078: public final void testHashCode() {
079: is1 = new integerSyntax(1000);
080: is2 = new integerSyntax(1000 - 1);
081: assertTrue(is2.hashCode() == 999);
082: assertTrue(is1.hashCode() != is2.hashCode());
083: }
084:
085: /*
086: * hashCode() method testing. Tests if two object are equal they must have
087: * the same hash code.
088: */
089: public final void testHashCode1() {
090: is1 = new integerSyntax(1, 1, 10);
091: is2 = new integerSyntax(1, 1, 15);
092: assertTrue(is1.hashCode() == 1);
093: assertTrue(is1.hashCode() == is2.hashCode());
094: }
095:
096: /*
097: * hashCode() method testing. Tests that hash code is just this integer
098: * attribute's integer value.
099: */
100: public final void testHashCode2() {
101: is1 = new Copies(5);
102: is2 = new NumberUp(5);
103: assertTrue(is1.hashCode() == 5);
104: assertTrue(is2.hashCode() == 5);
105: assertTrue(is1.hashCode() == is2.hashCode());
106: }
107:
108: /*
109: * equals(Object object) method testing. Tests if two IntegerSyntax
110: * objects are equal equals() return true.
111: */
112: public final void testEquals() {
113: is1 = new Copies(99);
114: is2 = new Copies(99);
115: assertTrue(is1.equals(is2));
116: }
117:
118: /*
119: * equals(Object object) method testing. Tests if two IntegerSyntax
120: * objects aren't equal equals() return false.
121: */
122: public final void testEquals1() {
123: is1 = new Copies(99);
124: is2 = new NumberUp(99);
125: assertFalse(is1.equals(is2));
126:
127: is2 = null;
128: assertFalse(is1.equals(is2));
129: }
130:
131: /*
132: * getValue() method testing.
133: */
134: public final void testGetValue() {
135: is1 = new PagesPerMinute(30);
136: assertTrue(is1.getValue() == 30);
137: }
138:
139: /*
140: * Auxiliary class
141: */
142: protected class integerSyntax extends IntegerSyntax {
143:
144: public integerSyntax(int value) {
145: super (value);
146: }
147:
148: public integerSyntax(int value, int lowerBound, int upperBound) {
149: super(value, lowerBound, upperBound);
150: }
151: }
152:
153: }
|