Ticket #16567: 16567.imageryit.patch

File 16567.imageryit.patch, 8.3 KB (added by taylor.smock, 6 years ago)

Implement AfterAllCallback and BeforeAllCallback for instances where there is a static JOSMTestRules, modify ImageryPreferenceTestIT to be a full JUnit5 test, add junit-jupiter-params as an Ivy dependency

  • ivy.xml

     
    6060        <dependency conf="test->default" org="io.github.classgraph" name="classgraph" rev="4.8.67"/>
    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"/>
    6566        <dependency conf="test->default" org="org.junit.jupiter" name="junit-jupiter-migrationsupport" rev="5.6.2"/>
  • test/unit/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreferenceTestIT.java

     
    11// License: GPL. For details, see LICENSE file.
    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;
    99import java.io.IOException;
     
    1414import java.util.List;
    1515import java.util.Locale;
    1616import java.util.Map;
    17 import java.util.Objects;
    1817import java.util.Optional;
    1918import java.util.TreeMap;
    2019import java.util.concurrent.TimeUnit;
     
    2423import javax.imageio.ImageIO;
    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;
    3534import org.openstreetmap.gui.jmapviewer.TileXY;
     
    6160import org.openstreetmap.josm.io.imagery.ApiKeyProvider;
    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;
    6765import org.openstreetmap.josm.tools.Logging;
     
    7270/**
    7371 * Integration tests of {@link ImageryPreference} class.
    7472 */
    75 @RunWith(ParallelParameterized.class)
    7673public class ImageryPreferenceTestIT {
    7774
    7875    private static final String ERROR_SEP = " -> ";
     
    8279    /**
    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<>());
    9490    private static final Map<String, byte[]> workingURLs = Collections.synchronizedMap(new TreeMap<>());
     
    10197     * Setup test
    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);
    107103        helper = new TMSCachedTileLoaderJob(null, null, new CacheAccess<>(null), new TileJobOptions(0, 0, null, 0), null);
     
    112108    /**
    113109     * Cleanup test
    114110     */
    115     @AfterClass
     111    @AfterAll
    116112    public static void afterClass() {
    117113        for (String e : notIgnoredErrors) {
    118114            Logging.warn("Ignore line unused: " + e);
     
    123119     * Returns list of imagery entries to test.
    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()
    130                 .stream()
    131                 .map(x -> new Object[] {x.getId(), x})
    132                 .collect(Collectors.toList());
     125                .stream().map(i -> Arguments.of(i.getId(), i)).collect(Collectors.toList());
    133126    }
    134127
    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);
    142     }
    143 
    144128    private boolean addError(ImageryInfo info, String error) {
    145129        String errorMsg = error.replace('\n', ' ');
    146130        if (notIgnoredErrors.contains(errorMsg))
     
    404388
    405389    /**
    406390     * Test that available imagery entry is valid.
     391     *
     392     * @param id The id of the imagery info to show as the test name
     393     * @param info The imagery info to test
    407394     */
    408     @Test
    409     public void testImageryEntryValidity() {
     395    @ParameterizedTest(name = "{0}")
     396    @MethodSource("data")
     397    public void testImageryEntryValidity(String id, ImageryInfo info) {
    410398        checkEntry(info);
    411         assertTrue(format(errors), errors.isEmpty());
     399        assertTrue(errors.isEmpty(), format(errors));
    412400        assertFalse(workingURLs.isEmpty());
    413         assumeTrue(format(ignoredErrors), ignoredErrors.isEmpty());
     401        assumeTrue(ignoredErrors.isEmpty(), format(ignoredErrors));
    414402    }
    415403}
  • test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java

     
    2323import java.util.logging.Handler;
    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;
    2931import org.junit.rules.TemporaryFolder;
     
    8183 *
    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;
    8789    private boolean usePreferences = false;
     
    464466        after();
    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
    469481     * @throws InitializationError If an error occurred while creating the required environment.