jdk/test/javax/print/CheckDupFlavor.java
changeset 2697 b27edaf0767e
parent 1720 539a197aefbd
child 5506 202f599c92aa
--- a/jdk/test/javax/print/CheckDupFlavor.java	Wed Apr 15 08:47:21 2009 -0700
+++ b/jdk/test/javax/print/CheckDupFlavor.java	Mon Apr 20 12:31:36 2009 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright 2004-2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 2004-2009 Sun Microsystems, Inc.  All Rights Reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -35,17 +35,19 @@
 
 public class CheckDupFlavor {
     public static void main(String[] args){
-        PrintService pservice =
-                     PrintServiceLookup.lookupDefaultPrintService();
-
-        if (pservice == null) {
-                System.out.println("No default PrintService found. Test ABORTED.");
-            return;
+        PrintService defService = PrintServiceLookup.lookupDefaultPrintService();
+        PrintService[] pservice;
+        if (defService == null) {
+            pservice = PrintServiceLookup.lookupPrintServices(null, null);
+            if (pservice.length == 0) {
+                throw new RuntimeException("No printer found.  TEST ABORTED");
+            }
+            defService = pservice[0];
         }
 
-        System.out.println("Default service = "+pservice);
+        System.out.println("PrintService = "+defService);
 
-        DocFlavor[] flavors = pservice.getSupportedDocFlavors();
+        DocFlavor[] flavors = defService.getSupportedDocFlavors();
         if (flavors==null) {
             System.out.println("No flavors supported. Test PASSED.");
             return;
@@ -54,13 +56,13 @@
 
         ArrayList flavorList = new ArrayList();
         for (int i=0; i<flavors.length; i++) {
-                if (flavors[i] == null) {
-                        throw new RuntimeException("Null flavor. Test FAILED.");
-                } else if (flavorList.contains(flavors[i])) {
-                        throw new RuntimeException("\n\tDuplicate flavor found : "+flavors[i]+" : Test FAILED.");
-                } else {
-                        flavorList.add(flavors[i]);
-                }
+            if (flavors[i] == null) {
+                 throw new RuntimeException("Null flavor. Test FAILED.");
+            } else if (flavorList.contains(flavors[i])) {
+                 throw new RuntimeException("\n\tDuplicate flavor found : "+flavors[i]+" : Test FAILED.");
+            } else {
+                flavorList.add(flavors[i]);
+            }
         }
         System.out.println("No duplicate found. Test PASSED.");
     }