1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.aikiit.fotorenamer.image;
17
18 import de.aikiit.fotorenamer.TestConstants;
19 import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants;
20 import org.apache.log4j.Logger;
21 import org.junit.jupiter.api.Test;
22
23 import java.io.File;
24 import java.util.regex.Matcher;
25
26 import static org.junit.jupiter.api.Assertions.assertThrows;
27 import static org.junit.jupiter.api.Assertions.assertTrue;
28
29
30
31
32
33
34 class MetaDataExtractorTest {
35 private static final Logger LOG = Logger.getLogger(MetaDataExtractorTest.class);
36
37 @Test
38 void makeSurePatternMatchesMultipleRenamedFiles() {
39 Matcher matcher = TestConstants.IS_TEST_FILE.matcher("123123123123_20110130_131102_IMG_7559_mini.JpG");
40 assertTrue(matcher.find());
41 }
42
43 @Test
44 void ensureGivenExampleFileIsRenamed() throws Exception {
45 File f = new File(TestConstants.FULLPATH_TEST_IMG);
46
47 int minLength = TestConstants.PLAIN_FILE_NAME.length();
48
49 if (!f.exists()) {
50 LOG.debug("Switching to renamed file, since another test may have touched it before.");
51 f = new File(TestConstants.FULLPATH_TEST_IMG_RENAMED);
52 minLength = f.getName().length();
53 }
54
55 LOG.debug("Extracting metadata from " + f.getAbsolutePath());
56
57 String renamedFile =
58 MetaDataExtractor
59 .generateCreationDateInCorrectFormat(f);
60 assertTrue(renamedFile.endsWith(TestConstants.PLAIN_FILE_NAME));
61 assertTrue(renamedFile.length() >= minLength);
62 }
63
64
65
66
67 @Test
68 void checkAssertionErrors() {
69 assertThrows(AssertionError.class, () -> MetaDataExtractor.getExifMetadata(null, ExifTagConstants.EXIF_TAG_BRIGHTNESS));
70 }
71
72
73
74
75 @Test
76 void checkAssertionErrorTag() {
77 assertThrows(AssertionError.class, () -> MetaDataExtractor.getExifMetadata(new File(TestConstants.FULLPATH_TEST_IMG), null));
78 }
79
80 }