- Timestamp:
- 2016-09-03T20:25:52+02:00 (8 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/data/PreferencesTest.java
r10945 r10947 1 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.data 2 package org.openstreetmap.josm.data; 3 3 4 import java.awt.Color 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertTrue; 5 6 6 import org.openstreetmap.josm.JOSMFixture 7 import org.openstreetmap.josm.Main 8 import org.openstreetmap.josm.data.preferences.ColorProperty 7 import java.awt.Color; 9 8 10 class PreferencesTest extends GroovyTestCase { 11 @Override 12 void setUp() { 13 JOSMFixture.createUnitTestFixture().init(); 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")); 14 36 } 15 37 16 void testColorName() { 17 assert Main.pref.getColorName("color.layer {5DE308C0-916F-4B5A-B3DB-D45E17F30172}.gpx") == "color.layer {5DE308C0-916F-4B5A-B3DB-D45E17F30172}.gpx" 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()); 18 46 } 19 47 20 void testColorAlpha() { 21 assert new ColorProperty("foo", new Color(0x12345678, true)).get().alpha == 0x12 22 assert Main.pref.putColor("bar", new Color(0x12345678, true)) 23 assert new ColorProperty("bar", (String) null).get().alpha == 0x12 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()); 24 56 } 25 57 26 void testColorNameAlpha() { 27 assert new ColorProperty("foo", new Color(0x12345678, true)).get().alpha == 0x12 28 assert Main.pref.getDefaultColor("foo") == new Color(0x34, 0x56, 0x78, 0x12) 29 assert Main.pref.getDefaultColor("foo").alpha == 0x12 30 } 31 32 void testToXml() { 33 assert Main.pref.toXML(true) == String.format( 58 /** 59 * Test {@link Preferences#toXML}. 60 */ 61 @Test 62 public void testToXml() { 63 assertEquals(String.format( 34 64 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>%n" + 35 65 "<preferences xmlns='http://josm.openstreetmap.de/preferences-1.0' version='%d'>%n" + 36 " <tag key='expert' value='true'/>%n" + 37 " <tag key='jdk.Arrays.useLegacyMergeSort' value='false'/>%n" + 38 " <tag key='language' value='en'/>%n" + 39 " <tag key='osm-server.url' value='http://api06.dev.openstreetmap.org/api'/>%n" + 40 " <tag key='osm-server.username' value='%s'/>%n" + 41 "</preferences>%n", Version.getInstance().getVersion(), Main.pref.get("osm-server.username")) 66 " <tag key='osm-server.url' value='http://fake.xxx/api'/>%n" + 67 "</preferences>%n", Version.getInstance().getVersion()), 68 Main.pref.toXML(true)); 42 69 } 43 70 }
Note:
See TracChangeset
for help on using the changeset viewer.