Changeset 16691 in josm for trunk/test/unit/org


Ignore:
Timestamp:
2020-06-21T09:54:54+02:00 (4 years ago)
Author:
simon04
Message:

see #16031 - Add ComboTest.testUseLastAsDefault

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/ComboTest.java

    r16533 r16691  
    44import static org.junit.Assert.assertEquals;
    55import static org.junit.Assert.assertTrue;
     6import static org.openstreetmap.josm.tools.I18n.tr;
    67
    78import java.awt.Color;
     9import java.util.Arrays;
    810import java.util.Collections;
    911
     
    1315import org.junit.Test;
    1416import org.openstreetmap.josm.data.osm.OsmPrimitive;
     17import org.openstreetmap.josm.data.osm.OsmUtils;
    1518import org.openstreetmap.josm.testutils.JOSMTestRules;
    1619
     
    3841        assertTrue(new Combo().addToPanel(p, Collections.<OsmPrimitive>emptyList(), false));
    3942        assertTrue(p.getComponentCount() > 0);
     43    }
     44
     45    /**
     46     * Unit test for {@link ComboMultiSelect#use_last_as_default} and {@link ComboMultiSelect#getItemToSelect}
     47     */
     48    @Test
     49    public void testUseLastAsDefault() {
     50        Combo combo = new Combo();
     51        combo.key = "addr:country";
     52        combo.use_last_as_default = 1;
     53        combo.values_from = "java.util.Locale#getISOCountries";
     54        OsmPrimitive way = OsmUtils.createPrimitive("way");
     55        OsmPrimitive wayAT = OsmUtils.createPrimitive("way addr:country=AT");
     56        OsmPrimitive waySI = OsmUtils.createPrimitive("way addr:country=SI");
     57
     58        combo.addToPanel(new JPanel(), Collections.singleton(way), false);
     59        assertEquals("", combo.getSelectedValue());
     60
     61        combo.default_ = "SI";
     62        combo.addToPanel(new JPanel(), Collections.singleton(way), false);
     63        assertEquals("SI", combo.getSelectedValue());
     64        combo.addToPanel(new JPanel(), Collections.singleton(wayAT), false);
     65        assertEquals("AT", combo.getSelectedValue());
     66        combo.default_ = null;
     67
     68        KeyedItem.LAST_VALUES.clear();
     69        KeyedItem.LAST_VALUES.put("addr:country", "AT");
     70        combo.addToPanel(new JPanel(), Collections.singleton(way), false);
     71        assertEquals("AT", combo.getSelectedValue());
     72        combo.addToPanel(new JPanel(), Collections.singleton(wayAT), true);
     73        assertEquals("AT", combo.getSelectedValue());
     74        combo.addToPanel(new JPanel(), Collections.singleton(way), true);
     75        assertEquals("", combo.getSelectedValue());
     76        combo.use_last_as_default = 2; // "force"
     77        combo.addToPanel(new JPanel(), Collections.singleton(way), true);
     78        assertEquals("AT", combo.getSelectedValue());
     79        KeyedItem.LAST_VALUES.clear();
     80
     81        combo.addToPanel(new JPanel(), Arrays.asList(wayAT, waySI), true);
     82        assertEquals(tr("<different>"), combo.getSelectedValue());
    4083    }
    4184
Note: See TracChangeset for help on using the changeset viewer.