source: josm/trunk/test/unit/org/openstreetmap/josm/data/PreferencesTest.java@ 10956

Last change on this file since 10956 was 10947, checked in by Don-vip, 8 years ago

fix/update PreferencesTest

  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertTrue;
6
7import java.awt.Color;
8
9import org.junit.Rule;
10import org.junit.Test;
11import org.openstreetmap.josm.Main;
12import org.openstreetmap.josm.data.preferences.ColorProperty;
13import org.openstreetmap.josm.testutils.JOSMTestRules;
14
15import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
16
17/**
18 * Unit tests of {@link Preferences}.
19 */
20public 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}
Note: See TracBrowser for help on using the repository browser.