1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.gpx;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertNull;
|
---|
6 |
|
---|
7 | import java.awt.Color;
|
---|
8 | import java.util.ArrayList;
|
---|
9 | import java.util.HashMap;
|
---|
10 |
|
---|
11 | import org.junit.Rule;
|
---|
12 | import org.junit.Test;
|
---|
13 | import org.openstreetmap.josm.TestUtils;
|
---|
14 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
15 | import org.openstreetmap.josm.tools.ListenerList;
|
---|
16 |
|
---|
17 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
18 | import nl.jqno.equalsverifier.EqualsVerifier;
|
---|
19 | import nl.jqno.equalsverifier.Warning;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Unit tests for class {@link GpxTrack}.
|
---|
23 | */
|
---|
24 | public class GpxTrackTest {
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Setup test.
|
---|
28 | */
|
---|
29 | @Rule
|
---|
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 | public 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", "TrackExtensions").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 | public 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 | }
|
---|