RFR: 8342098: Write a test to compare the images [v3]
Naveen Narayanan
duke at openjdk.org
Mon Oct 21 16:56:30 UTC 2024
On Mon, 21 Oct 2024 13:49:15 GMT, Alexey Ivanov <aivanov at openjdk.org> wrote:
>> test/jdk/java/awt/Robot/ScreenCaptureRobotTest.java line 133:
>>
>>> 131: return result;
>>> 132: }
>>> 133:
>>
>> Suggestion:
>>
>> //Save BufferedImage to PNG file
>> private static void saveImage(BufferedImage image, String fileName) {
>> if (image != null) {
>> try {
>> File file = new File(fileName);
>> System.out.println("Saving button image to " + file.getAbsolutePath());
>> ImageIO.write(image, "PNG", file);
>> } catch (Exception e) {
>> throw new RuntimeException("Could not write image file");
>> }
>> } else {
>> throw new RuntimeException("BufferedImage was set to null");
>> }
>> }
>
> Yes, please save the images, especially when comparison fails.
>
> I think handling `image != null` is not needed here. If `null` is passed, the test will fail with `NullPointerException`, and it's acceptable. Without the `if` statement, the code to save the image would be cleaner.
Saved images without null check.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/21524#discussion_r1809159884
More information about the client-libs-dev
mailing list