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.util;
16  
17  import org.junit.jupiter.api.Test;
18  
19  import javax.swing.*;
20  import java.awt.*;
21  
22  import static de.aikiit.fotorenamer.util.ComponentGaugeUtil.createImageIcon;
23  import static de.aikiit.fotorenamer.util.ComponentGaugeUtil.makeCentered;
24  import static org.junit.jupiter.api.Assertions.*;
25  
26  /**
27   * Tests util methods.
28   *
29   * @author hirsch
30   * @version 2011-03-21, 13:18
31   */
32  class ComponentGaugeUtilTest {
33      /**
34       * Checks image creation with a valid and an invalid path.
35       */
36      @Test
37      void createIconFromStringPath() {
38          // FIXME not really clear why this location (valid with File-separators) cannot be parsed into an URL
39          // assertNotNull(ComponentGaugeUtil.createImageIcon(MetaDataExtractorTest.FULLPATH_TEST_IMG));
40          assertNull(createImageIcon("wuumansho"));
41      }
42  
43      /**
44       * Checks assertion failure with null parameter.
45       */
46      @Test
47      void createIconFromStringPathWithAssertionFailure() {
48          assertThrows(AssertionError.class, () ->
49                  assertNull(createImageIcon(null))
50          );
51      }
52  
53      /**
54       * Checks that a component gets a non-default location after calling util
55       * method.
56       */
57      @Test
58      void gaugeSwingComponent() {
59          JButton button = new JButton("Test");
60          Point buttonSize = button.getLocation();
61          assertEquals(new Point(0, 0), buttonSize);
62          makeCentered(button);
63          assertNotSame(new Point(0, 0), button.getLocation());
64      }
65  }