I have code that uses the Swing / AWT print function that I want to use unit test. It uses the native system's print dialog box, but is there a way to get the JVM to intercept this and replace it with a layout during unit testing so that I can get a copy of the image to be printed?
My code for printing is simple and looks something like this:
Printable printable = getPrintable(); PrinterJob printJob = PrinterJob.getPrinterJob(); printJob.setPrintable(printable); if (printJob.printDialog()) { try { printJob.print(); } catch (PrinterException exception) { ... } }
I use FEST for my other graphics tests, but it doesn't seem to support printing tests. Is it possible to do this, or will I need to write test documentation that includes QA transfers to check their printer?
source share