Skip to content

Commit 75b7c79

Browse files
amosshiGoeLin
authored andcommitted
8300405: Screen capture for test JFileChooserSetLocationTest.java, failure case
Backport-of: db8fa1be052c8558398ea5fea2105458f1a3cd16
1 parent 6e34daa commit 75b7c79

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

test/jdk/javax/swing/JFileChooser/JFileChooserSetLocationTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,23 @@
2323

2424
import java.awt.Component;
2525
import java.awt.Dimension;
26+
import java.awt.GraphicsConfiguration;
27+
import java.awt.GraphicsEnvironment;
2628
import java.awt.HeadlessException;
2729
import java.awt.Point;
30+
import java.awt.Rectangle;
2831
import java.awt.Robot;
2932
import java.awt.event.ActionListener;
3033
import java.awt.event.InputEvent;
3134
import java.awt.event.KeyEvent;
35+
import java.awt.image.BufferedImage;
36+
import java.io.File;
3237
import java.util.Arrays;
3338
import java.util.List;
3439
import java.util.concurrent.atomic.AtomicBoolean;
3540
import java.util.concurrent.atomic.AtomicReference;
3641
import java.util.stream.Collectors;
42+
import javax.imageio.ImageIO;
3743
import javax.swing.JButton;
3844
import javax.swing.JDialog;
3945
import javax.swing.JFileChooser;
@@ -175,12 +181,18 @@ private static Point getActualLocation(final MyFileChooser fcoo)
175181
return pt.get();
176182
}
177183

178-
public static void verify(int x1, int x2, int y1, int y2) {
184+
public static void verify(int x1, int x2, int y1, int y2) throws Exception {
179185
System.out.println("verify " + x1 + "==" + x2 + "; " + y1 + "==" + y2);
180186
if ((Math.abs(x1 - x2) < TOLERANCE_LEVEL) &&
181187
(Math.abs(y1 - y2) < TOLERANCE_LEVEL)) {
182188
System.out.println("Test passed");
183189
} else {
190+
GraphicsConfiguration gc = GraphicsEnvironment.
191+
getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
192+
Rectangle gcBounds = gc.getBounds();
193+
BufferedImage bufferedImage = robot.createScreenCapture(
194+
new Rectangle(gcBounds));
195+
ImageIO.write(bufferedImage, "png",new File("FailureImage.png"));
184196
throw new RuntimeException(
185197
"Test Failed, setLocation() is not working properly");
186198
}

0 commit comments

Comments
 (0)