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.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       * @throws Exception in case of errors.
42       */
43      @Test
44      public void checkNPECorrectnessInConstructor() throws Exception {
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      @Test
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  }