1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.preferences;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 |
|
---|
6 | import java.awt.Color;
|
---|
7 |
|
---|
8 | import org.junit.Before;
|
---|
9 | import org.junit.Rule;
|
---|
10 | import org.junit.Test;
|
---|
11 | import org.openstreetmap.josm.Main;
|
---|
12 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
13 |
|
---|
14 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * Test {@link ColorProperty}
|
---|
18 | * @author Michael Zangl
|
---|
19 | */
|
---|
20 | public class ColorPropertyTest {
|
---|
21 | /**
|
---|
22 | * This is a preference test.
|
---|
23 | */
|
---|
24 | @Rule
|
---|
25 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
26 | public JOSMTestRules test = new JOSMTestRules().preferences();
|
---|
27 | private ColorProperty base;
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Set up test case
|
---|
31 | */
|
---|
32 | @Before
|
---|
33 | public void createTestProperty() {
|
---|
34 | base = new ColorProperty("test", Color.RED);
|
---|
35 | }
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Test {@link ColorProperty#get()}
|
---|
39 | */
|
---|
40 | @Test
|
---|
41 | public void testGet() {
|
---|
42 | assertEquals(Color.RED, base.get());
|
---|
43 |
|
---|
44 | Main.pref.put("color.test", "#00ff00");
|
---|
45 | assertEquals(new Color(0xff00ff00), base.get());
|
---|
46 | }
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Test {@link ColorProperty#put}
|
---|
50 | */
|
---|
51 | @Test
|
---|
52 | public void testPut() {
|
---|
53 | assertEquals(Color.RED, base.get());
|
---|
54 |
|
---|
55 | base.put(new Color(0xff00ff00));
|
---|
56 | assertEquals(new Color(0xff00ff00), base.get());
|
---|
57 | assertEquals("#00ff00", Main.pref.get("color.test").toLowerCase());
|
---|
58 |
|
---|
59 | base.put(null);
|
---|
60 | assertEquals(Color.RED, base.get());
|
---|
61 | }
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Test {@link ColorProperty#getChildColor(String)}
|
---|
65 | */
|
---|
66 | @Test
|
---|
67 | public void testGetChildColor() {
|
---|
68 | AbstractToStringProperty<Color> child = base.getChildColor("test2");
|
---|
69 |
|
---|
70 | assertEquals(Color.RED, child.get());
|
---|
71 |
|
---|
72 | base.put(Color.GREEN);
|
---|
73 | assertEquals(Color.GREEN, child.get());
|
---|
74 |
|
---|
75 | child.put(Color.YELLOW);
|
---|
76 | assertEquals(Color.YELLOW, child.get());
|
---|
77 | assertEquals(Color.GREEN, base.get());
|
---|
78 |
|
---|
79 | child.put(null);
|
---|
80 | assertEquals(Color.GREEN, child.get());
|
---|
81 | }
|
---|
82 | }
|
---|