View Javadoc
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.Disabled;
20  import org.junit.jupiter.api.Test;
21  
22  import java.io.File;
23  
24  import static de.aikiit.fotorenamer.TestConstants.FULLPATH_IMAGES;
25  import static de.aikiit.fotorenamer.TestConstants.FULLPATH_TEST_IMG;
26  import static org.junit.jupiter.api.Assertions.*;
27  
28  /**
29   * Test image renaming.
30   *
31   * @author hirsch
32   * @version 2011-06-02, 13:41
33   */
34  class CreationDateFromExifImageRenamerTest {
35  
36      private static final Logger LOG = Logger.
37              getLogger(CreationDateFromExifImageRenamerTest.class);
38  
39      /**
40       * Ensure that no NullPointerException is thrown with null arguments.
41       *
42       */
43      @Test
44      public void checkNPECorrectnessInConstructor() {
45          assertThrows(InvalidDirectoryException.class, () -> {
46              CreationDateFromExifImageRenamer imageRenamer = new
47                      CreationDateFromExifImageRenamer(null);
48              // just to avoid compiler warnings, code will not be reached
49              assertNotNull(imageRenamer);
50          });
51      }
52  
53      /**
54       * Perform file renaming (while waiting for Thread to finish).
55       *
56       * @throws Exception in case of errors.
57       */
58      // TODO redesign application - component mingles function and GUI and is
59      // not clearly testable
60      @Disabled("Since GHA cannot close the app")
61      public void renameTestImageAndDeleteFileAfterwards() throws Exception {
62  
63          LOG.info("Working on file " + FULLPATH_TEST_IMG);
64          assertTrue(new File(FULLPATH_TEST_IMG).exists());
65          assertTrue(new File(FULLPATH_TEST_IMG).exists());
66  
67          CreationDateFromExifImageRenamer renamer = new CreationDateFromExifImageRenamer(FULLPATH_IMAGES);
68          Thread t = new Thread(renamer);
69          t.start();
70          assertTrue(t.isAlive());
71          // wait until thread is finished
72          t.join();
73          assertEquals(Thread.State.TERMINATED, t.getState());
74  
75          // FIXME since MetadataExtractorTest renames the image,
76          // it has twice the prefix
77  /*
78          assertTrue("Renamed test image has to exist afterwards.",
79                  new File
80                          (TestConstants.FULLPATH_IMAGES +
81                                  "20110130_131102_20110130_131102_IMG_7559_mini.JPG").exists());
82                                  */
83      }
84  
85  }