Ignore:
Timestamp:
2020-06-10T08:04:42+02:00 (4 years ago)
Author:
simon04
Message:

fix #19197 - MapCSS JOSM_pref: check if a pref could be converted to a color instead of a string (patch by taylor.smock, modified)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/FunctionsTest.java

    r16583 r16590  
    66import static org.openstreetmap.josm.data.osm.OsmPrimitiveType.NODE;
    77
     8import java.util.Collections;
     9
    810import org.junit.Rule;
    911import org.junit.Test;
     
    1214import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    1315import org.openstreetmap.josm.data.osm.User;
     16import org.openstreetmap.josm.data.preferences.NamedColorProperty;
    1417import org.openstreetmap.josm.gui.mappaint.Environment;
    1518import org.openstreetmap.josm.gui.util.GuiHelper;
     
    113116    public void testPref() {
    114117        String key = "Functions.JOSM_pref";
     118        Config.getPref().put(key, null);
    115119        assertEquals("foobar", Functions.JOSM_pref(null, key, "foobar"));
    116120        Config.getPref().put(key, "baz");
     
    124128        });
    125129        assertEquals("foobar", Functions.JOSM_pref(null, key, "foobar"));
     130        Config.getPref().put(key, null);
    126131    }
     132
     133    /**
     134     * Unit test of {@link Functions#JOSM_pref}, color handling
     135     */
     136    @Test
     137    public void testPrefColor() {
     138        String key = "Functions.JOSM_pref";
     139        String colorKey = NamedColorProperty.NAMED_COLOR_PREFIX + NamedColorProperty.COLOR_CATEGORY_MAPPAINT + ".unknown." + key;
     140        Config.getPref().put(colorKey, null);
     141        assertEquals("#000000", Functions.JOSM_pref(null, key, "#000000"));
     142        Config.getPref().putList(colorKey, Collections.singletonList("#00FF00"));
     143        GuiHelper.runInEDTAndWait(() -> {
     144            // await org.openstreetmap.josm.gui.mappaint.ElemStyles.clearCached
     145        });
     146        assertEquals("#00FF00", Functions.JOSM_pref(null, key, "#000000"));
     147        Config.getPref().put(colorKey, null);
     148        GuiHelper.runInEDTAndWait(() -> {
     149            // await org.openstreetmap.josm.gui.mappaint.ElemStyles.clearCached
     150        });
     151        assertEquals("#000000", Functions.JOSM_pref(null, key, "#000000"));
     152        Config.getPref().put(colorKey, null);
     153    }
     154
    127155}
Note: See TracChangeset for help on using the changeset viewer.