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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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    }
Note: See TracChangeset for help on using the changeset viewer.