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.Doc;
023: import javax.print.SimpleDoc;
024: import javax.print.attribute.standard.ColorSupported;
025: import javax.print.attribute.standard.Compression;
026: import javax.print.attribute.standard.Copies;
027:
028: import junit.framework.TestCase;
029:
030: public class AttributeSetUtilitiesTest extends TestCase {
031:
032: public static void main(String[] args) {
033: junit.textui.TestRunner.run(AttributeSetUtilitiesTest.class);
034: }
035:
036: static {
037: System.out.println("AttributeSetUtilities testing...");
038: }
039:
040: /*
041: * verifyAttributeCategory(Object object, Class interfaceName) method testing.
042: * Tests that method returns the same Class and no exception is thown
043: * if arguments are valid.
044: */
045: public final void testVerifyAttributeCategory() {
046: assertEquals(ColorSupported.class, AttributeSetUtilities
047: .verifyAttributeCategory(ColorSupported.class,
048: PrintServiceAttribute.class));
049: }
050:
051: /*
052: * verifyAttributeCategory(Object object, Class interfaceName) method testing.
053: * Tests that method throws ClassCastException if object is not
054: * a Class that implements interfaceName.
055: */
056: public final void testVerifyAttributeCategory1() {
057:
058: try {
059: AttributeSetUtilities.verifyAttributeCategory(
060: ColorSupported.class, DocAttribute.class);
061: fail("method doesn't throw ClassCastException "
062: + "if object is not a Class that implements interfaceName");
063: } catch (ClassCastException e) {
064: //System.out.println("testVerifyAttributeCategory1 - " + e.toString());
065: }
066:
067: }
068:
069: /*
070: * verifyAttributeCategory(Object object, Class interfaceName) method testing.
071: * Tests that method throws NullPointerException if object is null.
072: */
073: public final void testVerifyAttributeCategory2() {
074:
075: try {
076: Attribute att = null;
077: AttributeSetUtilities.verifyAttributeCategory(att,
078: DocAttribute.class);
079: fail("method doesn't throw NullPointerException if object is null");
080: } catch (NullPointerException e) {
081: //System.out.println("testVerifyAttributeCategory2 - " + e.toString());
082: }
083:
084: }
085:
086: /*
087: * verifyAttributeCategory(Object object, Class interfaceName) method testing.
088: * Tests that method throws exception if object is a Class that implements
089: * interfaceName but interfaceName is not a class that implements interface
090: * Attribute.
091: */
092: public final void testVerifyAttributeCategory3() {
093:
094: //fails in "some" invironment
095: //see AttributeSetUtilities, line 337-339
096:
097: try {
098: AttributeSetUtilities.verifyAttributeCategory(
099: SimpleDoc.class, Doc.class);
100: fail("method doesn't throw ClassCastException if object "
101: + "is a Class that implements interfaceName but "
102: + "interfaceName is not a class that implements "
103: + "interface Attribute");
104: } catch (ClassCastException e) {
105: //System.out.println("testVerifyAttributeCategory3 - " + e.toString());
106: }
107:
108: }
109:
110: /*
111: * verifyAttributeValue(Object attribute, Class interfaceName) method testing.
112: * Tests that method returns object downcasted to type Attribute and no
113: * exception is thown if arguments are valid.
114: */
115: public final void testVerifyAttributeValue() {
116: PrintJobAttribute att = new Copies(10);
117: assertEquals(att, AttributeSetUtilities.verifyAttributeValue(
118: att, PrintJobAttribute.class));
119: assertEquals(att, AttributeSetUtilities.verifyAttributeValue(
120: att, PrintRequestAttribute.class));
121: }
122:
123: /*
124: * verifyAttributeValue(Object attribute, Class interfaceName) method testing.
125: * Tests that method throws ClassCastException if object isn't an instance
126: * of interfaceName.
127: */
128: public final void testVerifyAttributeValue1() {
129:
130: try {
131: DocAttribute att = Compression.COMPRESS;
132: AttributeSetUtilities.verifyAttributeValue(att,
133: PrintJobAttribute.class);
134:
135: } catch (ClassCastException e) {
136: //System.out.println("testVerifyAttributeValue1 - " + e.toString());
137: }
138: }
139:
140: /*
141: * verifyAttributeValue(Object attribute, Class interfaceName) method testing.
142: * Tests that method throws NullPointerException if object is null.
143: */
144: public final void testVerifyAttributeValue2() {
145:
146: try {
147: AttributeSetUtilities.verifyAttributeValue(null,
148: DocAttribute.class);
149: fail("method doesn't throw NullPointerException if object is null");
150: } catch (NullPointerException e) {
151: //System.out.println("testVerifyAttributeValue2 - " + e.toString());
152: }
153: }
154:
155: /*
156: * verifyCategoryForValue(Class attributeCategory, Attribute attribute) method testing.
157: * Tests that method throws no exception if arguments are valid.
158: */
159: public final void testVerifyCategoryForValue() {
160: PrintServiceAttribute att = ColorSupported.NOT_SUPPORTED;
161: AttributeSetUtilities.verifyCategoryForValue(
162: ColorSupported.class, att);
163: }
164:
165: /*
166: * verifyCategoryForValue(Class attributeCategory, Attribute attribute) method testing.
167: * Tests that method throws IllegalArgumentException if the category is
168: * not equal to the category of the attribute.
169: */
170: public final void testVerifyCategoryForValue1() {
171:
172: try {
173: PrintServiceAttribute att = ColorSupported.NOT_SUPPORTED;
174: AttributeSetUtilities.verifyCategoryForValue(
175: DocAttribute.class, att);
176: fail("method doesn't thrown IllegalArgumentException if the category "
177: + "is not equal to the category of the attribute.");
178: } catch (IllegalArgumentException e) {
179: //System.out.println("testVerifyCategoryForValue1 - " + e.toString());
180: }
181: }
182:
183: /*
184: * verifyCategoryForValue(Class attributeCategory, Attribute attribute) method testing.
185: * Tests that method throws NullPointerException if the attribute is null.
186: */
187: public final void testVerifyCategoryForValue2() {
188:
189: try {
190: AttributeSetUtilities.verifyCategoryForValue(
191: DocAttribute.class, null);
192: fail("method doesn't throw NullPointerException if object is null");
193: } catch (NullPointerException e) {
194: //System.out.println("testVerifyCategoryForValue2 - " + e.toString());
195: }
196: }
197:
198: /*
199: * unmodifiableView(AttributeSet attributeSet) methods testing.
200: * Tests that methods provides a client "read-only" access to the created
201: * unmodifiable view of some attribute set.
202: */
203: public final void testUnmodifiableView() {
204:
205: AttributeSet aset = new HashAttributeSet();
206: aset = AttributeSetUtilities.unmodifiableView(aset);
207: try {
208: aset.add(ColorSupported.SUPPORTED);
209: aset.addAll(aset);
210: aset.clear();
211: aset.remove(ColorSupported.NOT_SUPPORTED);
212: aset.remove(ColorSupported.class);
213: fail("method doesn't throw UnmodifiableSetException if someone"
214: + "try to modify attribute set");
215: } catch (Exception e) {
216: //System.out.println("testUnmodifiableView - " + e.toString());
217: }
218: }
219:
220: /*
221: * synchronizedView(AttributeSet attributeSet) methods testing.
222: */
223: public final void testSynchronizedView() {
224: //To-Do
225: }
226:
227: }
|