1 /*
2 Copyright 2011, Aiki IT, FotoRenamer
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 */
15 package de.aikiit.fotorenamer.image;
16
17 import de.aikiit.fotorenamer.exception.InvalidDirectoryException;
18 import org.apache.log4j.Logger;
19 import org.junit.jupiter.api.Test;
20
21 import java.io.File;
22
23 import static de.aikiit.fotorenamer.TestConstants.FULLPATH_IMAGES;
24 import static de.aikiit.fotorenamer.TestConstants.FULLPATH_TEST_IMG;
25 import static org.junit.jupiter.api.Assertions.*;
26
27 /**
28 * Test image renaming.
29 *
30 * @author hirsch
31 * @version 2011-06-02, 13:41
32 */
33 class CreationDateFromExifImageRenamerTest {
34
35 private static final Logger LOG = Logger.
36 getLogger(CreationDateFromExifImageRenamerTest.class);
37
38 /**
39 * Ensure that no NullPointerException is thrown with null arguments.
40 *
41 */
42 @Test
43 public void checkNPECorrectnessInConstructor() {
44 assertThrows(InvalidDirectoryException.class, () -> {
45 CreationDateFromExifImageRenamer imageRenamer = new
46 CreationDateFromExifImageRenamer(null);
47 // just to avoid compiler warnings, code will not be reached
48 assertNotNull(imageRenamer);
49 });
50 }
51
52 /**
53 * Perform file renaming (while waiting for Thread to finish).
54 *
55 * @throws Exception in case of errors.
56 */
57 // TODO redesign application - component mingles function and GUI and is
58 // not clearly testable
59 @Test
60 public void renameTestImageAndDeleteFileAfterwards() throws Exception {
61
62 LOG.info("Working on file " + FULLPATH_TEST_IMG);
63 assertTrue(new File(FULLPATH_TEST_IMG).exists());
64 assertTrue(new File(FULLPATH_TEST_IMG).exists());
65
66 CreationDateFromExifImageRenamer renamer = new CreationDateFromExifImageRenamer(FULLPATH_IMAGES);
67 Thread t = new Thread(renamer);
68 t.start();
69 assertTrue(t.isAlive());
70 // wait until thread is finished
71 t.join();
72 assertEquals(Thread.State.TERMINATED, t.getState());
73
74 // FIXME since MetadataExtractorTest renames the image,
75 // it has twice the prefix
76 /*
77 assertTrue("Renamed test image has to exist afterwards.",
78 new File
79 (TestConstants.FULLPATH_IMAGES +
80 "20110130_131102_20110130_131102_IMG_7559_mini.JPG").exists());
81 */
82 }
83
84 }