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

Last change on this file since 13079 was 13079, checked in by Don-vip, 6 years ago

see #15560 - EqualsVerifier does not work with newer Java versions -> disable tests automatically in this case
Workaround to https://github.com/jqno/equalsverifier/issues/177 / https://github.com/raphw/byte-buddy/issues/370
Inspired by https://issues.apache.org/jira/browse/SOLR-11606

  • Property svn:eol-style set to native
File size: 5.1 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.TestUtils;
19import org.openstreetmap.josm.gui.util.WindowGeometry.WindowGeometryException;
20import org.openstreetmap.josm.spi.preferences.Config;
21import org.openstreetmap.josm.testutils.JOSMTestRules;
22
23import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
24import nl.jqno.equalsverifier.EqualsVerifier;
25import nl.jqno.equalsverifier.Warning;
26
27/**
28 * Unit tests of {@link WindowGeometry} class.
29 */
30public class WindowGeometryTest {
31 /**
32 * Some of this depends on preferences.
33 */
34 @Rule
35 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
36 public JOSMTestRules test = new JOSMTestRules().preferences();
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 Config.getPref().put("gui.geometry", "x=0,y=0,width=800,height=600");
57 assertEquals(new WindowGeometry(new Point(300, 250), dim), WindowGeometry.centerOnScreen(dim));
58 }
59
60 /**
61 * Test of {@link WindowGeometry.WindowGeometryException} class.
62 * @throws WindowGeometryException always
63 */
64 @Test(expected = WindowGeometryException.class)
65 public void testWindowGeometryException1() throws WindowGeometryException {
66 Config.getPref().put("test", null);
67 new WindowGeometry("test");
68 }
69
70 /**
71 * Test of {@link WindowGeometry.WindowGeometryException} class.
72 * @throws WindowGeometryException always
73 */
74 @Test(expected = WindowGeometryException.class)
75 public void testWindowGeometryException2() throws WindowGeometryException {
76 Config.getPref().put("test", "");
77 new WindowGeometry("test");
78 }
79
80 /**
81 * Test of {@link WindowGeometry.WindowGeometryException} class.
82 * @throws WindowGeometryException always
83 */
84 @Test(expected = WindowGeometryException.class)
85 public void testWindowGeometryException3() throws WindowGeometryException {
86 Config.getPref().put("test", "x=not_a_number");
87 new WindowGeometry("test");
88 }
89
90 /**
91 * Test of {@link WindowGeometry.WindowGeometryException} class.
92 * @throws WindowGeometryException always
93 */
94 @Test(expected = WindowGeometryException.class)
95 public void testWindowGeometryException4() throws WindowGeometryException {
96 Config.getPref().put("test", "wrong_pattern");
97 new WindowGeometry("test");
98 }
99
100 /**
101 * Test of {@link WindowGeometry.WindowGeometryException} class.
102 * @throws WindowGeometryException never
103 */
104 @Test
105 public void testWindowGeometryException5() throws WindowGeometryException {
106 Config.getPref().put("test", "x=15,y=55,width=200,height=100");
107 assertNotNull(new WindowGeometry("test"));
108 }
109
110 /**
111 * Test of {@link WindowGeometry#isBugInMaximumWindowBounds} method.
112 */
113 @Test
114 public void testIsBugInMaximumWindowBounds() {
115 assertFalse(WindowGeometry.isBugInMaximumWindowBounds(new Rectangle(10, 10)));
116 assertTrue(WindowGeometry.isBugInMaximumWindowBounds(new Rectangle(10, 0)));
117 assertTrue(WindowGeometry.isBugInMaximumWindowBounds(new Rectangle(0, 10)));
118 }
119
120 /**
121 * Test of {@link WindowGeometry#getVirtualScreenBounds} method.
122 */
123 @Test
124 public void testGetVirtualScreenBounds() {
125 assertNotNull(WindowGeometry.getVirtualScreenBounds());
126 }
127
128 /**
129 * Test of {@link WindowGeometry#getMaxDimensionOnScreen} method.
130 */
131 @Test
132 public void testGetMaxDimensionOnScreen() {
133 assertNotNull(WindowGeometry.getMaxDimensionOnScreen(new JLabel()));
134 }
135
136 /**
137 * Test of {@link WindowGeometry#toString} method.
138 */
139 @Test
140 public void testToString() {
141 assertEquals("WindowGeometry{topLeft=java.awt.Point[x=0,y=0],extent=java.awt.Dimension[width=0,height=0]}",
142 new WindowGeometry(new Rectangle()).toString());
143 }
144
145 /**
146 * Unit test of methods {@link WindowGeometry#equals} and {@link WindowGeometry#hashCode}.
147 */
148 @Test
149 public void testEqualsContract() {
150 TestUtils.assumeWorkingEqualsVerifier();
151 EqualsVerifier.forClass(WindowGeometry.class).usingGetClass()
152 .suppress(Warning.NONFINAL_FIELDS)
153 .verify();
154 }
155}
Note: See TracBrowser for help on using the repository browser.