01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package javax.print;
19:
20: import javax.print.attribute.PrintServiceAttribute;
21: import javax.print.attribute.standard.Copies;
22: import javax.print.attribute.standard.Destination;
23: import javax.print.attribute.standard.JobName;
24: import javax.print.attribute.standard.PrinterIsAcceptingJobs;
25: import javax.print.attribute.standard.PrinterState;
26: import javax.print.attribute.standard.QueuedJobCount;
27: import javax.print.attribute.standard.RequestingUserName;
28: import junit.framework.TestCase;
29:
30: public class GetAttributeTest extends TestCase {
31: @SuppressWarnings("unchecked")
32: public void testGetAttribute() {
33: PrintService[] services;
34: Object probe;
35: Class[] clazz = new Class[] {
36: PrinterIsAcceptingJobs.ACCEPTING_JOBS.getCategory(),
37: PrinterState.IDLE.getCategory(), QueuedJobCount.class,
38: Destination.class, JobName.class,
39: RequestingUserName.class };
40: services = PrintServiceLookup.lookupPrintServices(null, null);
41: TestUtil.checkServices(services);
42: for (int i = 0, ii = services.length; i < ii; i++) {
43: for (int j = 0, jj = clazz.length; j < jj; j++) {
44: if (PrintServiceAttribute.class
45: .isAssignableFrom(clazz[j])) {
46: probe = services[i].getAttribute(clazz[j]);
47: assertNotNull(probe);
48: }
49: }
50: try {
51: probe = services[i].getAttribute(null);
52: fail("NullPointerException must be thrown - the category is null");
53: } catch (NullPointerException e) {
54: // OK
55: }
56: try {
57: Class<?> invalidClass = Copies.class;
58: probe = services[i]
59: .getAttribute((Class<? extends PrintServiceAttribute>) invalidClass);
60: fail("IllegalArgumentException must be thrown - category is not a Class that implements interface PrintServiceAttribute.");
61: } catch (IllegalArgumentException e) {
62: // OK
63: }
64: }
65: }
66: }
|