source: josm/trunk/test/unit/org/openstreetmap/josm/data/preferences/ColorPropertyTest.java@ 10824

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

see #13309 - Caching and notifying preferences (patch by michael2402) - gsoc-core

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