1 /*
   2 @test
   3 @bug 7023011
   4 @library ../../../regtesthelpers
   5 @build Sysout
   6 @summary Toolkit.getPrintJob() throws wrong exceptions
   7 @author andrei dmitriev: area=awt.headless
   8 @run main/othervm -Djava.awt.headless=true GetPrintJobHeadless
   9  */
  10 
  11 /*
  12  * In headless mode we should always getting NPE on the getPrintJob() call
  13  */
  14 import java.awt.*;
  15 import java.util.Properties;
  16 import test.java.awt.regtesthelpers.Sysout;
  17 
  18 public class GetPrintJobHeadless {
  19 
  20     public static void main(String[] s) {
  21         boolean stage1Passed = false;
  22         boolean stage2Passed = false;
  23 
  24         try {
  25             Toolkit.getDefaultToolkit().getPrintJob(
  26                     (Frame) null, "title", new Properties());
  27         } catch (NullPointerException e) {
  28             stage1Passed = true;
  29             e.printStackTrace();
  30             Sysout.println("Stage 1 passed. getPrintJob(null, String, property) has thrown NPE.");
  31         }
  32         if (!stage1Passed) {
  33             throw new RuntimeException("getPrintJob() should have thrown NPE but didn't.");
  34         }
  35 
  36         try {
  37             Toolkit.getDefaultToolkit().getPrintJob(
  38                     (Frame) null, "title", new JobAttributes(), new PageAttributes());
  39         } catch (NullPointerException e) {
  40             stage2Passed = true;
  41             e.printStackTrace();
  42             Sysout.println("Stage 2 passed. getPrintJob(null, String, jobAttrs, pageAttr) has thrown  NPE.");
  43         }
  44         if (!stage2Passed) {
  45             throw new RuntimeException("getPrintJob() should have thrown NPE but didn't.");
  46         }
  47 
  48         Sysout.println("Test PASSED");
  49     }
  50 }