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.

File:
1 edited

Legend:

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