Ignore:
Timestamp:
2015-10-11T17:28:19+02:00 (9 years ago)
Author:
Don-vip
Message:

improve/cleanup unit tests

Location:
trunk/test/unit/org/openstreetmap/josm/data/validation/tests
Files:
3 edited

Legend:

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

    r8741 r8857  
    22package org.openstreetmap.josm.data.validation.tests;
    33
    4 import static org.hamcrest.CoreMatchers.is;
    5 import static org.hamcrest.CoreMatchers.notNullValue;
     4import static org.junit.Assert.assertEquals;
    65import static org.junit.Assert.assertFalse;
    7 import static org.junit.Assert.assertThat;
     6import static org.junit.Assert.assertNotNull;
    87import static org.junit.Assert.assertTrue;
    98
     
    3332
    3433/**
    35  * JUnit Test of MapCSS TagChecker.
     34 * JUnit Test of {@link MapCSSTagChecker}.
    3635 */
    3736public class MapCSSTagCheckerTest {
     
    5352    @Test
    5453    public void testNaturalMarsh() throws Exception {
    55 
    5654        final List<MapCSSTagChecker.TagCheck> checks = MapCSSTagChecker.TagCheck.readMapCSS(new StringReader("" +
    5755                "*[natural=marsh] {\n" +
     
    6159                "   fixAdd: \"wetland=marsh\";\n" +
    6260                "}"));
    63         assertThat(checks.size(), is(1));
     61        assertEquals(1, checks.size());
    6462        final MapCSSTagChecker.TagCheck check = checks.get(0);
    65         assertThat(check, notNullValue());
    66         assertThat(check.getDescription(null), is("{0.key}=null is deprecated"));
    67         assertThat(check.fixCommands.get(0).toString(), is("fixRemove: {0.key}"));
    68         assertThat(check.fixCommands.get(1).toString(), is("fixAdd: natural=wetland"));
    69         assertThat(check.fixCommands.get(2).toString(), is("fixAdd: wetland=marsh"));
     63        assertNotNull(check);
     64        assertEquals("{0.key}=null is deprecated", check.getDescription(null));
     65        assertEquals("fixRemove: {0.key}", check.fixCommands.get(0).toString());
     66        assertEquals("fixAdd: natural=wetland", check.fixCommands.get(1).toString());
     67        assertEquals("fixAdd: wetland=marsh", check.fixCommands.get(2).toString());
    7068        final Node n1 = new Node();
    7169        n1.put("natural", "marsh");
    7270        assertTrue(check.evaluate(n1));
    73         assertThat(check.getErrorForPrimitive(n1).getMessage(), is("natural=marsh is deprecated"));
    74         assertThat(check.getErrorForPrimitive(n1).getSeverity(), is(Severity.WARNING));
    75         assertThat(check.fixPrimitive(n1).getDescriptionText(), is("Sequence: Fix of natural=marsh is deprecated"));
    76         assertThat(((ChangePropertyCommand) check.fixPrimitive(n1).getChildren().iterator().next()).getTags().toString(),
    77                 is("{natural=}"));
     71        assertEquals("natural=marsh is deprecated", check.getErrorForPrimitive(n1).getMessage());
     72        assertEquals(Severity.WARNING, check.getErrorForPrimitive(n1).getSeverity());
     73        assertEquals("Sequence: Fix of natural=marsh is deprecated", check.fixPrimitive(n1).getDescriptionText());
     74        assertEquals("{natural=}", ((ChangePropertyCommand) check.fixPrimitive(n1).getChildren().iterator().next()).getTags().toString());
    7875        final Node n2 = new Node();
    7976        n2.put("natural", "wood");
    8077        assertFalse(check.evaluate(n2));
    81         assertThat(MapCSSTagChecker.TagCheck.insertArguments(check.rule.selectors.get(0), "The key is {0.key} and the value is {0.value}", null),
    82                 is("The key is natural and the value is marsh"));
     78        assertEquals("The key is natural and the value is marsh",
     79                MapCSSTagChecker.TagCheck.insertArguments(check.rule.selectors.get(0), "The key is {0.key} and the value is {0.value}", null));
    8380    }
    8481
     
    9289                "}")).get(0);
    9390        final Command command = check.fixPrimitive(p);
    94         assertThat(command instanceof SequenceCommand, is(true));
     91        assertTrue(command instanceof SequenceCommand);
    9592        final Iterator<PseudoCommand> it = command.getChildren().iterator();
    96         assertThat(it.next() instanceof ChangePropertyKeyCommand, is(true));
    97         assertThat(it.next() instanceof ChangePropertyCommand, is(true));
     93        assertTrue(it.next() instanceof ChangePropertyKeyCommand);
     94        assertTrue(it.next() instanceof ChangePropertyCommand);
    9895    }
    9996
     
    104101        final OsmPrimitive p = OsmUtils.createPrimitive("way alt_name=Foo");
    105102        final Collection<TestError> errors = test.getErrorsForPrimitive(p, false);
    106         assertThat(errors.size(), is(1));
    107         assertThat(errors.iterator().next().getMessage(), is("has alt_name but not name"));
    108         assertThat(errors.iterator().next().getIgnoreSubGroup(), is("3000_*[.+_name][!name]"));
     103        assertEquals(1, errors.size());
     104        assertEquals("has alt_name but not name", errors.iterator().next().getMessage());
     105        assertEquals("3000_*[.+_name][!name]", errors.iterator().next().getIgnoreSubGroup());
    109106    }
    110107
     
    115112        final OsmPrimitive p = OsmUtils.createPrimitive("way highway=footway foot=no");
    116113        final Collection<TestError> errors = test.getErrorsForPrimitive(p, false);
    117         assertThat(errors.size(), is(1));
    118         assertThat(errors.iterator().next().getMessage(), is("footway used with foot=no"));
    119         assertThat(errors.iterator().next().getIgnoreSubGroup(), is("3000_way[highway=footway][foot]"));
     114        assertEquals(1, errors.size());
     115        assertEquals("footway used with foot=no", errors.iterator().next().getMessage());
     116        assertEquals("3000_way[highway=footway][foot]", errors.iterator().next().getIgnoreSubGroup());
    120117    }
    121118
     
    125122                "@media (min-josm-version: 1) { *[foo] { throwWarning: \"!\"; } }\n" +
    126123                "@media (min-josm-version: 2147483647) { *[bar] { throwWarning: \"!\"; } }\n");
    127         assertThat(test.getErrorsForPrimitive(OsmUtils.createPrimitive("way foo=1"), false).size(), is(1));
    128         assertThat(test.getErrorsForPrimitive(OsmUtils.createPrimitive("way bar=1"), false).size(), is(0));
     124        assertEquals(1, test.getErrorsForPrimitive(OsmUtils.createPrimitive("way foo=1"), false).size());
     125        assertEquals(0, test.getErrorsForPrimitive(OsmUtils.createPrimitive("way bar=1"), false).size());
    129126    }
    130127
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/OpeningHourTestTest.java

    r8680 r8857  
    44import static org.CustomMatchers.hasSize;
    55import static org.CustomMatchers.isEmpty;
    6 import static org.hamcrest.CoreMatchers.is;
    76import static org.hamcrest.CoreMatchers.not;
     7import static org.junit.Assert.assertEquals;
    88import static org.junit.Assert.assertFalse;
    99import static org.junit.Assert.assertThat;
     
    5656        assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su-Th sunset-24:00,04:00-sunrise; Fr-Sa sunset-sunrise"), isEmpty());
    5757        assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise"), hasSize(1));
    58         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise")
    59                 .get(0).getSeverity(), is(Severity.OTHER));
    60         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise")
    61                 .get(0).getPrettifiedValue(), is("Su-Th sunset-24:00,04:00-sunrise; Fr-Sa sunset-sunrise"));
    62     }
    63 
    64     @Test
    65     public void testI18n() throws Exception {
     58        assertEquals(Severity.OTHER, OPENING_HOUR_TEST.checkOpeningHourSyntax(
     59                key, "Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise").get(0).getSeverity());
     60        assertEquals("Su-Th sunset-24:00,04:00-sunrise; Fr-Sa sunset-sunrise", OPENING_HOUR_TEST.checkOpeningHourSyntax(
     61                key, "Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise").get(0).getPrettifiedValue());
     62    }
     63
     64    @Test
     65    public void testI18n() {
    6666        assertTrue(OPENING_HOUR_TEST.checkOpeningHourSyntax("opening_hours", ".", OpeningHourTest.CheckMode.POINTS_IN_TIME, false, "de")
    6767                .get(0).toString().contains("Unerwartetes Zeichen"));
     
    7878        final List<OpeningHourTest.OpeningHoursTestError> errors = OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Tue");
    7979        assertThat(errors, hasSize(2));
    80         assertThat(errors.get(0).getMessage(), is(key + " - Mo-Tue <--- (Please use the abbreviation \"Tu\" for \"tue\".)"));
    81         assertThat(errors.get(0).getSeverity(), is(Severity.WARNING));
    82         assertThat(errors.get(1).getMessage(), is(key +
     80        assertEquals(key + " - Mo-Tue <--- (Please use the abbreviation \"Tu\" for \"tue\".)", errors.get(0).getMessage());
     81        assertEquals(Severity.WARNING, errors.get(0).getSeverity());
     82        assertEquals(key +
    8383                " - Mo-Tue <--- (This rule is not very explicit because there is no time selector being used."+
    84                 " Please add a time selector to this rule or use a comment to make it more explicit.)"));
    85         assertThat(errors.get(1).getSeverity(), is(Severity.WARNING));
     84                " Please add a time selector to this rule or use a comment to make it more explicit.)", errors.get(1).getMessage());
     85        assertEquals(Severity.WARNING, errors.get(1).getSeverity());
    8686    }
    8787
     
    9494        final List<OpeningHourTest.OpeningHoursTestError> errors = OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Sa-Su 10.00-20.00");
    9595        assertThat(errors, hasSize(2));
    96         assertThat(errors.get(0).getMessage(), is(key + " - Sa-Su 10. <--- (Please use \":\" as hour/minute-separator)"));
    97         assertThat(errors.get(0).getSeverity(), is(Severity.WARNING));
    98         assertThat(errors.get(0).getPrettifiedValue(), is("Sa-Su 10:00-20:00"));
    99         assertThat(errors.get(1).getMessage(), is(key + " - Sa-Su 10.00-20. <--- (Please use \":\" as hour/minute-separator)"));
    100         assertThat(errors.get(1).getSeverity(), is(Severity.WARNING));
     96        assertEquals(key + " - Sa-Su 10. <--- (Please use \":\" as hour/minute-separator)", errors.get(0).getMessage());
     97        assertEquals(Severity.WARNING, errors.get(0).getSeverity());
     98        assertEquals("Sa-Su 10:00-20:00", errors.get(0).getPrettifiedValue());
     99        assertEquals(key + " - Sa-Su 10.00-20. <--- (Please use \":\" as hour/minute-separator)", errors.get(1).getMessage());
     100        assertEquals(Severity.WARNING, errors.get(1).getSeverity());
    101101    }
    102102
     
    118118        final String key = "opening_hours";
    119119        assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "badtext"), hasSize(1));
    120         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "badtext").get(0).getMessage(),
    121                 is(key + " - ba <--- (Unexpected token: \"b\" Invalid/unsupported syntax.)"));
     120        assertEquals(key + " - ba <--- (Unexpected token: \"b\" Invalid/unsupported syntax.)",
     121                OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "badtext").get(0).getMessage());
    122122        assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "5.00 p.m-11.00 p.m"), hasSize(1));
    123         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "5.00 p.m-11.00 p.m").get(0).getMessage(),
    124                 is(key + " - 5.00 p <--- (hyphen (-) or open end (+) in time range expected. "
    125                        + "For working with points in time, the mode for opening_hours.js has to be altered. Maybe wrong tag?)"));
     123        assertEquals(key + " - 5.00 p <--- (hyphen (-) or open end (+) in time range expected. "
     124                + "For working with points in time, the mode for opening_hours.js has to be altered. Maybe wrong tag?)",
     125                OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "5.00 p.m-11.00 p.m").get(0).getMessage());
    126126    }
    127127
     
    142142        final String key = "opening_hours";
    143143        assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "9:00-18:00"), hasSize(1));
    144         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "9:00-18:00").get(0).getSeverity(), is(Severity.OTHER));
    145         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "9:00-18:00").get(0).getPrettifiedValue(), is("09:00-18:00"));
     144        assertEquals(Severity.OTHER, OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "9:00-18:00").get(0).getSeverity());
     145        assertEquals("09:00-18:00", OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "9:00-18:00").get(0).getPrettifiedValue());
    146146    }
    147147
     
    152152    public void testCheckOpeningHourSyntaxTicket9367() {
    153153        final String key = "opening_hours";
    154         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getSeverity(), is(Severity.WARNING));
    155         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getMessage(),
    156                 is(key + " - Mo,Tu 04-17 <--- (Time range without minutes specified. "
    157                        + "Not very explicit! Please use this syntax instead \"04:00-17:00\".)"));
    158         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getPrettifiedValue(), is("Mo,Tu 04:00-17:00"));
     154        assertEquals(Severity.WARNING, OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getSeverity());
     155        assertEquals(key + " - Mo,Tu 04-17 <--- (Time range without minutes specified. "
     156                + "Not very explicit! Please use this syntax instead \"04:00-17:00\".)",
     157                OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getMessage());
     158        assertEquals("Mo,Tu 04:00-17:00", OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getPrettifiedValue());
    159159    }
    160160
     
    174174        assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00",
    175175                OpeningHourTest.CheckMode.BOTH), hasSize(1));
    176         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00",
    177                 OpeningHourTest.CheckMode.BOTH).get(0).getPrettifiedValue(), is("Mo-Fr 00:00-00:30,04:00-00:30; Sa,Su,PH 00:00-24:00"));
    178         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00",
    179                 OpeningHourTest.CheckMode.BOTH).get(0).getPrettifiedValue(), is("Mo-Fr 00:00-00:30,04:00-00:30; Sa,Su,PH 00:00-24:00"));
     176        assertEquals("Mo-Fr 00:00-00:30,04:00-00:30; Sa,Su,PH 00:00-24:00",
     177                OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00",
     178                OpeningHourTest.CheckMode.BOTH).get(0).getPrettifiedValue());
     179        assertEquals("Mo-Fr 00:00-00:30,04:00-00:30; Sa,Su,PH 00:00-24:00",
     180                OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00",
     181                OpeningHourTest.CheckMode.BOTH).get(0).getPrettifiedValue());
    180182    }
    181183
     
    194196        assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00",
    195197                OpeningHourTest.CheckMode.BOTH), hasSize(1));
    196         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00",
    197                 OpeningHourTest.CheckMode.BOTH).get(0).getSeverity(), is(Severity.OTHER));
    198         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00",
    199                 OpeningHourTest.CheckMode.BOTH).get(0).getPrettifiedValue(), is("Mo-Fr 13:30,17:45,19:00; Sa 15:00; Su 11:00"));
     198        assertEquals(Severity.OTHER,
     199                OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00",
     200                OpeningHourTest.CheckMode.BOTH).get(0).getSeverity());
     201        assertEquals("Mo-Fr 13:30,17:45,19:00; Sa 15:00; Su 11:00",
     202                OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00",
     203                OpeningHourTest.CheckMode.BOTH).get(0).getPrettifiedValue());
    200204    }
    201205
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/TagCheckerTest.java

    r8753 r8857  
    22package org.openstreetmap.josm.data.validation.tests;
    33
    4 import static org.hamcrest.CoreMatchers.is;
    5 import static org.junit.Assert.assertThat;
     4import static org.junit.Assert.assertEquals;
    65
    76import java.io.IOException;
     
    1615import org.openstreetmap.josm.gui.tagging.TaggingPresets;
    1716
     17/**
     18 * JUnit Test of {@link TagChecker}.
     19 */
    1820public class TagCheckerTest {
     21
    1922    /**
    2023     * Setup test.
     
    3740    public void testInvalidKey() throws Exception {
    3841        final List<TestError> errors = test(OsmUtils.createPrimitive("node Name=Main"));
    39         assertThat(errors.size(), is(1));
    40         assertThat(errors.get(0).getMessage(), is("Misspelled property key"));
    41         assertThat(errors.get(0).getDescription(), is("Key 'Name' looks like 'name'."));
     42        assertEquals(1, errors.size());
     43        assertEquals("Misspelled property key", errors.get(0).getMessage());
     44        assertEquals("Key 'Name' looks like 'name'.", errors.get(0).getDescription());
    4245    }
    4346
     
    4548    public void testMisspelledKey() throws Exception {
    4649        final List<TestError> errors = test(OsmUtils.createPrimitive("node landuse;=forest"));
    47         assertThat(errors.size(), is(1));
    48         assertThat(errors.get(0).getMessage(), is("Misspelled property key"));
    49         assertThat(errors.get(0).getDescription(), is("Key 'landuse;' looks like 'landuse'."));
     50        assertEquals(1, errors.size());
     51        assertEquals("Misspelled property key", errors.get(0).getMessage());
     52        assertEquals("Key 'landuse;' looks like 'landuse'.", errors.get(0).getDescription());
    5053    }
    5154
     
    5356    public void testTranslatedNameKey() throws Exception {
    5457        final List<TestError> errors = test(OsmUtils.createPrimitive("node namez=Baz"));
    55         assertThat(errors.size(), is(1));
    56         assertThat(errors.get(0).getMessage(), is("Presets do not contain property key"));
    57         assertThat(errors.get(0).getDescription(), is("Key 'namez' not in presets."));
     58        assertEquals(1, errors.size());
     59        assertEquals("Presets do not contain property key", errors.get(0).getMessage());
     60        assertEquals("Key 'namez' not in presets.", errors.get(0).getDescription());
    5861    }
    5962
     
    6164    public void testMisspelledTag() throws Exception {
    6265        final List<TestError> errors = test(OsmUtils.createPrimitive("node landuse=forrest"));
    63         assertThat(errors.size(), is(1));
    64         assertThat(errors.get(0).getMessage(), is("Presets do not contain property value"));
    65         assertThat(errors.get(0).getDescription(), is("Value 'forrest' for key 'landuse' not in presets."));
     66        assertEquals(1, errors.size());
     67        assertEquals("Presets do not contain property value", errors.get(0).getMessage());
     68        assertEquals("Value 'forrest' for key 'landuse' not in presets.", errors.get(0).getDescription());
    6669    }
    67 
    6870}
Note: See TracChangeset for help on using the changeset viewer.