Ignore:
Timestamp:
2023-03-13T21:59:27+01:00 (2 years ago)
Author:
taylor.smock
Message:

See #16567: Convert all assertion calls to JUnit 5 (patch by gaben, modified)

The modifications are as follows:

  • Merge DomainValidatorTest.testIDN and DomainValidatorTest.testIDNJava6OrLater
  • Update some tests to use @ParameterizedTest (DomainValidatorTest)
  • Replace various exception blocks with assertThrows. These typically looked like
        try {
            // Something that should throw an exception here
            fail("An exception should have been thrown");
        } catch (Exception e) {
            // Verify the exception matches expectations here
        }
    
  • Replace assertTrue(val instanceof Clazz) with assertInstanceOf
  • Replace JUnit 4 @Suite with JUnit 5 @Suite

Both the original patch and the modified patch fix various lint issues.

Location:
trunk/test/unit/org/openstreetmap/josm/data/projection
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/projection/EllipsoidTest.java

    r18144 r18690  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.projection;
     3
     4import static org.junit.jupiter.api.Assertions.fail;
    35
    46import java.security.SecureRandom;
    57import java.util.Random;
    68
    7 import org.junit.Assert;
    89import org.junit.jupiter.api.Test;
    910import org.openstreetmap.josm.data.coor.LatLon;
     
    3738                    String error = String.format("point: %s iterations: %s current: %s errorLat: %s errorLon %s",
    3839                            new LatLon(lat, lon), i, ll, Math.abs(lat - ll.lat()), Math.abs(lon - ll.lon()));
    39                     System.err.println(error);
    40                     Assert.fail();
     40                    fail(error);
    4141                }
    4242            }
  • trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionRefTest.java

    r18027 r18690  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.projection;
     3
     4import static org.junit.jupiter.api.Assertions.fail;
    35
    46import java.io.BufferedReader;
     
    3436import java.util.regex.Pattern;
    3537
    36 import org.junit.Assert;
    3738import org.junit.jupiter.api.Test;
    3839import org.junit.jupiter.api.extension.RegisterExtension;
     
    133134                    Matcher m = projPattern.matcher(line);
    134135                    if (!m.matches()) {
    135                         Assert.fail("unable to parse line: " + line);
     136                        fail("unable to parse line: " + line);
    136137                    }
    137138                    String code = m.group(1);
     
    383384        refs.stream().map(ref -> ref.code).forEach(allCodes::remove);
    384385        if (!allCodes.isEmpty()) {
    385             Assert.fail("no reference data for following projections: "+allCodes);
     386            fail("no reference data for following projections: "+allCodes);
    386387        }
    387388
     
    389390            String def0 = Projections.getInit(ref.code);
    390391            if (def0 == null) {
    391                 Assert.fail("unknown code: "+ref.code);
     392                fail("unknown code: "+ref.code);
    392393            }
    393394            if (!ref.def.equals(def0)) {
     
    411412                                "        expected: eastnorth(%s,%s),%n" +
    412413                                "        but got:  eastnorth(%s,%s)!%n",
    413                                 proj.toString(), proj.toCode(), ll.lat(), ll.lon(), enRef.east(), enRef.north(), en.east(), en.north());
     414                                proj, proj.toCode(), ll.lat(), ll.lon(), enRef.east(), enRef.north(), en.east(), en.north());
    414415                        failures.add(errorEN);
    415416                        failingProjs.computeIfAbsent(proj.proj.getProj4Id(), x -> new TreeSet<>()).add(ref.code);
     
    419420        });
    420421        if (!failures.isEmpty()) {
    421             System.err.println(failures.toString());
     422            System.err.println(failures);
    422423            throw new AssertionError("Failing:\n" +
    423424                    failingProjs.keySet().size() + " projections: " + failingProjs.keySet() + "\n" +
  • trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionRegressionTest.java

    r18100 r18690  
    161161        for (String code : Projections.getAllProjectionCodes()) {
    162162            if (!dataCodes.contains(code)) {
    163                  fail.append("Did not find projection "+code+" in test data!\n");
     163                 fail.append("Did not find projection ").append(code).append(" in test data!\n");
    164164             }
    165165        }
     
    169169            Projection proj = Projections.getProjectionByCode(data.code);
    170170            if (proj == null) {
    171                 fail.append("Projection "+data.code+" from test data was not found!\n");
     171                fail.append("Projection ").append(data.code).append(" from test data was not found!\n");
    172172                continue;
    173173            }
     
    178178                        "        expected: eastnorth(%s,%s),%n" +
    179179                        "        but got:  eastnorth(%s,%s)!%n",
    180                         proj.toString(), data.code, data.ll.lat(), data.ll.lon(), data.en.east(), data.en.north(), en.east(), en.north());
     180                        proj, data.code, data.ll.lat(), data.ll.lon(), data.en.east(), data.en.north(), en.east(), en.north());
    181181                fail.append(error);
    182182            }
     
    185185                        "        expected: latlon(%s,%s),%n" +
    186186                        "        but got:  latlon(%s,%s)!%n",
    187                         proj.toString(), data.code, data.en.east(), data.en.north(), data.ll2.lat(), data.ll2.lon(), ll2.lat(), ll2.lon());
     187                        proj, data.code, data.en.east(), data.en.north(), data.ll2.lat(), data.ll2.lon(), ll2.lat(), ll2.lon());
    188188                fail.append(error);
    189189            }
     
    191191
    192192        if (fail.length() > 0) {
    193             System.err.println(fail.toString());
     193            System.err.println(fail);
    194194            throw new AssertionError(fail.toString());
    195195        }
  • trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionTest.java

    r18494 r18690  
    33
    44import static org.junit.jupiter.api.Assertions.assertTrue;
     5import static org.junit.jupiter.api.Assertions.fail;
    56
    67import java.security.SecureRandom;
     
    1011import java.util.Random;
    1112
    12 import org.junit.Assert;
    1313import org.junit.jupiter.api.Test;
    1414import org.openstreetmap.josm.data.Bounds;
     
    4040
    4141        for (int i = 0; i <= 3; ++i) {
    42             testProjection(Projections.getProjectionByCode("EPSG:"+Integer.toString(27561+i))); // Lambert 4 Zones France
     42            testProjection(Projections.getProjectionByCode("EPSG:"+ (27561 + i))); // Lambert 4 Zones France
    4343        }
    4444
    4545        for (int i = 0; i <= 4; ++i) {
    46             testProjection(Projections.getProjectionByCode("EPSG:"+Integer.toString(2176+i))); // PUWG Poland
     46            testProjection(Projections.getProjectionByCode("EPSG:"+ (2176 + i))); // PUWG Poland
    4747        }
    4848
     
    5050
    5151        for (int i = 0; i <= 60; ++i) {
    52             testProjection(Projections.getProjectionByCode("EPSG:"+Integer.toString(32601+i))); // UTM North
    53             testProjection(Projections.getProjectionByCode("EPSG:"+Integer.toString(32701+i))); // UTM South
     52            testProjection(Projections.getProjectionByCode("EPSG:"+ (32601 + i))); // UTM North
     53            testProjection(Projections.getProjectionByCode("EPSG:"+ (32701 + i))); // UTM South
    5454        }
    5555
     
    5959
    6060        for (int i = 0; i <= 8; ++i) {
    61             testProjection(Projections.getProjectionByCode("EPSG:"+Integer.toString(3942+i))); // Lambert CC9 Zones France
     61            testProjection(Projections.getProjectionByCode("EPSG:"+ (3942 + i))); // Lambert CC9 Zones France
    6262        }
    6363
    6464        for (int i = 0; i <= 17; ++i) {
    65             testProjection(Projections.getProjectionByCode("EPSG:"+Integer.toString(102421+i))); // WGS_1984_ARC_System Zones
     65            testProjection(Projections.getProjectionByCode("EPSG:"+ (102421 + i))); // WGS_1984_ARC_System Zones
    6666        }
    6767
     
    7070
    7171        if (error) {
    72             System.err.println(text);
    73             Assert.fail();
     72            fail(text);
    7473        }
    7574    }
     
    8079            Bounds b = p.getWorldBoundsLatLon();
    8180
    82             text += String.format("*** %s %s%n", p.toString(), p.toCode());
     81            text += String.format("*** %s %s%n", p, p.toCode());
    8382            for (int num = 0; num < 1000; ++num) {
    8483
     
    148147
    149148        if (error2) {
    150             System.err.println(text2);
    151             Assert.fail();
     149            fail(text2);
    152150        }
    153151        assertTrue(projIds.isEmpty(), "missing test: "+projIds);
  • trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionsTest.java

    r18030 r18690  
    22package org.openstreetmap.josm.data.projection;
    33
    4 import static org.junit.Assert.assertNull;
     4import static org.junit.jupiter.api.Assertions.assertNull;
    55
    66import org.junit.jupiter.api.Test;
Note: See TracChangeset for help on using the changeset viewer.