Changeset 10947 in josm for trunk


Ignore:
Timestamp:
2016-09-03T20:25:52+02:00 (3 years ago)
Author:
Don-vip
Message:

fix/update PreferencesTest

File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/PreferencesTest.java

    r10945 r10947  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.data
     2package org.openstreetmap.josm.data;
    33
    4 import java.awt.Color
     4import static org.junit.Assert.assertEquals;
     5import static org.junit.Assert.assertTrue;
    56
    6 import org.openstreetmap.josm.JOSMFixture
    7 import org.openstreetmap.josm.Main
    8 import org.openstreetmap.josm.data.preferences.ColorProperty
     7import java.awt.Color;
    98
    10 class PreferencesTest extends GroovyTestCase {
    11     @Override
    12     void setUp() {
    13         JOSMFixture.createUnitTestFixture().init();
     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"));
    1436    }
    1537
    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());
    1846    }
    1947
    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());
    2456    }
    2557
    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(
    3464            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>%n" +
    3565            "<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));
    4269    }
    4370}
Note: See TracChangeset for help on using the changeset viewer.