1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.imaging.formats.icns;
19
20 import org.apache.commons.imaging.ImageInfo;
21 import org.apache.commons.imaging.ImageReadException;
22 import org.apache.commons.imaging.Imaging;
23 import org.junit.jupiter.api.Assertions;
24 import org.junit.jupiter.api.Disabled;
25 import org.junit.jupiter.params.ParameterizedTest;
26 import org.junit.jupiter.params.provider.Arguments;
27 import org.junit.jupiter.params.provider.MethodSource;
28
29 import java.awt.image.BufferedImage;
30 import java.io.File;
31 import java.io.IOException;
32 import java.util.Arrays;
33 import java.util.List;
34 import java.util.stream.Stream;
35
36 import static org.junit.jupiter.api.Assertions.assertEquals;
37 import static org.junit.jupiter.api.Assertions.assertNotNull;
38
39 public class IcnsReadTest extends IcnsBaseTest {
40
41 public static Stream<File> data() throws Exception {
42 return getIcnsImages().stream();
43 }
44
45
46
47
48
49
50
51
52
53
54 public static Stream<Arguments> provideIcnsImagesWithMonoAndJpegPngData() {
55 return Arrays
56 .asList(
57 Arguments.of("/images/icns/IMAGING-248/python.icns", 7),
58 Arguments.of("/images/icns/IMAGING-248/groovy.icns", 3))
59 .stream();
60 }
61
62 @Disabled(value = "RoundtripTest has to be fixed befor implementation can throw UnsupportedOperationException")
63 @ParameterizedTest
64 @MethodSource("data")
65 public void testImageMetadata(final File imageFile) {
66 Assertions.assertThrows(UnsupportedOperationException.class, () -> Imaging.getMetadata(imageFile));
67 }
68
69 @ParameterizedTest
70 @MethodSource("data")
71 public void testImageInfo(final File imageFile) throws Exception {
72 final ImageInfo imageInfo = Imaging.getImageInfo(imageFile);
73 assertNotNull(imageInfo);
74 }
75
76 @ParameterizedTest
77 @MethodSource("data")
78 public void testBufferedImage(final File imageFile) throws Exception {
79 final BufferedImage image = Imaging.getBufferedImage(imageFile);
80 assertNotNull(image);
81
82 }
83
84
85
86
87
88
89
90 @ParameterizedTest()
91 @MethodSource("provideIcnsImagesWithMonoAndJpegPngData")
92 public void testIcnsElementMonoPngJpeg(final String file, final int numberOfImages) throws ImageReadException, IOException {
93 final File testFile = new File(IcnsReadTest.class.getResource(file).getFile());
94 final List<BufferedImage> images = new IcnsImageParser().getAllBufferedImages(testFile);
95 assertEquals(numberOfImages, images.size());
96 }
97 }