
import java.awt.AWTException;
import java.awt.EventQueue;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.time.Instant;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.IntStream;
import javax.swing.JFrame;
import javax.swing.Timer;



/**
 *
 * @author akouznet
 */
public class RobotBlackCaptureTest {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(() -> {
            JFrame jFrame = new JFrame("RobotBlackCaptureTest");
            jFrame.setVisible(true);
            jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            new Timer(1000, a -> {
                try {
                    System.err.print("Capturing at " + Instant.now() + "... ");
                    Robot robot = new Robot();
                    BufferedImage createScreenCapture = robot.createScreenCapture(jFrame.getBounds());
                    assertNotBlack(createScreenCapture);
                    System.err.println("capture is not black!");
                } catch (AWTException ex) {
                    Logger.getLogger(RobotBlackCaptureTest.class.getName()).log(Level.SEVERE, null, ex);
                }
            }).start();
        });
    }
    
    public static void assertNotBlack(BufferedImage image) {
        int w = image.getWidth();
        int h = image.getHeight();
        final boolean value = IntStream.range(0, w).parallel().allMatch(x 
                -> IntStream.range(0, h).allMatch(y
                        -> (image.getRGB(x, y) & 0xffffff) == 0));
        if (value) {
            throw new AssertionError("All pixels are black!");
        }
    }
    
}
