Changeset 7033 in josm for trunk/test/unit/org


Ignore:
Timestamp:
2014-05-01T02:34:43+02:00 (10 years ago)
Author:
Don-vip
Message:

see #8465 - global use of try-with-resources, according to

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

Legend:

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

    r7005 r7033  
    55
    66import java.io.FileInputStream;
    7 import java.io.FileNotFoundException;
     7import java.io.IOException;
     8import java.io.InputStream;
    89import java.util.Arrays;
    910import java.util.Collection;
     
    6364
    6465    @Test
    65     public void filter_test() throws ParseError, IllegalDataException, FileNotFoundException {
     66    public void filter_test() throws ParseError, IllegalDataException, IOException {
    6667        for (int i : new int [] {1,2,3, 11,12,13,14, 15}) {
    67             DataSet ds = OsmReader.parseDataSet(new FileInputStream("data_nodist/filterTests.osm"), NullProgressMonitor.INSTANCE);
     68            DataSet ds;
     69            try (InputStream is = new FileInputStream("data_nodist/filterTests.osm")) {
     70                ds = OsmReader.parseDataSet(is, NullProgressMonitor.INSTANCE);
     71            }
    6872
    6973            List<Filter> filters = new LinkedList<>();
  • trunk/test/unit/org/openstreetmap/josm/data/osm/QuadBucketsTest.java

    r7005 r7033  
    33
    44import java.io.FileInputStream;
     5import java.io.InputStream;
    56import java.util.ArrayList;
    67import java.util.Collection;
     
    6667    public void testRemove() throws Exception {
    6768        Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
    68         DataSet ds = OsmReader.parseDataSet(new FileInputStream("data_nodist/restriction.osm"), NullProgressMonitor.INSTANCE);
    69         removeAllTest(ds);
     69        try (InputStream fis = new FileInputStream("data_nodist/restriction.osm")) {
     70            DataSet ds = OsmReader.parseDataSet(fis, NullProgressMonitor.INSTANCE);
     71            removeAllTest(ds);
     72        }
    7073    }
    7174
     
    7376    public void testMove() throws Exception {
    7477        Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
    75         DataSet ds = OsmReader.parseDataSet(new FileInputStream("data_nodist/restriction.osm"), NullProgressMonitor.INSTANCE);
    76 
    77         for (Node n: ds.getNodes()) {
    78             n.setCoor(new LatLon(10, 10));
     78        try (InputStream fis = new FileInputStream("data_nodist/restriction.osm")) {
     79            DataSet ds = OsmReader.parseDataSet(fis, NullProgressMonitor.INSTANCE);
     80   
     81            for (Node n: ds.getNodes()) {
     82                n.setCoor(new LatLon(10, 10));
     83            }
     84   
     85            removeAllTest(ds);
    7986        }
    80 
    81         removeAllTest(ds);
    8287    }
    8388}
  • trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionRefTest.java

    r7005 r7033  
    4949    @Test
    5050    public void test() throws IOException, FileNotFoundException {
    51         BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream("data_nodist/projection-reference-data.csv"), Utils.UTF_8));
    52         StringBuilder fail = new StringBuilder();
    53         String line;
    54         while ((line = in.readLine()) != null) {
    55             if (line.startsWith("#")) {
    56                 continue;
    57             }
    58             String[] f = line.split(",");
    59             String code = f[0];
    60             double lat = Double.parseDouble(f[1]);
    61             double lon = Double.parseDouble(f[2]);
    62             double east = Double.parseDouble(f[3]);
    63             double north = Double.parseDouble(f[4]);
    64             Projection p = Projections.getProjectionByCode(code);
    65             {
     51        try (BufferedReader in = new BufferedReader(new InputStreamReader(
     52                new FileInputStream("data_nodist/projection-reference-data.csv"), Utils.UTF_8))) {
     53            StringBuilder fail = new StringBuilder();
     54            String line;
     55            while ((line = in.readLine()) != null) {
     56                if (line.startsWith("#")) {
     57                    continue;
     58                }
     59                String[] f = line.split(",");
     60                String code = f[0];
     61                double lat = Double.parseDouble(f[1]);
     62                double lon = Double.parseDouble(f[2]);
     63                double east = Double.parseDouble(f[3]);
     64                double north = Double.parseDouble(f[4]);
     65                Projection p = Projections.getProjectionByCode(code);
    6666                EastNorth en = p.latlon2eastNorth(new LatLon(lat, lon));
    67                 String error = String.format("%s (%s): Projecting latlon(%s,%s):%n" +
     67                String errorEN = String.format("%s (%s): Projecting latlon(%s,%s):%n" +
    6868                        "        expected: eastnorth(%s,%s),%n" +
    6969                        "        but got:  eastnorth(%s,%s)!%n",
    7070                        p.toString(), code, lat, lon, east, north, en.east(), en.north());
    71                 double EPSILON = 1e-3; // 1 mm accuracy
    72                 if (Math.abs(east - en.east()) > EPSILON || Math.abs(north - en.north()) > EPSILON) {
    73                     fail.append(error);
     71                double EPSILON_EN = 1e-3; // 1 mm accuracy
     72                if (Math.abs(east - en.east()) > EPSILON_EN || Math.abs(north - en.north()) > EPSILON_EN) {
     73                    fail.append(errorEN);
    7474                }
    75             }
    76             {
    7775                LatLon ll = p.eastNorth2latlon(new EastNorth(east, north));
    78                 String error = String.format("%s (%s): Inverse projecting eastnorth(%s,%s):%n" +
     76                String errorLL = String.format("%s (%s): Inverse projecting eastnorth(%s,%s):%n" +
    7977                        "        expected: latlon(%s,%s),%n" +
    8078                        "        but got:  latlon(%s,%s)!%n",
    8179                        p.toString(), code, east, north, lat, lon, ll.lat(), ll.lon());
    82                 double EPSILON = Math.toDegrees(1e-3 / 6378137); // 1 mm accuracy (or better)
    83                 if (Math.abs(lat - ll.lat()) > EPSILON || Math.abs(lon - ll.lon()) > EPSILON) {
     80                double EPSILON_LL = Math.toDegrees(1e-3 / 6378137); // 1 mm accuracy (or better)
     81                if (Math.abs(lat - ll.lat()) > EPSILON_LL || Math.abs(lon - ll.lon()) > EPSILON_LL) {
    8482                    if (!("yes".equals(System.getProperty("suppressPermanentFailure")) && code.equals("EPSG:21781"))) {
    85                         fail.append(error);
     83                        fail.append(errorLL);
    8684                    }
    8785                }
    8886            }
    89         }
    90         Utils.close(in);
    91         if (fail.length() > 0) {
    92             System.err.println(fail.toString());
    93             throw new AssertionError(fail.toString());
     87            if (fail.length() > 0) {
     88                System.err.println(fail.toString());
     89                throw new AssertionError(fail.toString());
     90            }
    9491        }
    9592    }
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/UnconnectedWaysTest.java

    r6881 r7033  
    66
    77import java.io.FileInputStream;
     8import java.io.InputStream;
    89
    910import org.junit.Before;
     
    3334    @Test
    3435    public void testTicket6313() throws Exception {
    35         final DataSet ds = OsmReader.parseDataSet(new FileInputStream("data_nodist/UnconnectedWaysTest.osm"), NullProgressMonitor.INSTANCE);
    36         bib.visit(ds.allPrimitives());
    37         bib.endTest();
    38         assertThat(bib.getErrors(), isEmpty());
     36        try (InputStream fis = new FileInputStream("data_nodist/UnconnectedWaysTest.osm")) {
     37            final DataSet ds = OsmReader.parseDataSet(fis, NullProgressMonitor.INSTANCE);
     38            bib.visit(ds.allPrimitives());
     39            bib.endTest();
     40            assertThat(bib.getErrors(), isEmpty());
     41        }
    3942    }
    4043}
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/sort/RelationSorterTest.java

    r7005 r7033  
    33
    44import java.io.FileInputStream;
    5 import java.io.FileNotFoundException;
     5import java.io.IOException;
     6import java.io.InputStream;
    67import java.util.List;
    78
     
    2425
    2526    @BeforeClass
    26     public static void loadData() throws FileNotFoundException, IllegalDataException {
     27    public static void loadData() throws IllegalDataException, IOException {
    2728        Main.initApplicationPreferences();
    2829        Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
    29         testDataset = OsmReader.parseDataSet(new FileInputStream("data_nodist/relation_sort.osm"), NullProgressMonitor.INSTANCE);
     30        try (InputStream fis = new FileInputStream("data_nodist/relation_sort.osm")) {
     31            testDataset = OsmReader.parseDataSet(fis, NullProgressMonitor.INSTANCE);
     32        }
    3033    }
    3134
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/sort/WayConnectionTypeCalculatorTest.java

    r7005 r7033  
    33
    44import java.io.FileInputStream;
    5 import java.io.FileNotFoundException;
     5import java.io.IOException;
     6import java.io.InputStream;
    67import java.util.Arrays;
    78import java.util.List;
     
    2526
    2627    @BeforeClass
    27     public static void loadData() throws FileNotFoundException, IllegalDataException {
     28    public static void loadData() throws IllegalDataException, IOException {
    2829        Main.initApplicationPreferences();
    2930        Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
    30         testDataset = OsmReader.parseDataSet(new FileInputStream("data_nodist/relation_sort.osm"), NullProgressMonitor.INSTANCE);
     31        try (InputStream fis = new FileInputStream("data_nodist/relation_sort.osm")) {
     32            testDataset = OsmReader.parseDataSet(fis, NullProgressMonitor.INSTANCE);
     33        }
    3134    }
    3235
Note: See TracChangeset for help on using the changeset viewer.