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