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.BeforeClass;
|
---|
17 | import org.junit.Test;
|
---|
18 | import org.openstreetmap.josm.JOSMFixture;
|
---|
19 | import org.openstreetmap.josm.Main;
|
---|
20 | import org.openstreetmap.josm.tools.WindowGeometry.WindowGeometryException;
|
---|
21 |
|
---|
22 | import nl.jqno.equalsverifier.EqualsVerifier;
|
---|
23 | import nl.jqno.equalsverifier.Warning;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Unit tests of {@link WindowGeometry} class.
|
---|
27 | */
|
---|
28 | public class WindowGeometryTest {
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Setup test.
|
---|
32 | */
|
---|
33 | @BeforeClass
|
---|
34 | public static void setUp() {
|
---|
35 | JOSMFixture.createUnitTestFixture().init();
|
---|
36 | }
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * Test of {@link WindowGeometry#centerInWindow} method.
|
---|
40 | */
|
---|
41 | @Test
|
---|
42 | public void testCenterInWindow() {
|
---|
43 | assertNotNull(WindowGeometry.centerInWindow(null, null));
|
---|
44 | assertNotNull(WindowGeometry.centerInWindow(new JPanel(), null));
|
---|
45 | }
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Test of {@link WindowGeometry#centerOnScreen} method.
|
---|
49 | */
|
---|
50 | @Test
|
---|
51 | public void testCenterOnScreen() {
|
---|
52 | Dimension dim = new Dimension(200, 100);
|
---|
53 | assertEquals(new WindowGeometry(new Point(0, 0), dim), WindowGeometry.centerOnScreen(dim));
|
---|
54 | assertEquals(new WindowGeometry(new Point(300, 250), dim), WindowGeometry.centerOnScreen(dim, null));
|
---|
55 | }
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Test of {@link WindowGeometry.WindowGeometryException} class.
|
---|
59 | * @throws WindowGeometryException always
|
---|
60 | */
|
---|
61 | @Test(expected = WindowGeometryException.class)
|
---|
62 | public void testWindowGeometryException1() throws WindowGeometryException {
|
---|
63 | Main.pref.put("test", null);
|
---|
64 | new WindowGeometry("test");
|
---|
65 | }
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Test of {@link WindowGeometry.WindowGeometryException} class.
|
---|
69 | * @throws WindowGeometryException always
|
---|
70 | */
|
---|
71 | @Test(expected = WindowGeometryException.class)
|
---|
72 | public void testWindowGeometryException2() throws WindowGeometryException {
|
---|
73 | Main.pref.put("test", "");
|
---|
74 | new WindowGeometry("test");
|
---|
75 | }
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * Test of {@link WindowGeometry.WindowGeometryException} class.
|
---|
79 | * @throws WindowGeometryException always
|
---|
80 | */
|
---|
81 | @Test(expected = WindowGeometryException.class)
|
---|
82 | public void testWindowGeometryException3() throws WindowGeometryException {
|
---|
83 | Main.pref.put("test", "x=not_a_number");
|
---|
84 | new WindowGeometry("test");
|
---|
85 | }
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Test of {@link WindowGeometry.WindowGeometryException} class.
|
---|
89 | * @throws WindowGeometryException always
|
---|
90 | */
|
---|
91 | @Test(expected = WindowGeometryException.class)
|
---|
92 | public void testWindowGeometryException4() throws WindowGeometryException {
|
---|
93 | Main.pref.put("test", "wrong_pattern");
|
---|
94 | new WindowGeometry("test");
|
---|
95 | }
|
---|
96 |
|
---|
97 | /**
|
---|
98 | * Test of {@link WindowGeometry.WindowGeometryException} class.
|
---|
99 | * @throws WindowGeometryException never
|
---|
100 | */
|
---|
101 | @Test
|
---|
102 | public void testWindowGeometryException5() throws WindowGeometryException {
|
---|
103 | Main.pref.put("test", "x=15,y=55,width=200,height=100");
|
---|
104 | assertNotNull(new WindowGeometry("test"));
|
---|
105 | }
|
---|
106 |
|
---|
107 | /**
|
---|
108 | * Test of {@link WindowGeometry#isBugInMaximumWindowBounds} method.
|
---|
109 | */
|
---|
110 | @Test
|
---|
111 | public void testIsBugInMaximumWindowBounds() {
|
---|
112 | assertFalse(WindowGeometry.isBugInMaximumWindowBounds(new Rectangle(10, 10)));
|
---|
113 | assertTrue(WindowGeometry.isBugInMaximumWindowBounds(new Rectangle(10, 0)));
|
---|
114 | assertTrue(WindowGeometry.isBugInMaximumWindowBounds(new Rectangle(0, 10)));
|
---|
115 | }
|
---|
116 |
|
---|
117 | /**
|
---|
118 | * Test of {@link WindowGeometry#getVirtualScreenBounds} method.
|
---|
119 | */
|
---|
120 | @Test
|
---|
121 | public void testGetVirtualScreenBounds() {
|
---|
122 | assertNotNull(WindowGeometry.getVirtualScreenBounds());
|
---|
123 | }
|
---|
124 |
|
---|
125 | /**
|
---|
126 | * Test of {@link WindowGeometry#getMaxDimensionOnScreen} method.
|
---|
127 | */
|
---|
128 | @Test
|
---|
129 | public void testGetMaxDimensionOnScreen() {
|
---|
130 | assertNotNull(WindowGeometry.getMaxDimensionOnScreen(new JLabel()));
|
---|
131 | }
|
---|
132 |
|
---|
133 | /**
|
---|
134 | * Test of {@link WindowGeometry#toString} method.
|
---|
135 | */
|
---|
136 | @Test
|
---|
137 | public void testToString() {
|
---|
138 | assertEquals("WindowGeometry{topLeft=java.awt.Point[x=0,y=0],extent=java.awt.Dimension[width=0,height=0]}",
|
---|
139 | new WindowGeometry(new Rectangle()).toString());
|
---|
140 | }
|
---|
141 |
|
---|
142 | /**
|
---|
143 | * Unit test of methods {@link WindowGeometry#equals} and {@link WindowGeometry#hashCode}.
|
---|
144 | */
|
---|
145 | @Test
|
---|
146 | public void equalsContract() {
|
---|
147 | EqualsVerifier.forClass(WindowGeometry.class).usingGetClass()
|
---|
148 | .suppress(Warning.NONFINAL_FIELDS)
|
---|
149 | .verify();
|
---|
150 | }
|
---|
151 | }
|
---|