/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.commons.imaging.formats.png;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;

import java.awt.image.BufferedImage;
import java.io.File;
import java.util.List;

import org.apache.commons.imaging.ImageInfo;
import org.apache.commons.imaging.Imaging;
import org.apache.commons.imaging.common.ImageMetadata;
import org.apache.commons.imaging.internal.Debug;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class PngReadTest extends PngBaseTest {

    @Test
    public void test() throws Exception {
        Debug.debug("start");

        final List<File> images = getPngImages();
        for (int i = 0; i < images.size(); i++) {

            final File imageFile = images.get(i);
            Debug.debug("imageFile", imageFile);
            if (isInvalidPNGTestFile(imageFile)) {
                try {
                    Imaging.getMetadata(imageFile);
                    fail("Image read should have failed.");
                } catch (final Exception e) {
                }

                try {
                    Imaging.getImageInfo(imageFile);
                    fail("Image read should have failed.");
                } catch (final Exception e) {
                }

                try {
                    Imaging.getBufferedImage(imageFile);
                    fail("Image read should have failed.");
                } catch (final Exception e) {
                }
            } else {
                final ImageMetadata metadata = Imaging.getMetadata(imageFile);
                Assertions.assertFalse(metadata instanceof File); // Dummy check to avoid unused warning (it may be null)

                final ImageInfo imageInfo = Imaging.getImageInfo(imageFile);
                assertNotNull(imageInfo);

                Debug.debug("ICC profile", Imaging.getICCProfile(imageFile));

                final BufferedImage image = Imaging.getBufferedImage(imageFile);
                assertNotNull(image);
            }
        }
    }

}

@@ -850,124 +850,8 @@
 g;%0A%0A
-import static org.junit.jupiter.api.Assertions.assertNotNull;%0Aimport static org.junit.jupiter.api.Assertions.fail;%0A%0A
 impo
@@ -1199,16 +1199,140 @@
 .Test;%0A%0A
+import static org.junit.jupiter.api.Assertions.assertThrows;%0Aimport static org.junit.jupiter.api.Assertions.assertNotNull;%0A%0A
 public c
@@ -1713,37 +1713,82 @@
                 
-try %7B
+assertThrows(%0A                    Exception.class,
 %0A               
@@ -1783,32 +1783,38 @@
                 
+ () -%3E
  Imaging.getMeta
@@ -1820,33 +1820,33 @@
 adata(imageFile)
-;
+,
 %0A               
@@ -1842,37 +1842,32 @@
                 
-fail(
 %22Image read shou
@@ -1874,34 +1874,32 @@
 ld have failed.%22
-);
 %0A               
@@ -1903,54 +1903,50 @@
     
-%7D catch (final Exception e) %7B%0A        
+);%0A%0A                assertThrows(%0A
         
 %7D%0A%0A 
@@ -1933,35 +1933,32 @@
 Throws(%0A        
-%7D%0A%0A
                 
@@ -1949,37 +1949,48 @@
                 
-try %7B
+Exception.class,
 %0A               
@@ -1985,32 +1985,42 @@
                 
+     () -%3E
  Imaging.getImag
@@ -2027,34 +2027,37 @@
 eInfo(imageFile)
-;%0A
+,%0A   
                 
@@ -2052,37 +2052,33 @@
                 
-fail(
+ 
 %22Image read shou
@@ -2085,34 +2085,32 @@
 ld have failed.%22
-);
 %0A               
@@ -2114,54 +2114,50 @@
     
-%7D catch (final Exception e) %7B%0A        
+);%0A%0A                assertThrows(%0A
         
 %7D%0A%0A 
@@ -2152,19 +2152,16 @@
         
-%7D%0A%0A
         
@@ -2172,13 +2172,24 @@
     
-try %7B
+Exception.class,
 %0A   
@@ -2204,16 +2204,26 @@
         
+     () -%3E
  Imaging
@@ -2242,34 +2242,38 @@
 Image(imageFile)
-;%0A
+,%0A    
                 
@@ -2280,13 +2280,8 @@
     
-fail(
 %22Ima
@@ -2308,18 +2308,16 @@
 failed.%22
-);
 %0A       
@@ -2329,55 +2329,10 @@
     
-%7D catch (final Exception e) %7B%0A                %7D
+);
 %0A   

Use JUnit5 assertThrows style