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


Ignore:
Timestamp:
2020-02-10T23:58:31+01:00 (5 years ago)
Author:
simon04
Message:

fix #18679 - Autofilter: extract numeric value from number+unit

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/autofilter/AutoFilterManagerTest.java

    r15764 r15838  
    33
    44import static org.junit.Assert.assertEquals;
    5 import static org.junit.Assert.assertNull;
    65
    76import java.util.Arrays;
     7import java.util.OptionalInt;
    88import java.util.TreeSet;
    99import java.util.stream.Collectors;
     
    3434    @Test
    3535    public void testTagValuesForPrimitive() {
    36         final TreeSet<String> values = Stream.of(
     36        AutoFilterManager.getInstance().setCurrentAutoFilter(null);
     37        final TreeSet<Integer> values = Stream.of(
    3738                OsmUtils.createPrimitive("way level=-4--5"),
    3839                OsmUtils.createPrimitive("way level=-2"),
     
    4243                OsmUtils.createPrimitive("way level=6-9"),
    4344                OsmUtils.createPrimitive("way level=10;12-13"))
    44                 .flatMap(o -> AutoFilterManager.getTagValuesForPrimitive("level", o))
     45                .flatMapToInt(o -> AutoFilterManager.getInstance().getTagValuesForPrimitive("level", o))
     46                .boxed()
    4547                .collect(Collectors.toCollection(TreeSet::new));
    46         assertEquals(new TreeSet<>(Arrays.asList("-5", "-4", "-2", "0", "1", "2", "3", "6", "7", "8", "9", "10", "12", "13")), values);
     48        assertEquals(new TreeSet<>(Arrays.asList(-5, -4, -2, 0, 1, 2, 3, 6, 7, 8, 9, 10, 12, 13)), values);
    4749
    4850    }
     
    5355    @Test
    5456    public void testTagValuesForPrimitivesDefaults() {
    55         assertNull(getLayer("way foo=bar"));
    56         assertEquals("1", getLayer("way bridge=yes"));
    57         assertEquals("1", getLayer("way power=line"));
    58         assertEquals("-1", getLayer("way tunnel=yes"));
    59         assertEquals("0", getLayer("way tunnel=building_passage"));
    60         assertEquals("0", getLayer("way highway=residential"));
    61         assertEquals("0", getLayer("way railway=rail"));
    62         assertEquals("0", getLayer("way waterway=canal"));
     57        AutoFilterManager.getInstance().setCurrentAutoFilter(null);
     58        assertEquals(OptionalInt.empty(), getLayer("way foo=bar"));
     59        AutoFilterRule.getDefaultRule("layer").ifPresent(AutoFilterManager.getInstance()::enableAutoFilterRule);
     60        assertEquals(OptionalInt.empty(), getLayer("way foo=bar"));
     61        assertEquals(OptionalInt.of(1), getLayer("way bridge=yes"));
     62        assertEquals(OptionalInt.of(1), getLayer("way power=line"));
     63        assertEquals(OptionalInt.of(-1), getLayer("way tunnel=yes"));
     64        assertEquals(OptionalInt.of(0), getLayer("way tunnel=building_passage"));
     65        assertEquals(OptionalInt.of(0), getLayer("way highway=residential"));
     66        assertEquals(OptionalInt.of(0), getLayer("way railway=rail"));
     67        assertEquals(OptionalInt.of(0), getLayer("way waterway=canal"));
    6368    }
    6469
    65     private String getLayer(final String assertion) {
    66         return AutoFilterManager.getTagValuesForPrimitive("layer", OsmUtils.createPrimitive(assertion))
    67                 .findFirst()
    68                 .orElse(null);
     70    private OptionalInt getLayer(final String assertion) {
     71        return AutoFilterManager.getInstance()
     72                .getTagValuesForPrimitive("layer", OsmUtils.createPrimitive(assertion))
     73                .findFirst();
    6974    }
    7075}
Note: See TracChangeset for help on using the changeset viewer.