Changeset 16727 in josm for trunk


Ignore:
Timestamp:
2020-06-28T19:08:21+02:00 (4 years ago)
Author:
simon04
Message:

fix #16567 - Fix ImageryPreferenceTestIT for JUnit 5 (patch by taylor.smock)

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/ivy.xml

    r16617 r16727  
    6161        <dependency conf="test->default" org="org.junit.platform" name="junit-platform-launcher" rev="1.6.2"/>
    6262        <dependency conf="test->default" org="org.junit.vintage" name="junit-vintage-engine" rev="5.6.2"/>
     63        <dependency conf="test->default" org="org.junit.jupiter" name="junit-jupiter-params" rev="5.6.2"/>
    6364        <dependency conf="test->default" org="org.junit.jupiter" name="junit-jupiter-api" rev="5.6.2"/>
    6465        <dependency conf="test->default" org="org.junit.jupiter" name="junit-jupiter-engine" rev="5.6.2"/>
  • trunk/test/unit/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreferenceTestIT.java

    r16643 r16727  
    22package org.openstreetmap.josm.gui.preferences.imagery;
    33
    4 import static org.junit.Assert.assertFalse;
    5 import static org.junit.Assert.assertTrue;
    6 import static org.junit.Assume.assumeTrue;
     4import static org.junit.jupiter.api.Assertions.assertFalse;
     5import static org.junit.jupiter.api.Assertions.assertTrue;
     6import static org.junit.jupiter.api.Assumptions.assumeTrue;
    77
    88import java.io.ByteArrayInputStream;
     
    1515import java.util.Locale;
    1616import java.util.Map;
    17 import java.util.Objects;
    1817import java.util.Optional;
    1918import java.util.TreeMap;
     
    2524
    2625import org.apache.commons.jcs3.access.CacheAccess;
    27 import org.junit.AfterClass;
    28 import org.junit.BeforeClass;
    29 import org.junit.ClassRule;
    30 import org.junit.Test;
    31 import org.junit.runner.RunWith;
    32 import org.junit.runners.Parameterized.Parameters;
     26import org.junit.jupiter.api.AfterAll;
     27import org.junit.jupiter.api.BeforeAll;
     28import org.junit.jupiter.api.extension.RegisterExtension;
     29import org.junit.jupiter.params.ParameterizedTest;
     30import org.junit.jupiter.params.provider.Arguments;
     31import org.junit.jupiter.params.provider.MethodSource;
    3332import org.openstreetmap.gui.jmapviewer.Coordinate;
    3433import org.openstreetmap.gui.jmapviewer.FeatureAdapter;
     
    6261import org.openstreetmap.josm.io.imagery.WMSImagery.WMSGetCapabilitiesException;
    6362import org.openstreetmap.josm.testutils.JOSMTestRules;
    64 import org.openstreetmap.josm.testutils.ParallelParameterized;
    6563import org.openstreetmap.josm.tools.HttpClient;
    6664import org.openstreetmap.josm.tools.HttpClient.Response;
     
    7371 * Integration tests of {@link ImageryPreference} class.
    7472 */
    75 @RunWith(ParallelParameterized.class)
    7673public class ImageryPreferenceTestIT {
    7774
     
    8380     * Setup rule
    8481     */
    85     @ClassRule
     82    @RegisterExtension
    8683    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    87     public static JOSMTestRules test = new JOSMTestRules().https().i18n().preferences().projection().projectionNadGrids()
    88                                                    .timeout((int) TimeUnit.MINUTES.toMillis(40)).parameters();
     84    static JOSMTestRules test = new JOSMTestRules().https().i18n().preferences().projection().projectionNadGrids()
     85                                                   .timeout((int) TimeUnit.MINUTES.toMillis(40));
    8986
    9087    /** Entry to test */
    91     private final ImageryInfo info;
    9288    private final Map<String, Map<ImageryInfo, List<String>>> errors = Collections.synchronizedMap(new TreeMap<>());
    9389    private final Map<String, Map<ImageryInfo, List<String>>> ignoredErrors = Collections.synchronizedMap(new TreeMap<>());
     
    10298     * @throws IOException in case of I/O error
    10399     */
    104     @BeforeClass
     100    @BeforeAll
    105101    public static void beforeClass() throws IOException {
    106102        FeatureAdapter.registerApiKeyAdapter(ApiKeyProvider::retrieveApiKey);
     
    113109     * Cleanup test
    114110     */
    115     @AfterClass
     111    @AfterAll
    116112    public static void afterClass() {
    117113        for (String e : notIgnoredErrors) {
     
    124120     * @return list of imagery entries to test
    125121     */
    126     @Parameters(name = "{0}")
    127     public static List<Object[]> data() {
     122    public static List<Arguments> data() {
    128123        ImageryLayerInfo.instance.load(false);
    129124        return ImageryLayerInfo.instance.getDefaultLayers()
    130125                .stream()
    131                 .map(x -> new Object[] {x.getId(), x})
     126                .map(i -> Arguments.of(i.getId(), i))
    132127                .collect(Collectors.toList());
    133     }
    134 
    135     /**
    136      * Constructs a new {@code ImageryPreferenceTestIT} instance.
    137      * @param id entry ID, used only to name tests
    138      * @param info entry to test
    139      */
    140     public ImageryPreferenceTestIT(String id, ImageryInfo info) {
    141         this.info = Objects.requireNonNull(info);
    142128    }
    143129
     
    405391    /**
    406392     * Test that available imagery entry is valid.
     393     *
     394     * @param id The id of the imagery info to show as the test name
     395     * @param info The imagery info to test
    407396     */
    408     @Test
    409     public void testImageryEntryValidity() {
     397    @ParameterizedTest(name = "{0}")
     398    @MethodSource("data")
     399    public void testImageryEntryValidity(String id, ImageryInfo info) {
    410400        checkEntry(info);
    411         assertTrue(format(errors), errors.isEmpty());
     401        assertTrue(errors.isEmpty(), format(errors));
    412402        assertFalse(workingURLs.isEmpty());
    413         assumeTrue(format(ignoredErrors), ignoredErrors.isEmpty());
     403        assumeTrue(ignoredErrors.isEmpty(), format(ignoredErrors));
    414404    }
    415405}
  • trunk/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java

    r16658 r16727  
    2424
    2525import org.awaitility.Awaitility;
     26import org.junit.jupiter.api.extension.AfterAllCallback;
    2627import org.junit.jupiter.api.extension.AfterEachCallback;
     28import org.junit.jupiter.api.extension.BeforeAllCallback;
    2729import org.junit.jupiter.api.extension.BeforeEachCallback;
    2830import org.junit.jupiter.api.extension.ExtensionContext;
     
    8284 * @author Michael Zangl
    8385 */
    84 public class JOSMTestRules implements TestRule, AfterEachCallback, BeforeEachCallback {
     86public class JOSMTestRules implements TestRule, AfterEachCallback, BeforeEachCallback, AfterAllCallback, BeforeAllCallback {
    8587    private int timeout = isDebugMode() ? -1 : 10 * 1000;
    8688    private TemporaryFolder josmHome;
     
    465467    }
    466468
     469    @Override
     470    public void beforeAll(ExtensionContext context) throws Exception {
     471        beforeEach(context);
     472    }
     473
     474    @Override
     475    public void afterAll(ExtensionContext context) throws Exception {
     476        afterEach(context);
     477    }
     478
    467479    /**
    468480     * Set up before running a test
Note: See TracChangeset for help on using the changeset viewer.