Ignore:
Timestamp:
2014-08-06T19:33:57+02:00 (10 years ago)
Author:
donvip
Message:

[josm_opendata] add more unit tests, fix Java 7 warnings

Location:
applications/editors/josm/plugins/opendata/test/unit/org/openstreetmap/josm/plugins/opendata/core/io
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/opendata/test/unit/org/openstreetmap/josm/plugins/opendata/core/io/NonRegFunctionalTests.java

    r30563 r30568  
    66import static org.junit.Assert.assertTrue;
    77
     8import java.io.IOException;
     9import java.nio.file.DirectoryIteratorException;
     10import java.nio.file.DirectoryStream;
     11import java.nio.file.Files;
     12import java.nio.file.Path;
     13import java.nio.file.Paths;
     14import java.util.ArrayList;
    815import java.util.Collection;
    916
     17import org.openstreetmap.josm.TestUtils;
    1018import org.openstreetmap.josm.data.osm.DataSet;
    1119import org.openstreetmap.josm.data.osm.Node;
     
    4048        assertTrue(found);
    4149    }
     50   
     51    /**
     52     * Lists all datasets files matching given extension.
     53     * @param ext file extension to search for
     54     * @returns List of all datasets files matching given extension
     55     * @throws IOException in case of I/O error
     56     */
     57    public static Collection<Path> listDataFiles(String ext) throws IOException {
     58        Collection<Path> result = new ArrayList<>();
     59        addTree(Paths.get(TestUtils.getTestDataRoot()+"datasets"), result, ext.toLowerCase());
     60        return result;
     61    }
     62   
     63    static void addTree(Path directory, Collection<Path> all, String ext) throws IOException {
     64        try (DirectoryStream<Path> ds = Files.newDirectoryStream(directory)) {
     65            for (Path child : ds) {
     66                if (Files.isDirectory(child)) {
     67                    addTree(child, all, ext);
     68                } else if (child.toString().toLowerCase().endsWith(ext)) {
     69                    all.add(child);
     70                }
     71            }
     72        } catch (DirectoryIteratorException ex) {
     73            // I/O error encounted during the iteration, the cause is an IOException
     74            throw ex.getCause();
     75        }
     76    }
    4277}
  • applications/editors/josm/plugins/opendata/test/unit/org/openstreetmap/josm/plugins/opendata/core/io/geographic/MifReaderTest.java

    r30550 r30568  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.opendata.core.io.geographic;
    3 
    4 import static org.junit.Assert.assertFalse;
    53
    64import java.io.File;
     
    1311import org.openstreetmap.josm.JOSMFixture;
    1412import org.openstreetmap.josm.TestUtils;
    15 import org.openstreetmap.josm.data.osm.DataSet;
     13import org.openstreetmap.josm.plugins.opendata.core.io.NonRegFunctionalTests;
    1614
    1715/**
     
    3634        File file = new File(TestUtils.getRegressionDataFile(9592, "bg.mif"));
    3735        try (InputStream is = new FileInputStream(file)) {
    38             DataSet ds = MifReader.parseDataSet(is, file, null, null);
    39             assertFalse(ds.allPrimitives().isEmpty());
     36            NonRegFunctionalTests.testGeneric(MifReader.parseDataSet(is, file, null, null));
    4037        }
    4138    }
Note: See TracChangeset for help on using the changeset viewer.