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.standard;
021:
022: import java.util.HashMap;
023: import java.util.HashSet;
024: import java.util.Set;
025:
026: import junit.framework.TestCase;
027:
028: public class PrinterStateReasonsTest extends TestCase {
029:
030: public static void main(String[] args) {
031: junit.textui.TestRunner.run(PrinterStateReasonsTest.class);
032: }
033:
034: static {
035: System.out.println("PrinterStateReasons testing...");
036: }
037:
038: PrinterStateReasons reasons;
039:
040: /*
041: * PrinterStateReasons() constructor testing.
042: */
043: public final void testPrinterStateReasons() {
044: reasons = new PrinterStateReasons();
045: assertEquals(0, reasons.size());
046: }
047:
048: /*
049: * PrinterStateReasons(int initialCapacity) constructor testing.
050: */
051: public final void testPrinterStateReasonsint() {
052: try {
053: reasons = new PrinterStateReasons(-1);
054: fail("Constructor doesn't throw IllegalArgumentException if "
055: + "initialCapacity < 0");
056: } catch (IllegalArgumentException e) {
057: }
058: }
059:
060: /*
061: * PrinterStateReasons(Map map) constructor testing.
062: */
063: public final void testPrinterStateReasonsMap() {
064: HashMap map = new HashMap();
065: map.put(PrinterStateReason.TONER_LOW, Severity.WARNING);
066: map.put(PrinterStateReason.DEVELOPER_LOW, Severity.WARNING);
067: map.put(PrinterStateReason.MEDIA_LOW, Severity.ERROR);
068: reasons = new PrinterStateReasons(map);
069:
070: assertEquals(3, reasons.size());
071: assertTrue(reasons.containsKey(PrinterStateReason.TONER_LOW));
072: assertTrue(reasons
073: .containsKey(PrinterStateReason.DEVELOPER_LOW));
074: assertTrue(reasons.containsKey(PrinterStateReason.MEDIA_LOW));
075:
076: try {
077: map = new HashMap();
078: map.put(PrinterStateReason.MEDIA_LOW, PrinterState.IDLE);
079: reasons = new PrinterStateReasons(map);
080: fail("Constructor doesn't throw ClassCastException if "
081: + "some value in the map isn't Severity");
082: } catch (ClassCastException e) {
083: }
084:
085: try {
086: map = new HashMap();
087: map.put(PrinterState.IDLE, Severity.ERROR);
088: reasons = new PrinterStateReasons(map);
089: fail("Constructor doesn't throw ClassCastException if "
090: + "some key in the map isn't PrinterStateReason");
091: } catch (ClassCastException e) {
092: }
093:
094: try {
095: map = new HashMap();
096: Severity severity = null;
097: map.put(PrinterStateReason.COVER_OPEN, severity);
098: reasons = new PrinterStateReasons(map);
099: fail("Constructor doesn't throw NullPointerException if "
100: + "some key in the map is null");
101: } catch (NullPointerException e) {
102: }
103:
104: try {
105: map.put(null, Severity.REPORT);
106: reasons = new PrinterStateReasons(map);
107: fail("Constructor doesn't throw NullPointerException if "
108: + "some value in the map is null");
109: } catch (NullPointerException e) {
110: }
111:
112: try {
113: map = null;
114: reasons = new PrinterStateReasons(map);
115: fail("Constructor doesn't throw NullPointerException if "
116: + "map is null");
117: } catch (NullPointerException e) {
118: }
119:
120: }
121:
122: /*
123: * getCategory() method testing.
124: */
125: public final void testGetCategory() {
126: reasons = new PrinterStateReasons();
127: assertEquals(PrinterStateReasons.class, reasons.getClass());
128: }
129:
130: /*
131: * getName() method testing.
132: */
133: public final void testGetName() {
134: reasons = new PrinterStateReasons();
135: assertEquals("printer-state-reasons", reasons.getName());
136: }
137:
138: /*
139: * printerStateReasonSet(Severity severity) method testing.
140: */
141: public final void testPrinterStateReasonSet() {
142: reasons = new PrinterStateReasons();
143: reasons.put(PrinterStateReason.MEDIA_LOW, Severity.ERROR);
144: HashSet set = new HashSet();
145: set.add(PrinterStateReason.MEDIA_LOW);
146: assertEquals(set, reasons.printerStateReasonSet(Severity.ERROR));
147: set = new HashSet();
148: assertEquals(set, reasons
149: .printerStateReasonSet(Severity.REPORT));
150: }
151:
152: /*
153: * printerStateReasonSet(Severity severity) method testing.
154: */
155: public final void testPrinterStateReasonSet1() {
156: reasons = new PrinterStateReasons();
157: reasons.put(PrinterStateReason.COVER_OPEN, Severity.ERROR);
158: reasons.put(PrinterStateReason.MEDIA_LOW, Severity.WARNING);
159: reasons.put(PrinterStateReason.DOOR_OPEN, Severity.ERROR);
160: reasons.put(PrinterStateReason.INPUT_TRAY_MISSING,
161: Severity.ERROR);
162:
163: Set set = reasons.printerStateReasonSet(Severity.ERROR);
164: try {
165: set.iterator().remove();
166: fail("Unmodifiable set was changed");
167: } catch (UnsupportedOperationException e) {
168: }
169:
170: try {
171: set.add(PrinterStateReason.COVER_OPEN);
172: fail("Unmodifiable set was changed");
173: } catch (UnsupportedOperationException e) {
174:
175: }
176: }
177: }
|