Ignore:
Timestamp:
2023-03-13T21:59:27+01:00 (3 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/osm/WaySegmentTest.java

    r17896 r18690  
    22package org.openstreetmap.josm.data.osm;
    33
     4import static org.junit.jupiter.api.Assertions.assertEquals;
     5import static org.junit.jupiter.api.Assertions.assertThrows;
     6
    47import java.util.Arrays;
    58
    6 import org.junit.Assert;
    79import org.junit.jupiter.api.extension.RegisterExtension;
    810import org.junit.jupiter.api.Test;
     
    2527
    2628    @Test
    27     void testForNodePair() throws Exception {
     29    void testForNodePair() {
    2830        final DataSet ds = new DataSet();
    2931        final Node n1 = new Node(LatLon.ZERO);
     
    4244        w.addNode(n4);
    4345        w.addNode(n1);
    44         Assert.assertEquals(WaySegment.forNodePair(w, n1, n2).getLowerIndex(), 0);
    45         Assert.assertEquals(WaySegment.forNodePair(w, n1, n3).getLowerIndex(), 2);
    46         Assert.assertEquals(WaySegment.forNodePair(w, n1, n4).getLowerIndex(), 4);
    47         Assert.assertEquals(WaySegment.forNodePair(w, n4, n1).getLowerIndex(), 5);
    48         try {
    49             Assert.assertEquals(WaySegment.forNodePair(w, n3, n4).getLowerIndex(), 5);
    50             throw new IllegalStateException("Expecting IllegalArgumentException");
    51         } catch (IllegalArgumentException expected) {
    52             System.out.println("Expected exception: " + expected.getMessage());
    53         }
     46        assertEquals(WaySegment.forNodePair(w, n1, n2).getLowerIndex(), 0);
     47        assertEquals(WaySegment.forNodePair(w, n1, n3).getLowerIndex(), 2);
     48        assertEquals(WaySegment.forNodePair(w, n1, n4).getLowerIndex(), 4);
     49        assertEquals(WaySegment.forNodePair(w, n4, n1).getLowerIndex(), 5);
     50        IllegalArgumentException iae = assertThrows(IllegalArgumentException.class, () -> WaySegment.forNodePair(w, n3, n4));
     51        assertEquals("Node pair is not part of way!", iae.getMessage());
    5452    }
    5553}
Note: See TracChangeset for help on using the changeset viewer.