1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.imaging;
19
20 import static org.junit.jupiter.api.Assertions.assertEquals;
21
22 import java.io.File;
23 import java.util.Arrays;
24 import java.util.stream.Stream;
25
26 import org.apache.commons.io.FilenameUtils;
27 import org.junit.jupiter.params.ParameterizedTest;
28 import org.junit.jupiter.params.provider.MethodSource;
29
30 public class ImagingGuessFormatTest extends AbstractImagingTest {
31
32 public static final String BMP_IMAGE_FILE = "bmp\\1\\Oregon Scientific DS6639 - DSC_0307 - small.bmp";
33 public static final String PNG_IMAGE_FILE = "png\\1\\Oregon Scientific DS6639 - DSC_0307 - small.png";
34 public static final String GIF_IMAGE_FILE = "gif\\single\\1\\Oregon Scientific DS6639 - DSC_0307 - small.gif";
35 public static final String ICNS_IMAGE_FILE = "icns\\1\\poedit48x48.icns";
36 public static final String ICO_IMAGE_FILE = "ico\\1\\Oregon Scientific DS6639 - DSC_0307 - small.ico";
37 public static final String TIFF_IMAGE_FILE = "tiff\\1\\Oregon Scientific DS6639 - DSC_0307 - small.tif";
38 public static final String JPEG_IMAGE_FILE = "jpg\\1\\Oregon Scientific DS6639 - DSC_0307 - small.jpg";
39 public static final String PSD_IMAGE_FILE = "psd\\1\\Oregon Scientific DS6639 - DSC_0307 - small.psd";
40 public static final String PBM_IMAGE_FILE = "pbm\\1\\Oregon Scientific DS6639 - DSC_0307 - small.pbm";
41 public static final String PGM_IMAGE_FILE = "pbm\\1\\Oregon Scientific DS6639 - DSC_0307 - small.pgm";
42 public static final String PPM_IMAGE_FILE = "pbm\\1\\Oregon Scientific DS6639 - DSC_0307 - small.ppm";
43 public static final String TGA_IMAGE_FILE = "tga\\1\\Oregon Scientific DS6639 - DSC_0307 - small.tga";
44 public static final String UNKNOWN_IMAGE_FILE = "info.txt";
45
46 public static Stream<Object[]> data() {
47 return Arrays.asList(new Object[] { ImageFormats.PNG, PNG_IMAGE_FILE }, new Object[] { ImageFormats.GIF, GIF_IMAGE_FILE },
48 new Object[] { ImageFormats.ICNS, ICNS_IMAGE_FILE },
49
50
51 new Object[] { ImageFormats.TIFF, TIFF_IMAGE_FILE }, new Object[] { ImageFormats.JPEG, JPEG_IMAGE_FILE },
52 new Object[] { ImageFormats.BMP, BMP_IMAGE_FILE }, new Object[] { ImageFormats.PSD, PSD_IMAGE_FILE },
53 new Object[] { ImageFormats.PBM, PBM_IMAGE_FILE }, new Object[] { ImageFormats.PGM, PGM_IMAGE_FILE },
54 new Object[] { ImageFormats.PPM, PPM_IMAGE_FILE },
55
56
57
58
59
60 new Object[] { ImageFormats.UNKNOWN, UNKNOWN_IMAGE_FILE }).stream();
61 }
62
63 @ParameterizedTest
64 @MethodSource("data")
65 public void testGuessFormat(final ImageFormats expectedFormat, final String pathToFile) throws Exception {
66 final String imagePath = FilenameUtils.separatorsToSystem(pathToFile);
67 final File imageFile = new File(ImagingTestConstants.TEST_IMAGE_FOLDER, imagePath);
68
69 final ImageFormat guessedFormat = Imaging.guessFormat(imageFile);
70 assertEquals(expectedFormat, guessedFormat);
71 }
72
73 }