@@ -17,10 +17,9 @@ public class ScreenshotTest {
1717 public void takeScreenshotOfMainScreen () throws Exception {
1818 Rectangle screenRect = new Rectangle (Toolkit .getDefaultToolkit ().getScreenSize ());
1919 BufferedImage capture = new Robot ().createScreenCapture (screenRect );
20- File imageFile = new File ("single-screen. bmp" );
20+ File imageFile = File . createTempFile ("single-screen" , " bmp" );
2121 ImageIO .write (capture , "bmp" , imageFile );
2222 assertTrue (imageFile .exists ());
23- imageFile .delete ();
2423 }
2524
2625 @ Test
@@ -34,21 +33,19 @@ public void takeScreenshotOfAllScreens() throws Exception {
3433 allScreenBounds .height = Math .max (allScreenBounds .height , screenBounds .height );
3534 }
3635 BufferedImage capture = new Robot ().createScreenCapture (allScreenBounds );
37- File imageFile = new File ("all-screens. bmp" );
36+ File imageFile = File . createTempFile ("all-screens" , " bmp" );
3837 ImageIO .write (capture , "bmp" , imageFile );
3938 assertTrue (imageFile .exists ());
40- imageFile .delete ();
4139 }
4240
4341 @ Test
4442 public void makeScreenshot (Component component ) throws Exception {
4543 Rectangle componentRect = component .getBounds ();
4644 BufferedImage bufferedImage = new BufferedImage (componentRect .width , componentRect .height , BufferedImage .TYPE_INT_ARGB );
4745 component .paint (bufferedImage .getGraphics ());
48- File imageFile = new File ("component-screenshot. bmp" );
46+ File imageFile = File . createTempFile ("component-screenshot" , " bmp" );
4947 ImageIO .write (bufferedImage , "bmp" , imageFile );
5048 assertTrue (imageFile .exists ());
51- imageFile .delete ();
5249 }
5350
5451}
0 commit comments