1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.tools;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertFalse;
|
---|
6 | import static org.junit.Assert.assertNotNull;
|
---|
7 | import static org.junit.Assert.assertTrue;
|
---|
8 |
|
---|
9 | import java.awt.Dimension;
|
---|
10 | import java.awt.Point;
|
---|
11 | import java.awt.Rectangle;
|
---|
12 |
|
---|
13 | import javax.swing.JLabel;
|
---|
14 | import javax.swing.JPanel;
|
---|
15 |
|
---|
16 | import org.junit.Rule;
|
---|
17 | import org.junit.Test;
|
---|
18 | import org.openstreetmap.josm.Main;
|
---|
19 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
20 | import org.openstreetmap.josm.tools.WindowGeometry.WindowGeometryException;
|
---|
21 |
|
---|
22 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
23 | import nl.jqno.equalsverifier.EqualsVerifier;
|
---|
24 | import nl.jqno.equalsverifier.Warning;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Unit tests of {@link WindowGeometry} class.
|
---|
28 | */
|
---|
29 | public 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 | }
|
---|