Ignore:
Timestamp:
2023-03-13T21:59:27+01:00 (13 months 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/validation/routines/EmailValidatorTest.java

    r17374 r18690  
    1717package org.openstreetmap.josm.data.validation.routines;
    1818
    19 import static org.junit.Assert.assertEquals;
    20 import static org.junit.Assert.assertFalse;
    21 import static org.junit.Assert.assertTrue;
     19import static org.junit.jupiter.api.Assertions.assertEquals;
     20import static org.junit.jupiter.api.Assertions.assertFalse;
     21import static org.junit.jupiter.api.Assertions.assertTrue;
    2222
    2323import org.junit.jupiter.api.BeforeEach;
     
    172172            return; // Cannot run the test
    173173        }
    174         assertTrue("xn--d1abbgf6aiiy.xn--p1ai should validate", validator.isValid("someone@xn--d1abbgf6aiiy.xn--p1ai"));
    175         assertTrue("президент.рф should validate", validator.isValid("someone@президент.рф"));
    176         assertTrue("www.b\u00fccher.ch should validate", validator.isValid("someone@www.b\u00fccher.ch"));
    177         assertFalse("www.\uFFFD.ch FFFD should fail", validator.isValid("someone@www.\uFFFD.ch"));
    178         assertTrue("www.b\u00fccher.ch should validate", validator.isValid("someone@www.b\u00fccher.ch"));
    179         assertFalse("www.\uFFFD.ch FFFD should fail", validator.isValid("someone@www.\uFFFD.ch"));
     174        assertTrue(validator.isValid("someone@xn--d1abbgf6aiiy.xn--p1ai"), "xn--d1abbgf6aiiy.xn--p1ai should validate");
     175        assertTrue(validator.isValid("someone@президент.рф"), "президент.рф should validate");
     176        assertTrue(validator.isValid("someone@www.b\u00fccher.ch"), "www.b\u00fccher.ch should validate");
     177        assertFalse(validator.isValid("someone@www.\uFFFD.ch"), "www.\uFFFD.ch FFFD should fail");
     178        assertTrue(validator.isValid("someone@www.b\u00fccher.ch"), "www.b\u00fccher.ch should validate");
     179        assertFalse(validator.isValid("someone@www.\uFFFD.ch"), "www.\uFFFD.ch FFFD should fail");
    180180    }
    181181
     
    217217    void testEmailWithControlChars() {
    218218        for (char c = 0; c < 32; c++) {
    219             assertFalse("Test control char " + ((int) c), validator.isValid("foo" + c + "bar@domain.com"));
     219            assertFalse(validator.isValid("foo" + c + "bar@domain.com"), "Test control char " + ((int) c));
    220220        }
    221         assertFalse("Test control char 127", validator.isValid("foo" + ((char) 127) + "bar@domain.com"));
     221        assertFalse(validator.isValid("foo" + ((char) 127) + "bar@domain.com"), "Test control char 127");
    222222    }
    223223
     
    234234
    235235       // Depends on the validator
    236        assertTrue(
    237              "@localhost.localdomain should be accepted but wasn't",
    238              allowLocal.isValid("joe@localhost.localdomain")
    239        );
    240        assertTrue(
    241              "@localhost should be accepted but wasn't",
    242              allowLocal.isValid("joe@localhost")
    243        );
    244 
    245        assertFalse(
    246              "@localhost.localdomain should be accepted but wasn't",
    247              noLocal.isValid("joe@localhost.localdomain")
    248        );
    249        assertFalse(
    250              "@localhost should be accepted but wasn't",
    251              noLocal.isValid("joe@localhost")
    252        );
     236       assertTrue(allowLocal.isValid("joe@localhost.localdomain"), "@localhost.localdomain should be accepted but wasn't");
     237       assertTrue(allowLocal.isValid("joe@localhost"), "@localhost should be accepted but wasn't");
     238
     239       assertFalse(noLocal.isValid("joe@localhost.localdomain"), "@localhost.localdomain should be accepted but wasn't");
     240       assertFalse(noLocal.isValid("joe@localhost"), "@localhost should be accepted but wasn't");
    253241    }
    254242
     
    259247    @Test
    260248    void testEmailWithSlashes() {
    261        assertTrue(
    262              "/ and ! valid in username",
    263              validator.isValid("joe!/blow@apache.org")
    264        );
    265        assertFalse(
    266              "/ not valid in domain",
    267              validator.isValid("joe@ap/ache.org")
    268        );
    269        assertFalse(
    270              "! not valid in domain",
    271              validator.isValid("joe@apac!he.org")
    272        );
     249       assertTrue(validator.isValid("joe!/blow@apache.org"), "/ and ! valid in username");
     250       assertFalse(validator.isValid("joe@ap/ache.org"), "/ not valid in domain");
     251       assertFalse(validator.isValid("joe@apac!he.org"), "! not valid in domain");
    273252    }
    274253
     
    496475            String item = resultPair.item;
    497476            if (resultPair.valid) {
    498                 assertTrue("Should be OK: " + item, validator.isValid(item));
     477                assertTrue(validator.isValid(item), "Should be OK: " + item);
    499478            } else {
    500                 assertFalse("Should fail: " + item, validator.isValid(item));
     479                assertFalse(validator.isValid(item), "Should fail: " + item);
    501480            }
    502481        }
Note: See TracChangeset for help on using the changeset viewer.