Changeset 14605 in josm for trunk/test


Ignore:
Timestamp:
2018-12-27T21:06:59+01:00 (6 years ago)
Author:
Don-vip
Message:

see #16073 - convert single global test to one test per imagery entry

Slower, but this improves readbility and allows to focus on entries failing for several consecutive tries.

Location:
trunk/test/unit/org/openstreetmap/josm
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreferenceTestIT.java

    r14603 r14605  
    1414import java.util.Locale;
    1515import java.util.Map;
     16import java.util.Objects;
    1617import java.util.Optional;
    1718import java.util.TreeMap;
    1819import java.util.concurrent.TimeUnit;
     20import java.util.stream.Collectors;
    1921
    2022import javax.imageio.ImageIO;
    2123
    2224import org.apache.commons.jcs.access.CacheAccess;
    23 import org.junit.Before;
    24 import org.junit.Rule;
     25import org.junit.BeforeClass;
     26import org.junit.ClassRule;
    2527import org.junit.Test;
     28import org.junit.runner.Description;
     29import org.junit.runner.RunWith;
     30import org.junit.runners.Parameterized.Parameters;
     31import org.junit.runners.model.Statement;
    2632import org.openstreetmap.gui.jmapviewer.Coordinate;
    2733import org.openstreetmap.gui.jmapviewer.TileXY;
     
    5359import org.openstreetmap.josm.io.imagery.WMSImagery.WMSGetCapabilitiesException;
    5460import org.openstreetmap.josm.testutils.JOSMTestRules;
     61import org.openstreetmap.josm.testutils.ParallelParameterized;
    5562import org.openstreetmap.josm.tools.HttpClient;
    5663import org.openstreetmap.josm.tools.HttpClient.Response;
     
    6370 * Integration tests of {@link ImageryPreference} class.
    6471 */
     72@RunWith(ParallelParameterized.class)
    6573public class ImageryPreferenceTestIT {
    6674
     
    7179     * Setup rule
    7280     */
    73     @Rule
     81    @ClassRule
    7482    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    75     public JOSMTestRules test = new JOSMTestRules().https().preferences().projection().projectionNadGrids()
     83    public static JOSMTestRules test = new JOSMTestRules().https().preferences().projection().projectionNadGrids()
    7684                                                   .timeout((int) TimeUnit.MINUTES.toMillis(40));
    7785
     86    static {
     87        try {
     88            test.apply(new Statement() {
     89                @Override
     90                public void evaluate() throws Throwable {
     91                    // Do nothing. Hack needed because @Parameters are computed before anything else
     92                }
     93            }, Description.createSuiteDescription(ImageryPreferenceTestIT.class)).evaluate();
     94        } catch (Throwable e) {
     95            Logging.error(e);
     96        }
     97    }
     98
     99    /** Entry to test */
     100    private final ImageryInfo info;
    78101    private final Map<String, Map<ImageryInfo, List<String>>> errors = Collections.synchronizedMap(new TreeMap<>());
    79     private final Map<String, byte[]> workingURLs = Collections.synchronizedMap(new TreeMap<>());
    80 
    81     private TMSCachedTileLoaderJob helper;
    82     private List<String> ignoredErrors;
     102    private static final Map<String, byte[]> workingURLs = Collections.synchronizedMap(new TreeMap<>());
     103
     104    private static TMSCachedTileLoaderJob helper;
     105    private static List<String> ignoredErrors;
    83106
    84107    /**
     
    86109     * @throws IOException in case of I/O error
    87110     */
    88     @Before
    89     public void before() throws IOException {
     111    @BeforeClass
     112    public static void beforeClass() throws IOException {
    90113        helper = new TMSCachedTileLoaderJob(null, null, new CacheAccess<>(null), new TileJobOptions(0, 0, null, 0), null);
    91114        ignoredErrors = TestUtils.getIgnoredErrorMessages(ImageryPreferenceTestIT.class);
     115    }
     116
     117    /**
     118     * Returns list of imagery entries to test.
     119     * @return list of imagery entries to test
     120     */
     121    @Parameters(name = "{0}")
     122    public static List<Object[]> data() {
     123        ImageryLayerInfo.instance.load(false);
     124        return ImageryLayerInfo.instance.getDefaultLayers()
     125                .stream().map(x -> new Object[] {x.getId(), x})
     126                .collect(Collectors.toList());
     127    }
     128
     129    /**
     130     * Constructs a new {@code ImageryPreferenceTestIT} instance.
     131     * @param id entry ID, used only to name tests
     132     * @param info entry to test
     133     */
     134    public ImageryPreferenceTestIT(String id, ImageryInfo info) {
     135        this.info = Objects.requireNonNull(info);
    92136    }
    93137
     
    336380
    337381    /**
    338      * Test that available imagery entries are valid.
    339      * @throws Exception in case of error
     382     * Test that available imagery entry is valid.
    340383     */
    341384    @Test
    342     public void testValidityOfAvailableImageryEntries() throws Exception {
    343         ImageryLayerInfo.instance.load(false);
    344         ImageryLayerInfo.instance.getDefaultLayers().parallelStream().forEach(this::checkEntry);
     385    public void testValidityOfAvailableImageryEntry() {
     386        checkEntry(info);
    345387        assertTrue(errors.toString().replaceAll("\\}, ", "\n\\}, ").replaceAll(", ImageryInfo\\{", "\n      ,ImageryInfo\\{"),
    346388                errors.isEmpty());
Note: See TracChangeset for help on using the changeset viewer.