source: josm/trunk/test/unit/org/openstreetmap/josm/gui/util/WindowGeometryTest.java @ 12679

Last change on this file since 12679 was 12679, checked in by Don-vip, 16 months ago

see #15182 - make actions.downloadtasks.Download*Task depend on io.OsmServerLocationReader, not the opposite

  • Property svn:eol-style set to native
File size: 5.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.util;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertFalse;
6import static org.junit.Assert.assertNotNull;
7import static org.junit.Assert.assertTrue;
8
9import java.awt.Dimension;
10import java.awt.Point;
11import java.awt.Rectangle;
12
13import javax.swing.JLabel;
14import javax.swing.JPanel;
15
16import org.junit.Rule;
17import org.junit.Test;
18import org.openstreetmap.josm.Main;
19import org.openstreetmap.josm.gui.util.WindowGeometry.WindowGeometryException;
20import org.openstreetmap.josm.testutils.JOSMTestRules;
21
22import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
23import nl.jqno.equalsverifier.EqualsVerifier;
24import nl.jqno.equalsverifier.Warning;
25
26/**
27 * Unit tests of {@link WindowGeometry} class.
28 */
29public class WindowGeometryTest {
30    /**
31     * Some of this depends on preferences.
32     */
33    @Rule
34    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
35    public JOSMTestRules test = new JOSMTestRules().preferences();
36
37    /**
38     * Test of {@link WindowGeometry#centerInWindow} method.
39     */
40    @Test
41    public void testCenterInWindow() {
42        assertNotNull(WindowGeometry.centerInWindow(null, null));
43        assertNotNull(WindowGeometry.centerInWindow(new JPanel(), null));
44    }
45
46    /**
47     * Test of {@link WindowGeometry#centerOnScreen} method.
48     */
49    @Test
50    public void testCenterOnScreen() {
51        Dimension dim = new Dimension(200, 100);
52        assertEquals(new WindowGeometry(new Point(0, 0), dim), WindowGeometry.centerOnScreen(dim));
53        assertEquals(new WindowGeometry(new Point(300, 250), dim), WindowGeometry.centerOnScreen(dim, null));
54
55        Main.pref.put("gui.geometry", "x=0,y=0,width=800,height=600");
56        assertEquals(new WindowGeometry(new Point(300, 250), dim), WindowGeometry.centerOnScreen(dim));
57    }
58
59    /**
60     * Test of {@link WindowGeometry.WindowGeometryException} class.
61     * @throws WindowGeometryException always
62     */
63    @Test(expected = WindowGeometryException.class)
64    public void testWindowGeometryException1() throws WindowGeometryException {
65        Main.pref.put("test", null);
66        new WindowGeometry("test");
67    }
68
69    /**
70     * Test of {@link WindowGeometry.WindowGeometryException} class.
71     * @throws WindowGeometryException always
72     */
73    @Test(expected = WindowGeometryException.class)
74    public void testWindowGeometryException2() throws WindowGeometryException {
75        Main.pref.put("test", "");
76        new WindowGeometry("test");
77    }
78
79    /**
80     * Test of {@link WindowGeometry.WindowGeometryException} class.
81     * @throws WindowGeometryException always
82     */
83    @Test(expected = WindowGeometryException.class)
84    public void testWindowGeometryException3() throws WindowGeometryException {
85        Main.pref.put("test", "x=not_a_number");
86        new WindowGeometry("test");
87    }
88
89    /**
90     * Test of {@link WindowGeometry.WindowGeometryException} class.
91     * @throws WindowGeometryException always
92     */
93    @Test(expected = WindowGeometryException.class)
94    public void testWindowGeometryException4() throws WindowGeometryException {
95        Main.pref.put("test", "wrong_pattern");
96        new WindowGeometry("test");
97    }
98
99    /**
100     * Test of {@link WindowGeometry.WindowGeometryException} class.
101     * @throws WindowGeometryException never
102     */
103    @Test
104    public void testWindowGeometryException5() throws WindowGeometryException {
105        Main.pref.put("test", "x=15,y=55,width=200,height=100");
106        assertNotNull(new WindowGeometry("test"));
107    }
108
109    /**
110     * Test of {@link WindowGeometry#isBugInMaximumWindowBounds} method.
111     */
112    @Test
113    public void testIsBugInMaximumWindowBounds() {
114        assertFalse(WindowGeometry.isBugInMaximumWindowBounds(new Rectangle(10, 10)));
115        assertTrue(WindowGeometry.isBugInMaximumWindowBounds(new Rectangle(10, 0)));
116        assertTrue(WindowGeometry.isBugInMaximumWindowBounds(new Rectangle(0, 10)));
117    }
118
119    /**
120     * Test of {@link WindowGeometry#getVirtualScreenBounds} method.
121     */
122    @Test
123    public void testGetVirtualScreenBounds() {
124        assertNotNull(WindowGeometry.getVirtualScreenBounds());
125    }
126
127    /**
128     * Test of {@link WindowGeometry#getMaxDimensionOnScreen} method.
129     */
130    @Test
131    public void testGetMaxDimensionOnScreen() {
132        assertNotNull(WindowGeometry.getMaxDimensionOnScreen(new JLabel()));
133    }
134
135    /**
136     * Test of {@link WindowGeometry#toString} method.
137     */
138    @Test
139    public void testToString() {
140        assertEquals("WindowGeometry{topLeft=java.awt.Point[x=0,y=0],extent=java.awt.Dimension[width=0,height=0]}",
141                new WindowGeometry(new Rectangle()).toString());
142    }
143
144    /**
145     * Unit test of methods {@link WindowGeometry#equals} and {@link WindowGeometry#hashCode}.
146     */
147    @Test
148    public void testEqualsContract() {
149        EqualsVerifier.forClass(WindowGeometry.class).usingGetClass()
150            .suppress(Warning.NONFINAL_FIELDS)
151            .verify();
152    }
153}
Note: See TracBrowser for help on using the repository browser.