Changeset 18690 in josm for trunk/test/functional/org


Ignore:
Timestamp:
2023-03-13T21:59:27+01:00 (20 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.

Location:
trunk/test/functional/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/functional/org/openstreetmap/josm/io/MultiFetchServerObjectReaderTest.java

    r18203 r18690  
    1616import java.io.PrintWriter;
    1717import java.nio.charset.StandardCharsets;
     18import java.nio.file.Files;
    1819import java.security.SecureRandom;
    1920import java.text.MessageFormat;
     
    5253 */
    5354@SuppressFBWarnings(value = "CRLF_INJECTION_LOGS")
    54 @Timeout(value = 60, unit = TimeUnit.SECONDS)
     55@Timeout(value = 1, unit = TimeUnit.MINUTES)
    5556class MultiFetchServerObjectReaderTest {
    5657    private static final Logger logger = Logger.getLogger(MultiFetchServerObjectReader.class.getName());
     
    191192        try (
    192193            PrintWriter pw = new PrintWriter(
    193                     new OutputStreamWriter(new FileOutputStream(dataSetCacheOutputFile), StandardCharsets.UTF_8)
     194                    new OutputStreamWriter(Files.newOutputStream(dataSetCacheOutputFile.toPath()), StandardCharsets.UTF_8)
    194195        )) {
    195196            logger.info(MessageFormat.format("caching test data set in ''{0}'' ...", dataSetCacheOutputFile.toString()));
  • trunk/test/functional/org/openstreetmap/josm/tools/HttpClientTest.java

    r18437 r18690  
    240240    void testTooMuchRedirects() throws IOException {
    241241        mockRedirects(false, 3);
    242         assertThrows(IOException.class, () -> HttpClient.create(url("/relative-redirect/3")).setMaxRedirects(2).connect(progress));
     242        final HttpClient client = HttpClient.create(url("/relative-redirect/3")).setMaxRedirects(2);
     243        try {
     244            assertThrows(IOException.class, () -> client.connect(progress));
     245        } finally {
     246            client.disconnect();
     247        }
    243248    }
    244249
     
    370375    void testTakesTooLong() throws IOException {
    371376        mockDelay(1);
    372         assertThrows(IOException.class, () -> HttpClient.create(url("/delay/1")).setReadTimeout(500).connect(progress));
     377        final HttpClient client = HttpClient.create(url("/delay/1")).setReadTimeout(500);
     378        try {
     379            assertThrows(IOException.class, () -> client.connect(progress));
     380        } finally {
     381            client.disconnect();
     382        }
    373383    }
    374384
     
    387397
    388398    /**
    389      * Test of {@link Response#uncompress} method with Gzip compression.
     399     * Test of {@link Response#uncompress(boolean)} method with Gzip compression.
    390400     * @throws IOException if any I/O error occurs
    391401     */
     
    407417
    408418    /**
    409      * Test of {@link Response#uncompress} method with Bzip compression.
     419     * Test of {@link Response#uncompress(boolean)} method with Bzip compression.
    410420     * @throws IOException if any I/O error occurs
    411421     */
     
    427437
    428438    /**
    429      * Test of {@link Response#uncompress} method with Bzip compression.
     439     * Test of {@link Response#uncompress(boolean)} method with Bzip compression.
    430440     * @throws IOException if any I/O error occurs
    431441     */
Note: See TracChangeset for help on using the changeset viewer.