source: josm/trunk/test/unit/org/openstreetmap/josm/data/gpx/GpxTrackTest.java@ 17360

Last change on this file since 17360 was 17275, checked in by Don-vip, 3 years ago

see #16567 - upgrade almost all tests to JUnit 5, except those depending on WiremockRule

See https://github.com/tomakehurst/wiremock/issues/684

  • Property svn:eol-style set to native
File size: 2.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.gpx;
3
4import static org.junit.jupiter.api.Assertions.assertEquals;
5import static org.junit.jupiter.api.Assertions.assertNull;
6
7import java.awt.Color;
8import java.util.ArrayList;
9import java.util.HashMap;
10
11import org.junit.jupiter.api.extension.RegisterExtension;
12import org.junit.jupiter.api.Test;
13import org.openstreetmap.josm.TestUtils;
14import org.openstreetmap.josm.testutils.JOSMTestRules;
15import org.openstreetmap.josm.tools.ListenerList;
16
17import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
18import nl.jqno.equalsverifier.EqualsVerifier;
19import nl.jqno.equalsverifier.Warning;
20
21/**
22 * Unit tests for class {@link GpxTrack}.
23 */
24class GpxTrackTest {
25
26 /**
27 * Setup test.
28 */
29 @RegisterExtension
30 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
31 public JOSMTestRules test = new JOSMTestRules();
32
33 /**
34 * Tests weather the track can read and write colors.
35 */
36 @Test
37 void testColors() {
38 GpxTrack trk = new GpxTrack(new ArrayList<IGpxTrackSegment>(), new HashMap<>());
39 GpxExtensionCollection ext = trk.getExtensions();
40 ext.add("gpxd", "color", "#FF0000");
41 trk.invalidate();
42 assertEquals(trk.getColor(), Color.RED);
43 trk.setColor(Color.GREEN);
44 assertEquals(trk.getColor(), Color.GREEN);
45 trk.invalidate();
46 assertEquals(trk.getColor(), Color.GREEN);
47 ext.remove("gpxd", "color");
48 trk.invalidate();
49 assertNull(trk.getColor());
50 ext.add("gpxx", "TrackExtension").getExtensions().add("gpxx", "DisplayColor", "Blue");
51 trk.invalidate();
52 assertEquals(trk.getColor(), Color.BLUE);
53 trk.setColor(null);
54 assertNull(trk.getColor());
55 trk.invalidate();
56 assertNull(trk.getColor());
57 }
58
59 /**
60 * Unit test of methods {@link GpxTrack#equals} and {@link GpxTrack#hashCode}.
61 */
62 @Test
63 void testEqualsContract() {
64 TestUtils.assumeWorkingEqualsVerifier();
65 GpxExtensionCollection col = new GpxExtensionCollection();
66 col.add("josm", "from-server", "true");
67 EqualsVerifier.forClass(GpxTrack.class).usingGetClass()
68 .suppress(Warning.NONFINAL_FIELDS)
69 .withPrefabValues(ListenerList.class, ListenerList.create(), ListenerList.create())
70 .withPrefabValues(GpxExtensionCollection.class, new GpxExtensionCollection(), col)
71 .withIgnoredFields("bounds", "length", "colorCache", "colorFormat", "listeners")
72 .verify();
73 }
74}
Note: See TracBrowser for help on using the repository browser.