source: josm/trunk/test/unit/org/openstreetmap/josm/data/osm/BBoxTest.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: 4.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertFalse;
6import static org.junit.Assert.assertTrue;
7
8import org.junit.Rule;
9import org.junit.Test;
10import org.openstreetmap.josm.TestUtils;
11import org.openstreetmap.josm.data.coor.LatLon;
12import org.openstreetmap.josm.testutils.JOSMTestRules;
13
14import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
15import nl.jqno.equalsverifier.EqualsVerifier;
16import nl.jqno.equalsverifier.Warning;
17
18/**
19 * Unit tests for class {@link BBox}.
20 */
21public class BBoxTest {
22
23 /**
24 * Setup test.
25 */
26 @Rule
27 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
28 public JOSMTestRules test = new JOSMTestRules();
29
30 /**
31 * Unit test of methods {@link BBox#equals} and {@link BBox#hashCode}.
32 */
33 @Test
34 public void testEqualsContract() {
35 TestUtils.assumeWorkingEqualsVerifier();
36 EqualsVerifier.forClass(BBox.class).usingGetClass()
37 .suppress(Warning.NONFINAL_FIELDS)
38 .verify();
39 }
40
41 /**
42 * Test LatLon constructor which might result in invalid bbox
43 */
44 @Test
45 public void testLatLonConstructor() {
46 LatLon latLon1 = new LatLon(10, 20);
47 LatLon latLon2 = new LatLon(20, 10);
48 BBox b1 = new BBox(latLon1, latLon2);
49 BBox b2 = new BBox(latLon2, latLon1);
50 assertTrue(b1.bounds(latLon1));
51 assertTrue(b2.bounds(latLon1));
52 assertTrue(b1.bounds(latLon2));
53 assertTrue(b2.bounds(latLon2));
54 assertTrue(b2.bounds(b1));
55 assertTrue(b1.bounds(b2));
56
57 // outside of world latlon values
58 LatLon outOfWorld = new LatLon(-190, 340);
59 BBox b3 = new BBox(outOfWorld, latLon1);
60 BBox b4 = new BBox(latLon1, outOfWorld);
61 BBox b5 = new BBox(outOfWorld, outOfWorld);
62
63 assertTrue(b3.isValid());
64 assertTrue(b4.isValid());
65 assertTrue(b3.bounds(latLon1));
66 assertTrue(b4.bounds(latLon1));
67 assertTrue(b5.isValid());
68 assertFalse(b3.isInWorld());
69 assertFalse(b4.isInWorld());
70 assertFalse(b5.isInWorld());
71 }
72
73 /**
74 * Test double constructor which might result in invalid bbox
75 */
76 @Test
77 public void testDoubleConstructor() {
78 assertTrue(new BBox(1, 2, 3, 4).isValid());
79 assertFalse(new BBox(Double.NaN, 2, 3, 4).isValid());
80 assertFalse(new BBox(1, Double.NaN, 3, 4).isValid());
81 assertFalse(new BBox(1, 2, Double.NaN, 4).isValid());
82 assertFalse(new BBox(1, 2, 3, Double.NaN).isValid());
83 }
84
85 /**
86 * Test Node constructor which might result in invalid bbox
87 */
88 @Test
89 public void testNodeConstructor() {
90 assertTrue(new BBox(new Node(LatLon.NORTH_POLE)).isValid());
91 assertFalse(new BBox(new Node()).isValid());
92 }
93
94 /**
95 * Unit test of {@link BBox#add(LatLon)} method.
96 */
97 @Test
98 public void testAddLatLon() {
99 BBox b = new BBox();
100 b.add((LatLon) null);
101 b.add(new LatLon(Double.NaN, Double.NaN));
102 assertFalse(b.isValid());
103 b.add(LatLon.NORTH_POLE);
104 assertTrue(b.isValid());
105 assertEquals(LatLon.NORTH_POLE, b.getCenter());
106 }
107
108 /**
109 * Unit test of {@link BBox#add(double, double)} method.
110 */
111 @Test
112 public void testAddDouble() {
113 BBox b = new BBox();
114 b.add(1, Double.NaN);
115 assertFalse(b.isValid());
116 b.add(Double.NaN, 2);
117 assertFalse(b.isValid());
118 b.add(1, 2);
119 assertTrue(b.isValid());
120 assertEquals(new LatLon(2, 1), b.getCenter());
121 }
122
123 /**
124 * Unit test of {@link BBox#addPrimitive} method.
125 */
126 @Test
127 public void testAddPrimitive() {
128 BBox b = new BBox();
129 b.addPrimitive(new Node(LatLon.NORTH_POLE), 0.5);
130 assertEquals(LatLon.NORTH_POLE, b.getCenter());
131 assertEquals(new LatLon(90.5, -0.5), b.getTopLeft());
132 assertEquals(new LatLon(89.5, +0.5), b.getBottomRight());
133 }
134
135 /**
136 * Unit test of {@link BBox#height} and {@link BBox#width} methods.
137 */
138 @Test
139 public void testHeightWidth() {
140 BBox b1 = new BBox(1, 2, 3, 5);
141 assertEquals(2, b1.width(), 1e-7);
142 assertEquals(3, b1.height(), 1e-7);
143 BBox b2 = new BBox();
144 assertEquals(0, b2.width(), 1e-7);
145 assertEquals(0, b2.height(), 1e-7);
146 }
147
148 /**
149 * Unit test of {@link BBox#toString} method.
150 */
151 @Test
152 public void testToString() {
153 assertEquals("[ x: Infinity -> -Infinity, y: Infinity -> -Infinity ]", new BBox().toString());
154 assertEquals("[ x: 1.0 -> 3.0, y: 2.0 -> 4.0 ]", new BBox(1, 2, 3, 4).toString());
155 }
156}
Note: See TracBrowser for help on using the repository browser.