1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.imaging.formats.gif;
19
20 import java.io.File;
21 import java.io.IOException;
22 import java.util.List;
23
24 import org.apache.commons.imaging.AbstractImagingTest;
25 import org.apache.commons.imaging.ImageFormat;
26 import org.apache.commons.imaging.ImageFormats;
27 import org.apache.commons.imaging.Imaging;
28 import org.apache.commons.imaging.ImagingException;
29
30 public abstract class AbstractGifTest extends AbstractImagingTest {
31
32 private final static String ANIMATED_FOLDER_NAME = "animated";
33
34 private final static String SINGLE_IMAGE_FOLDER_NAME = "single";
35
36 private static final ImageFilter IMAGE_FILTER = AbstractGifTest::isGif;
37
38 private static final ImageFilter ANIMATED_IMAGE_FILTER = file -> isGif(file) && isAnimated(file);
39
40 private static final ImageFilter SINGLE_IMAGE_FILTER = file -> isGif(file) && isSingleImage(file);
41
42 protected static List<File> getAnimatedGifImages() throws IOException, ImagingException {
43 return getTestImages(ANIMATED_IMAGE_FILTER);
44 }
45
46 protected static List<File> getGifImages() throws IOException, ImagingException {
47 return getTestImages(IMAGE_FILTER);
48 }
49
50 protected static List<File> getGifImagesWithSingleImage() throws IOException, ImagingException {
51 return getTestImages(SINGLE_IMAGE_FILTER);
52 }
53
54 private static boolean isAnimated(final File file) {
55 final File index = file.getParentFile();
56 final File type = index.getParentFile();
57 return type.getName().equals(ANIMATED_FOLDER_NAME);
58 }
59
60 private static boolean isGif(final File file) throws IOException {
61 final ImageFormat format = Imaging.guessFormat(file);
62 return format == ImageFormats.GIF;
63 }
64
65 private static boolean isSingleImage(final File file) {
66 final File index = file.getParentFile();
67 final File type = index.getParentFile();
68 return type.getName().equals(SINGLE_IMAGE_FOLDER_NAME);
69 }
70
71 }