Changeset 9489 in josm for trunk/test/unit


Ignore:
Timestamp:
2016-01-16T16:41:44+01:00 (6 years ago)
Author:
Don-vip
Message:

unit tests code refactoring/cleanup

Location:
trunk/test/unit/org/openstreetmap/josm
Files:
9 edited

Legend:

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

    r9246 r9489  
    44import static org.junit.Assert.fail;
    55
     6import java.io.File;
     7import java.io.IOException;
     8import java.io.InputStream;
    69import java.util.Arrays;
    710import java.util.Comparator;
     11
     12import org.openstreetmap.josm.io.Compression;
    813
    914/**
     
    4651    public static String getRegressionDataFile(int ticketid, String filename) {
    4752        return getRegressionDataDir(ticketid) + '/' + filename;
     53    }
     54
     55    /**
     56     * Gets input stream to given file in test data directory for given ticket id.
     57     * @param ticketid Ticket numeric identifier
     58     * @param filename File name
     59     * @return path to given file in test data directory for given ticket id
     60     * @throws IOException if any I/O error occurs
     61     */
     62    public static InputStream getRegressionDataStream(int ticketid, String filename) throws IOException {
     63        return Compression.getUncompressedFileInputStream(new File(getRegressionDataDir(ticketid) + '/' + filename));
    4864    }
    4965
  • trunk/test/unit/org/openstreetmap/josm/actions/CombineWayActionTest.java

    r9225 r9489  
    44import static org.junit.Assert.assertEquals;
    55
    6 import java.io.FileInputStream;
    76import java.io.IOException;
    87import java.io.InputStream;
     
    109import java.util.List;
    1110import java.util.Set;
    12 
    13 import nl.jqno.equalsverifier.EqualsVerifier;
    1411
    1512import org.junit.BeforeClass;
     
    2320import org.openstreetmap.josm.io.IllegalDataException;
    2421import org.openstreetmap.josm.io.OsmReader;
     22
     23import nl.jqno.equalsverifier.EqualsVerifier;
    2524
    2625/**
     
    4443    @Test
    4544    public void testTicket11957() throws IOException, IllegalDataException {
    46         try (InputStream is = new FileInputStream(TestUtils.getRegressionDataFile(11957, "data.osm"))) {
     45        try (InputStream is = TestUtils.getRegressionDataStream(11957, "data.osm")) {
    4746            DataSet ds = OsmReader.parseDataSet(is, null);
    4847            NodeGraph graph = NodeGraph.createNearlyUndirectedGraphFromNodeWays(ds.getWays());
  • trunk/test/unit/org/openstreetmap/josm/actions/JoinAreasActionTest.java

    r8930 r9489  
    44import static org.junit.Assert.assertEquals;
    55
    6 import java.io.FileInputStream;
    76import java.io.IOException;
    87import java.io.InputStream;
     
    3938    @Test
    4039    public void testTicket10511() throws IOException, IllegalDataException {
    41         try (InputStream is = new FileInputStream(TestUtils.getRegressionDataFile(10511, "10511_mini.osm"))) {
     40        try (InputStream is = TestUtils.getRegressionDataStream(10511, "10511_mini.osm")) {
    4241            DataSet ds = OsmReader.parseDataSet(is, null);
    4342            Main.map.mapView.addLayer(new OsmDataLayer(ds, null, null));
     
    5453    @Test
    5554    public void testTicket11992() throws IOException, IllegalDataException {
    56         try (InputStream is = new FileInputStream(TestUtils.getRegressionDataFile(11992, "shapes.osm"))) {
     55        try (InputStream is = TestUtils.getRegressionDataStream(11992, "shapes.osm")) {
    5756            DataSet ds = OsmReader.parseDataSet(is, null);
    5857            assertEquals(10, ds.getWays().size());
  • trunk/test/unit/org/openstreetmap/josm/actions/PurgeActionTest.java

    r8984 r9489  
    55import static org.junit.Assert.assertTrue;
    66
    7 import java.io.FileInputStream;
    87import java.io.FileNotFoundException;
    98import java.io.IOException;
     
    4241    @Test
    4342    public void testCopyStringWayRelation() throws FileNotFoundException, IOException, IllegalDataException {
    44         try (InputStream is = new FileInputStream(TestUtils.getRegressionDataFile(12038, "data.osm"))) {
     43        try (InputStream is = TestUtils.getRegressionDataStream(12038, "data.osm")) {
    4544            DataSet ds = OsmReader.parseDataSet(is, null);
    4645            Main.map.mapView.addLayer(new OsmDataLayer(ds, null, null));
  • trunk/test/unit/org/openstreetmap/josm/data/imagery/WMTSTileSourceTest.java

    r9095 r9489  
    1414import org.openstreetmap.josm.JOSMFixture;
    1515import org.openstreetmap.josm.Main;
     16import org.openstreetmap.josm.TestUtils;
    1617import org.openstreetmap.josm.data.Bounds;
    1718import org.openstreetmap.josm.data.coor.LatLon;
     
    2425
    2526    private ImageryInfo testImageryTMS =  new ImageryInfo("test imagery", "http://localhost", "tms", null, null);
    26     private ImageryInfo testImageryPSEUDO_MERCATOR = getImagery("test/data/wmts/getcapabilities-pseudo-mercator.xml");
    27     private ImageryInfo testImageryTOPO_PL = getImagery("test/data/wmts/getcapabilities-TOPO.xml");
    28     private ImageryInfo testImageryORTO_PL = getImagery("test/data/wmts/getcapabilities-ORTO.xml");
    29     private ImageryInfo testImageryWIEN = getImagery("test/data/wmts/getCapabilities-wien.xml");
    30     private ImageryInfo testImageryWALLONIE = getImagery("test/data/wmts/WMTSCapabilities-Wallonie.xml");
    31     private ImageryInfo testImageryOntario = getImagery("test/data/wmts/WMTSCapabilities-Ontario.xml");
    32     private ImageryInfo testImagery12168 = getImagery("test/data/wmts/bug12168-WMTSCapabilities.xml");
    33     private ImageryInfo testLotsOfLayers = getImagery("test/data/wmts/getCapabilities-lots-of-layers.xml");
     27    private ImageryInfo testImageryPSEUDO_MERCATOR = getImagery(TestUtils.getTestDataRoot() + "wmts/getcapabilities-pseudo-mercator.xml");
     28    private ImageryInfo testImageryTOPO_PL = getImagery(TestUtils.getTestDataRoot() + "wmts/getcapabilities-TOPO.xml");
     29    private ImageryInfo testImageryORTO_PL = getImagery(TestUtils.getTestDataRoot() + "wmts/getcapabilities-ORTO.xml");
     30    private ImageryInfo testImageryWIEN = getImagery(TestUtils.getTestDataRoot() + "wmts/getCapabilities-wien.xml");
     31    private ImageryInfo testImageryWALLONIE = getImagery(TestUtils.getTestDataRoot() + "wmts/WMTSCapabilities-Wallonie.xml");
     32    private ImageryInfo testImageryOntario = getImagery(TestUtils.getTestDataRoot() + "wmts/WMTSCapabilities-Ontario.xml");
     33    private ImageryInfo testImagery12168 = getImagery(TestUtils.getTestDataRoot() + "wmts/bug12168-WMTSCapabilities.xml");
     34    private ImageryInfo testLotsOfLayers = getImagery(TestUtils.getTestDataRoot() + "wmts/getCapabilities-lots-of-layers.xml");
    3435
    3536    /**
  • trunk/test/unit/org/openstreetmap/josm/data/osm/MultipolygonBuilderTest.java

    r9480 r9489  
    44import static org.junit.Assert.assertNull;
    55
    6 import java.io.FileInputStream;
    76import java.io.InputStream;
    87
     
    1312import org.openstreetmap.josm.JOSMFixture;
    1413import org.openstreetmap.josm.TestUtils;
    15 import org.openstreetmap.josm.io.Compression;
    1614import org.openstreetmap.josm.io.OsmReader;
    1715
     
    4139    @Test
    4240    public void testTicket12376() throws Exception {
    43         try (InputStream is = new FileInputStream(TestUtils.getRegressionDataFile(12376, "multipolygon_hang.osm.bz2"))) {
    44             DataSet ds = OsmReader.parseDataSet(Compression.BZIP2.getUncompressedInputStream(is), null);
    45             for (Relation r : ds.getRelations()) {
     41        try (InputStream is = TestUtils.getRegressionDataStream(12376, "multipolygon_hang.osm.bz2")) {
     42            for (Relation r : OsmReader.parseDataSet(is, null).getRelations()) {
    4643                assertNull(new MultipolygonBuilder().makeFromWays(r.getMemberPrimitives(Way.class)));
    4744            }
  • trunk/test/unit/org/openstreetmap/josm/data/osm/OsmPrimitiveTest.java

    r9214 r9489  
    1313import org.openstreetmap.josm.data.projection.Projections;
    1414
     15/**
     16 * Unit tests of the {@code OsmPrimitive} class.
     17 */
    1518public class OsmPrimitiveTest {
    1619
  • trunk/test/unit/org/openstreetmap/josm/data/osm/WaySegmentTest.java

    r9214 r9489  
    1010import org.openstreetmap.josm.data.coor.LatLon;
    1111
     12/**
     13 * Unit tests of the {@code WaySegment} class.
     14 */
    1215public class WaySegmentTest {
    1316
     17    /**
     18     * Setup test.
     19     */
    1420    @Before
    15     public void setUp() throws Exception {
     21    public void setUp() {
    1622        JOSMFixture.createUnitTestFixture().init();
    1723    }
  • trunk/test/unit/org/openstreetmap/josm/gui/DefaultNameFormatterTest.java

    r9475 r9489  
    55import static org.junit.Assert.assertSame;
    66
    7 import java.io.FileInputStream;
    87import java.io.IOException;
    98import java.io.InputStream;
     
    2423import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetReader;
    2524import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;
    26 import org.openstreetmap.josm.io.Compression;
    2725import org.openstreetmap.josm.io.IllegalDataException;
    2826import org.openstreetmap.josm.io.OsmReader;
     
    5553        Comparator<Relation> comparator = DefaultNameFormatter.getInstance().getRelationComparator();
    5654
    57         try (InputStream is = new FileInputStream(TestUtils.getRegressionDataFile(9632, "data.osm.zip"))) {
    58             DataSet ds = OsmReader.parseDataSet(Compression.ZIP.getUncompressedInputStream(is), null);
     55        try (InputStream is = TestUtils.getRegressionDataStream(9632, "data.osm.zip")) {
     56            DataSet ds = OsmReader.parseDataSet(is, null);
    5957
    6058            // Test with 3 known primitives causing the problem. Correct order is p1, p3, p2 with this preset
Note: See TracChangeset for help on using the changeset viewer.