Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import java.awt.Component;
  2. import java.io.*;
  3.  
  4. import static org.junit.Assert.*;
  5.  
  6. import org.netbeans.jemmy.util.PNGEncoder;
  7.  
  8. public class BaseClassSwing {
  9.  
  10.     protected String outputFolder = "";
  11.     protected String inputFolder = "";
  12.     protected String baselineFolder = "";
  13.  
  14.     public BaseClassSwing() {
  15.     }
  16.  
  17.     public void testFiles() {
  18.  
  19.         try {
  20.  
  21.             /**
  22.              * open all files
  23.              */
  24.             File filesToTest = new File(inputFolder);
  25.  
  26.             String[] fileList = filesToTest.list();
  27.  
  28.             //check we have some files
  29.             if (fileList == null) {
  30.                 fail("No files in " + inputFolder);
  31.             }
  32.  
  33.             for (String fileName : fileList) {
  34.                 test(fileName);
  35.             }
  36.  
  37.             //Compare all output and check for changes
  38.             if (compareImages(outputFolder, baselineFolder)) {
  39.                 fail("Current output does not match baseline.");
  40.             }
  41.  
  42.         } catch (Exception e) {
  43.             e.printStackTrace();
  44.             fail(e.toString());
  45.         }
  46.     }
  47.  
  48.     public void getScreenshot(Component com, String filename) {
  49.         PNGEncoder.captureScreen(com, filename, PNGEncoder.COLOR_MODE);
  50.     }
  51.  
  52.     private boolean compareImages(String output, String baseline) {
  53.         /**
  54.          * ADD CODE TO GET FILES FROM FOLDER NAMES AND COMPARE THEM
  55.          */
  56.         return false;
  57.     }
  58.  
  59.     public void test(String testFile) {
  60.         //Do nothing for generic test
  61.     }
  62.  
  63. }