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