Changeset 14100 in josm


Ignore:
Timestamp:
2018-08-06T00:26:16+02:00 (9 months ago)
Author:
Don-vip
Message:

increase test coverage

Location:
trunk/test/unit/org/openstreetmap/josm
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/TestUtils.java

    r14092 r14100  
    2626import java.util.Comparator;
    2727import java.util.Objects;
     28import java.util.Set;
    2829import java.util.concurrent.ExecutionException;
    2930import java.util.concurrent.ThreadPoolExecutor;
     
    5051import org.openstreetmap.josm.tools.JosmRuntimeException;
    5152import org.openstreetmap.josm.tools.Utils;
     53import org.reflections.Reflections;
    5254
    5355import com.github.tomakehurst.wiremock.WireMockServer;
     
    516518        }
    517519    }
     520
     521    /**
     522     * Returns all JOSM subtypes of the given class.
     523     * @param <T> class
     524     * @param superClass class
     525     * @return all JOSM subtypes of the given class
     526     */
     527    public static <T> Set<Class<? extends T>> getJosmSubtypes(Class<T> superClass) {
     528        return new Reflections("org.openstreetmap.josm").getSubTypesOf(superClass);
     529    }
    518530}
  • trunk/test/unit/org/openstreetmap/josm/data/osm/search/SearchCompilerTest.java

    r13920 r14100  
    1414import java.util.Collection;
    1515import java.util.Collections;
    16 
     16import java.util.Set;
     17
     18import org.junit.Assert;
    1719import org.junit.Rule;
    1820import org.junit.Test;
     
    3941import org.openstreetmap.josm.gui.tagging.presets.items.Key;
    4042import org.openstreetmap.josm.testutils.JOSMTestRules;
     43import org.openstreetmap.josm.tools.Logging;
    4144import org.openstreetmap.josm.tools.date.DateUtils;
    4245
    4346import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     47import nl.jqno.equalsverifier.EqualsVerifier;
     48import nl.jqno.equalsverifier.Warning;
    4449
    4550/**
     
    701706        }
    702707    }
     708
     709    /**
     710     * Unit test of methods {@link Match#equals} and {@link Match#hashCode}, including all subclasses.
     711     */
     712    @Test
     713    public void testEqualsContract() {
     714        TestUtils.assumeWorkingEqualsVerifier();
     715        Set<Class<? extends Match>> matchers = TestUtils.getJosmSubtypes(Match.class);
     716        Assert.assertTrue(matchers.size() >= 10); // if it finds less than 10 classes, something is broken
     717        for (Class<?> c : matchers) {
     718            Logging.debug(c.toString());
     719            EqualsVerifier.forClass(c).usingGetClass()
     720                .suppress(Warning.NONFINAL_FIELDS, Warning.INHERITED_DIRECTLY_FROM_OBJECT)
     721                .withPrefabValues(TaggingPreset.class, newTaggingPreset("foo"), newTaggingPreset("bar"))
     722                .verify();
     723        }
     724    }
     725
     726    private static TaggingPreset newTaggingPreset(String name) {
     727        TaggingPreset result = new TaggingPreset();
     728        result.name = name;
     729        return result;
     730    }
    703731}
  • trunk/test/unit/org/openstreetmap/josm/gui/TableCellRendererTest.java

    r12632 r14100  
    1616import org.junit.Rule;
    1717import org.junit.Test;
     18import org.openstreetmap.josm.TestUtils;
    1819import org.openstreetmap.josm.testutils.JOSMTestRules;
    1920import org.openstreetmap.josm.tools.Utils;
    20 import org.reflections.Reflections;
    2121
    2222import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    6161    @Test
    6262    public void testTableCellRenderer() throws ReflectiveOperationException {
    63         Reflections reflections = new Reflections("org.openstreetmap.josm");
    64         Set<Class<? extends TableCellRenderer>> renderers = reflections.getSubTypesOf(TableCellRenderer.class);
     63        Set<Class<? extends TableCellRenderer>> renderers = TestUtils.getJosmSubtypes(TableCellRenderer.class);
    6564        Assert.assertTrue(renderers.size() >= 10); // if it finds less than 10 classes, something is broken
    6665        JTable tbl = new JTable(2, 2);
Note: See TracChangeset for help on using the changeset viewer.