1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertTrue;
|
---|
6 |
|
---|
7 | import java.awt.Color;
|
---|
8 |
|
---|
9 | import org.junit.Rule;
|
---|
10 | import org.junit.Test;
|
---|
11 | import org.openstreetmap.josm.Main;
|
---|
12 | import org.openstreetmap.josm.data.preferences.ColorProperty;
|
---|
13 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
14 |
|
---|
15 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Unit tests of {@link Preferences}.
|
---|
19 | */
|
---|
20 | public class PreferencesTest {
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Setup test.
|
---|
24 | */
|
---|
25 | @Rule
|
---|
26 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
27 | public JOSMTestRules test = new JOSMTestRules().platform().preferences().fakeAPI();
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Test color name.
|
---|
31 | */
|
---|
32 | @Test
|
---|
33 | public void testColorName() {
|
---|
34 | assertEquals("color.layer {5DE308C0-916F-4B5A-B3DB-D45E17F30172}.gpx",
|
---|
35 | Main.pref.getColorName("color.layer {5DE308C0-916F-4B5A-B3DB-D45E17F30172}.gpx"));
|
---|
36 | }
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * Test color alpha.
|
---|
40 | */
|
---|
41 | @Test
|
---|
42 | public void testColorAlpha() {
|
---|
43 | assertEquals(0x12, new ColorProperty("foo", new Color(0x12345678, true)).get().getAlpha());
|
---|
44 | assertTrue(Main.pref.putColor("bar", new Color(0x12345678, true)));
|
---|
45 | assertEquals(0x12, new ColorProperty("bar", (String) null).get().getAlpha());
|
---|
46 | }
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Test color name and alpha.
|
---|
50 | */
|
---|
51 | @Test
|
---|
52 | public void testColorNameAlpha() {
|
---|
53 | assertEquals(0x12, new ColorProperty("foo", new Color(0x12345678, true)).get().getAlpha());
|
---|
54 | assertEquals(new Color(0x34, 0x56, 0x78, 0x12), Main.pref.getDefaultColor("foo"));
|
---|
55 | assertEquals(0x12, Main.pref.getDefaultColor("foo").getAlpha());
|
---|
56 | }
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * Test {@link Preferences#toXML}.
|
---|
60 | */
|
---|
61 | @Test
|
---|
62 | public void testToXml() {
|
---|
63 | assertEquals(String.format(
|
---|
64 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>%n" +
|
---|
65 | "<preferences xmlns='http://josm.openstreetmap.de/preferences-1.0' version='%d'>%n" +
|
---|
66 | " <tag key='osm-server.url' value='http://fake.xxx/api'/>%n" +
|
---|
67 | "</preferences>%n", Version.getInstance().getVersion()),
|
---|
68 | Main.pref.toXML(true));
|
---|
69 | }
|
---|
70 | }
|
---|