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.io.ObjectStreamException;
023:
024: import junit.framework.TestCase;
025:
026: public class EnumSyntaxTest extends TestCase {
027:
028: public static void main(String[] args) {
029: junit.textui.TestRunner.run(EnumSyntaxTest.class);
030: }
031:
032: static {
033: System.out.println("EnumSyntax testing...");
034: }
035:
036: enumSyntax es;
037: ExtendEnumSyntax ees;
038:
039: /*
040: * clone() method testing.
041: */
042: public void testClone() {
043: es = new enumSyntax(10);
044: Object es2 = es.clone();
045: assertEquals(es2, es);
046: }
047:
048: /*
049: * getEnumValueTable() method testing.
050: * Tests that getEnumValueTable() returns null as a default.
051: */
052: public void testGetEnumValueTable() {
053: es = new enumSyntax(10);
054: EnumSyntax[] esyntax = es.getEnumValueTableEx();
055: assertNull(esyntax);
056: }
057:
058: /*
059: * getOffset() method testing.
060: * Tests that getOffset() returns 0 as a default.
061: */
062: public void testGetOffset() {
063: es = new enumSyntax(10);
064: int i = es.getOffsetEx();
065: assertEquals(0, i);
066: }
067:
068: /*
069: * getStringTable() method testing.
070: * Tests that GetStringTable() returns null as a default.
071: */
072: public void testGetStringTable() {
073: es = new enumSyntax(10);
074: String[] str = es.getStringTableEx();
075: assertNull(str);
076: }
077:
078: /*
079: * getValue() method testing.
080: * Tests that getValue() returns this enumeration value's integer value.
081: */
082: public void testGetValue() {
083: es = new enumSyntax(10);
084: int i = es.getValue();
085: assertEquals(10, i);
086: }
087:
088: /*
089: * hashCode() method testing.
090: * Tests that hash code is this enumeration value's integer value.
091: */
092: public void testHashCode() {
093: es = new enumSyntax(0);
094: int i = es.hashCode();
095: assertEquals(0, i);
096: }
097:
098: /*
099: * readResolve() method testing.
100: */
101: public void testReadResolve() {
102: ees = new ExtendEnumSyntax(1);
103: try {
104: ees.readResolveEx();
105: fail("readResolve() doesn't throw InvalidObjectException if"
106: + "enumeration value table is null");
107: } catch (ObjectStreamException e) {
108: //System.out.println(e);
109: }
110: }
111:
112: /*
113: * readResolve() method testing.
114: */
115: public void testReadResolve1() {
116: ees = new ExtendEnumSyntax(3);
117: try {
118: ees.readResolveEx();
119: fail("readResolve() doesn't throw InvalidObjectException if"
120: + "integer value doesn't have corresponding enumeration value");
121: } catch (ObjectStreamException e) {
122: //System.out.println(e);
123: }
124: }
125:
126: /*
127: * readResolve() method testing.
128: */
129: public void testReadResolve2() {
130: ees = new ExtendEnumSyntax(2);
131: try {
132: ees.readResolveEx();
133: fail("readResolve() doesn't throw InvalidObjectException if"
134: + "enumeration value is null");
135: } catch (ObjectStreamException e) {
136: //System.out.println(e);
137: }
138: }
139:
140: /*
141: * toString() method testing.
142: * Tests that if there is no string value corresponding to this enumeration
143: * value toString() returns string contains this enumeration value.
144: */
145: public void testToString() {
146: ees = new ExtendEnumSyntax(2);
147: assertEquals("2", ees.toString());
148: es = new enumSyntax(10);
149: assertEquals("10", es.toString());
150: }
151:
152: /*
153: * Auxiliary class
154: */
155: protected class enumSyntax extends EnumSyntax {
156:
157: public enumSyntax(int value) {
158: super (value);
159: }
160:
161: public EnumSyntax[] getEnumValueTableEx() {
162: return getEnumValueTable();
163: }
164:
165: public String[] getStringTableEx() {
166: return getStringTable();
167: }
168:
169: public int getOffsetEx() {
170: return getOffset();
171: }
172: }
173:
174: }
|