Changeset 6568 in josm for trunk/test/unit


Ignore:
Timestamp:
2013-12-30T23:57:06+01:00 (11 years ago)
Author:
simon04
Message:

fix #9462 - fix preset values for opening_hour/… such that the OpeningHourTest does not yield warnings, add unit test that validates all preset values

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/OpeningHourTestTest.java

    r6533 r6568  
    55import org.junit.Test;
    66import org.openstreetmap.josm.Main;
     7import org.openstreetmap.josm.data.osm.Tag;
    78import org.openstreetmap.josm.data.validation.Severity;
     9import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference;
     10import org.openstreetmap.josm.gui.tagging.TaggingPreset;
     11import org.openstreetmap.josm.gui.tagging.TaggingPresetItem;
     12import org.openstreetmap.josm.gui.tagging.TaggingPresetItems;
     13import org.openstreetmap.josm.gui.tagging.TaggingPresetReader;
     14import org.openstreetmap.josm.gui.tagging.TaggingPresetSearchAction;
    815
     16import java.util.Arrays;
     17import java.util.Collection;
     18import java.util.LinkedHashSet;
    919import java.util.List;
     20import java.util.Set;
    1021
    1122import static org.CustomMatchers.hasSize;
     
    128139        assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00", OpeningHourTest.CheckMode.BOTH).get(0).getPrettifiedValue(), is("Mo-Fr 13:30,17:45,19:00; Sa 15:00; Su 11:00"));
    129140    }
     141
     142    @Test
     143    public void testPresetValues() throws Exception {
     144        final Collection<TaggingPreset> presets = TaggingPresetReader.readFromPreferences(false);
     145        final Set<Tag> values = new LinkedHashSet<Tag>();
     146        for (final TaggingPreset p : presets) {
     147            for (final TaggingPresetItem i : p.data) {
     148                if (i instanceof TaggingPresetItems.KeyedItem &&
     149                        Arrays.asList("opening_hours", "service_times", "collection_times").contains(((TaggingPresetItems.KeyedItem) i).key)) {
     150                    for (final String v : ((TaggingPresetItems.KeyedItem) i).getValues()) {
     151                        values.add(new Tag(((TaggingPresetItems.KeyedItem) i).key, v));
     152                    }
     153                }
     154            }
     155        }
     156        for (final Tag t : values) {
     157            final List<OpeningHourTest.OpeningHoursTestError> errors = OPENING_HOUR_TEST.checkOpeningHourSyntax(t.getKey(), t.getValue());
     158            assertThat(t + " is valid", errors, isEmpty());
     159        }
     160    }
    130161}
Note: See TracChangeset for help on using the changeset viewer.