Changeset 8793 in josm for trunk/test/unit


Ignore:
Timestamp:
2015-09-24T22:29:41+02:00 (9 years ago)
Author:
Don-vip
Message:

fix #11889 - adapt projection regression test to Java 9. Safe approach: keep exact comparison but duplicate data files.

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

Legend:

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

    r8514 r8793  
    107107        .toString();
    108108    }
     109
     110    /**
     111     * Returns the Java version as a double value.
     112     * @return the Java version as a double value (1.7, 1.8, 1.9, etc.)
     113     */
     114    public static double getJavaVersion() {
     115        String version = System.getProperty("java.version");
     116        int pos = version.indexOf('.');
     117        pos = version.indexOf('.', pos + 1);
     118        return Double.parseDouble(version.substring(0, pos));
     119    }
    109120}
  • trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionRegressionTest.java

    r8540 r8793  
    1515import java.util.HashMap;
    1616import java.util.HashSet;
    17 import java.util.LinkedHashSet;
    1817import java.util.List;
    1918import java.util.Map;
    2019import java.util.Random;
    2120import java.util.Set;
     21import java.util.TreeSet;
    2222
    2323import org.junit.BeforeClass;
    2424import org.junit.Test;
    2525import org.openstreetmap.josm.JOSMFixture;
     26import org.openstreetmap.josm.TestUtils;
    2627import org.openstreetmap.josm.data.Bounds;
    2728import org.openstreetmap.josm.data.coor.EastNorth;
     
    4546
    4647    private static final String PROJECTION_DATA_FILE = "data_nodist/projection-regression-test-data.csv";
     48    private static final String PROJECTION_DATA_FILE_JAVA_9 = "data_nodist/projection-regression-test-data-java9.csv";
    4749
    4850    private static class TestData {
     
    5355    }
    5456
    55     public static void main(String[] args) throws IOException, FileNotFoundException {
     57    private static String getProjectionDataFile() {
     58        return TestUtils.getJavaVersion() >= 1.9 ? PROJECTION_DATA_FILE_JAVA_9 : PROJECTION_DATA_FILE;
     59    }
     60
     61    public static void main(String[] args) throws IOException {
    5662        setUp();
    5763
     
    6268
    6369        List<TestData> prevData = new ArrayList<>();
    64         if (new File(PROJECTION_DATA_FILE).exists()) {
     70        if (new File(getProjectionDataFile()).exists()) {
    6571            prevData = readData();
    6672        }
     
    7076        }
    7177
    72         Set<String> codesToWrite = new LinkedHashSet<>();
     78        Set<String> codesToWrite = new TreeSet<>();
    7379        for (TestData data : prevData) {
    7480            if (supportedCodesMap.containsKey(data.code)) {
     
    8490        Random rand = new Random();
    8591        try (BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
    86                 new FileOutputStream(PROJECTION_DATA_FILE), StandardCharsets.UTF_8))) {
     92                new FileOutputStream(getProjectionDataFile()), StandardCharsets.UTF_8))) {
    8793            out.write("# Data for test/unit/org/openstreetmap/josm/data/projection/ProjectionRegressionTest.java\n");
    8894            out.write("# Format: 1. Projection code; 2. lat/lon; 3. lat/lon projected -> east/north; 4. east/north (3.) inverse projected\n");
     
    108114
    109115    private static List<TestData> readData() throws IOException, FileNotFoundException {
    110         try (BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(PROJECTION_DATA_FILE), StandardCharsets.UTF_8))) {
     116        try (BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(getProjectionDataFile()),
     117                StandardCharsets.UTF_8))) {
    111118            List<TestData> result = new ArrayList<>();
    112119            String line;
Note: See TracChangeset for help on using the changeset viewer.