Changeset 11973 in josm for trunk/test


Ignore:
Timestamp:
2017-04-22T15:23:07+02:00 (2 years ago)
Author:
Don-vip
Message:

add unit tests

Location:
trunk/test/unit/org/openstreetmap/josm/data/osm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/osm/ChangesetDataSetTest.java

    r11878 r11973  
    22package org.openstreetmap.josm.data.osm;
    33
     4import static org.junit.Assert.assertEquals;
     5import static org.junit.Assert.assertFalse;
     6import static org.junit.Assert.assertTrue;
     7import static org.junit.Assert.fail;
     8
    49import java.util.Date;
     10import java.util.Iterator;
    511import java.util.Set;
    612
    7 import org.junit.Assert;
    813import org.junit.Rule;
    914import org.junit.Test;
    1015import org.openstreetmap.josm.Main;
    1116import org.openstreetmap.josm.data.coor.LatLon;
     17import org.openstreetmap.josm.data.osm.ChangesetDataSet.ChangesetDataSetEntry;
    1218import org.openstreetmap.josm.data.osm.ChangesetDataSet.ChangesetModificationType;
    1319import org.openstreetmap.josm.data.osm.history.HistoryNode;
     
    3844        try {
    3945            cds.getPrimitivesByModificationType(null);
    40             Assert.fail("Should have thrown an IllegalArgumentException as we gave a null argument.");
     46            fail("Should have thrown an IllegalArgumentException as we gave a null argument.");
    4147        } catch (IllegalArgumentException e) {
    4248            Main.trace(e);
     
    4551
    4652        // empty object, a modification type => empty list
    47         Assert.assertTrue(
     53        assertTrue(
    4854            "Empty data set should produce an empty list.",
    4955            cds.getPrimitivesByModificationType(
     
    6167        Set<HistoryOsmPrimitive> result = cds.getPrimitivesByModificationType(
    6268                    ChangesetModificationType.CREATED);
    63         Assert.assertEquals("We should have found only one item.", 1, result.size());
    64         Assert.assertTrue("The item found is prim1.", result.contains(prim1));
     69        assertEquals("We should have found only one item.", 1, result.size());
     70        assertTrue("The item found is prim1.", result.contains(prim1));
     71    }
     72
     73    /**
     74     * Unit test of method {@link ChangesetDataSet#iterator}.
     75     */
     76    @Test
     77    public void testIterator() {
     78        final ChangesetDataSet cds = new ChangesetDataSet();
     79        HistoryNode prim1 = new HistoryNode(1, 1, true, User.getAnonymous(), 1, new Date(), LatLon.ZERO);
     80        cds.put(prim1, ChangesetModificationType.CREATED);
     81        Iterator<ChangesetDataSetEntry> it = cds.iterator();
     82        assertTrue(it.hasNext());
     83        ChangesetDataSetEntry cdse = it.next();
     84        assertEquals(ChangesetModificationType.CREATED, cdse.getModificationType());
     85        assertEquals(prim1, cdse.getPrimitive());
     86        assertFalse(it.hasNext());
    6587    }
    6688}
  • trunk/test/unit/org/openstreetmap/josm/data/osm/FilterTest.java

    r10945 r11973  
    22package org.openstreetmap.josm.data.osm;
    33
     4import static org.junit.Assert.assertEquals;
    45import static org.junit.Assert.assertFalse;
    56import static org.junit.Assert.assertTrue;
     
    1819import org.openstreetmap.josm.actions.search.SearchCompiler.ParseError;
    1920import org.openstreetmap.josm.data.coor.LatLon;
     21import org.openstreetmap.josm.data.osm.Filter.FilterPreferenceEntry;
    2022import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    2123import org.openstreetmap.josm.io.OsmReader;
     
    2325
    2426import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     27import nl.jqno.equalsverifier.EqualsVerifier;
     28import nl.jqno.equalsverifier.Warning;
    2529
    2630/**
     
    187191    }
    188192
    189     private String filterCode(OsmPrimitive osm) {
     193    /**
     194     * Unit tests of {@link Filter.FilterPreferenceEntry} class.
     195     */
     196    @Test
     197    public void testFilterPreferenceEntry() {
     198        Filter f = new Filter();
     199        FilterPreferenceEntry fpe = f.getPreferenceEntry();
     200
     201        assertTrue(fpe.enable);
     202
     203        assertFalse(fpe.case_sensitive);
     204        assertFalse(fpe.hiding);
     205        assertFalse(fpe.inverted);
     206        assertFalse(fpe.mapCSS_search);
     207        assertFalse(fpe.regex_search);
     208
     209        assertEquals("add", fpe.mode);
     210        assertEquals("1", fpe.version);
     211        assertEquals("", fpe.text);
     212
     213        f.allElements = !f.allElements;
     214        f.caseSensitive = !f.caseSensitive;
     215        f.enable = !f.enable;
     216        f.hiding = !f.hiding;
     217        f.inverted = !f.inverted;
     218        f.mapCSSSearch = !f.mapCSSSearch;
     219        f.mode = SearchMode.remove;
     220        f.regexSearch = !f.regexSearch;
     221        f.text = "foo";
     222        fpe = f.getPreferenceEntry();
     223
     224        assertFalse(fpe.enable);
     225
     226        assertTrue(fpe.case_sensitive);
     227        assertTrue(fpe.hiding);
     228        assertTrue(fpe.inverted);
     229        assertTrue(fpe.mapCSS_search);
     230        assertTrue(fpe.regex_search);
     231
     232        assertEquals("remove", fpe.mode);
     233        assertEquals("1", fpe.version);
     234        assertEquals("foo", fpe.text);
     235
     236        assertEquals(fpe, new Filter(fpe).getPreferenceEntry());
     237    }
     238
     239    /**
     240     * Unit test of methods {@link FilterPreferenceEntry#equals} and {@link FilterPreferenceEntry#hashCode}.
     241     */
     242    @Test
     243    public void testEqualsContract() {
     244        EqualsVerifier.forClass(FilterPreferenceEntry.class).usingGetClass()
     245            .suppress(Warning.NONFINAL_FIELDS)
     246            .verify();
     247    }
     248
     249    private static String filterCode(OsmPrimitive osm) {
    190250        if (!osm.isDisabled())
    191251            return "v";
Note: See TracChangeset for help on using the changeset viewer.