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.ArrayList;
023:
024: import junit.framework.TestCase;
025:
026: public class JobStateReasonsTest extends TestCase {
027:
028: public static void main(String[] args) {
029: junit.textui.TestRunner.run(JobStateReasonsTest.class);
030: }
031:
032: static {
033: System.out.println("JobStateReasons testing...");
034: }
035:
036: /*
037: * JobStateReasons() constructor testing.
038: */
039: public final void testJobStateReasons() {
040: JobStateReasons jsrs = new JobStateReasons();
041: assertEquals(0, jsrs.size());
042: }
043:
044: /*
045: * JobStateReasons(Collection collection) constructor testing.
046: */
047: public final void testJobStateReasonsCollection() {
048:
049: ArrayList list = new ArrayList(5);
050: list.add(JobStateReason.ABORTED_BY_SYSTEM);
051: list.add(JobStateReason.COMPRESSION_ERROR);
052: list.add(JobStateReason.DOCUMENT_ACCESS_ERROR);
053: list.add(JobState.ABORTED);
054: try {
055: JobStateReasons jsreasons = new JobStateReasons(list);
056: fail("Constructor doesn't throw ClassCastException if "
057: + "some element of the collection isn't JobStateReason");
058: } catch (ClassCastException e) {
059: }
060:
061: list.remove(JobState.ABORTED);
062: JobStateReasons jsrs = new JobStateReasons(list);
063: JobStateReason reason = null;
064: list.add(reason);
065: try {
066: JobStateReasons jsreasons = new JobStateReasons(list);
067: fail("Constructor doesn't throw NullPointerException if "
068: + "some element of the collection is null");
069: } catch (NullPointerException e) {
070: }
071:
072: list.remove(reason);
073: JobStateReasons jsreasons = new JobStateReasons(list);
074: assertEquals(3, jsreasons.size());
075: assertTrue(jsreasons.contains(JobStateReason.ABORTED_BY_SYSTEM));
076: assertTrue(jsreasons.contains(JobStateReason.COMPRESSION_ERROR));
077: assertTrue(jsreasons
078: .contains(JobStateReason.DOCUMENT_ACCESS_ERROR));
079: }
080:
081: /*
082: * JobStateReasons(int initialCapacity) constructor testing.
083: */
084: public final void testJobStateReasonsint() {
085: try {
086: JobStateReasons jsreasons = new JobStateReasons(-1);
087: fail("Constructor doesn't throw IllegalArgumentException if "
088: + "initialCapacity < 0");
089: } catch (IllegalArgumentException e) {
090: }
091: }
092:
093: /*
094: *add(JobStateReason jsr) method testing.
095: */
096: public final void testAdd() {
097:
098: JobStateReasons jsreasons = new JobStateReasons(5);
099: assertTrue(jsreasons.add(JobStateReason.ABORTED_BY_SYSTEM));
100: assertFalse(jsreasons.add(JobStateReason.ABORTED_BY_SYSTEM));
101:
102: try {
103: assertTrue(jsreasons.add(null));
104: fail("Method doesn't throw NullPointerException if "
105: + "adding element is null");
106: } catch (NullPointerException e) {
107: }
108:
109: ArrayList list = new ArrayList(5);
110: list.add(JobStateReason.COMPRESSION_ERROR);
111: list.add(JobStateReason.JOB_PRINTING);
112: jsreasons = new JobStateReasons(list);
113: assertTrue(jsreasons.add(JobStateReason.ABORTED_BY_SYSTEM));
114: assertFalse(jsreasons.add(JobStateReason.JOB_PRINTING));
115: }
116:
117: /*
118: * getCategory() method testing.
119: */
120: public final void testGetCategory() {
121: JobStateReasons jsreasons = new JobStateReasons();
122: assertEquals(JobStateReasons.class, jsreasons.getCategory());
123: }
124:
125: /*
126: * getName() method testing.
127: */
128: public final void testGetName() {
129: JobStateReasons jsreasons = new JobStateReasons();
130: assertEquals("job-state-reasons", jsreasons.getName());
131: }
132:
133: }
|