source: josm/trunk/test/unit/org/openstreetmap/josm/gui/preferences/map/MapPaintPreferenceTestIT.java@ 18893

Last change on this file since 18893 was 18893, checked in by taylor.smock, 8 months ago

Fix #16567: Upgrade to JUnit 5

JOSMTestRules and JOSMTestFixture can reset the default JOSM profile, which can
be unexpected for new contributors. This updates all tests to use JUnit 5 and
the new JUnit 5 annotations.

This also renames MapCSSStyleSourceFilterTest to MapCSSStyleSourceFilterPerformanceTest
to match the naming convention for performance tests and fixes some lint issues.

This was tested by running all tests individually and together.

  • Property svn:eol-style set to native
File size: 4.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.preferences.map;
3
4import static org.junit.jupiter.api.Assertions.assertTrue;
5import static org.junit.jupiter.api.Assumptions.assumeFalse;
6import static org.junit.jupiter.api.Assumptions.assumeTrue;
7
8import java.io.IOException;
9import java.util.ArrayList;
10import java.util.List;
11import java.util.concurrent.TimeUnit;
12
13import org.junit.jupiter.api.BeforeAll;
14import org.junit.jupiter.api.Timeout;
15import org.junit.jupiter.params.ParameterizedTest;
16import org.junit.jupiter.params.provider.MethodSource;
17import org.openstreetmap.josm.TestUtils;
18import org.openstreetmap.josm.data.preferences.sources.ExtendedSourceEntry;
19import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
20import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference;
21import org.openstreetmap.josm.gui.mappaint.StyleKeys;
22import org.openstreetmap.josm.gui.mappaint.StyleSource;
23import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction;
24import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction.AssignmentInstruction;
25import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSRule;
26import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
27import org.openstreetmap.josm.gui.preferences.AbstractExtendedSourceEntryTestCase;
28import org.openstreetmap.josm.testutils.annotations.HTTPS;
29import org.openstreetmap.josm.tools.ImageProvider;
30
31/**
32 * Integration tests of {@link MapPaintPreference} class.
33 */
34@HTTPS
35@Timeout(value = 15, unit = TimeUnit.MINUTES)
36class MapPaintPreferenceTestIT extends AbstractExtendedSourceEntryTestCase {
37 /**
38 * Setup test
39 * @throws IOException in case of I/O error
40 */
41 @BeforeAll
42 public static void beforeClass() throws IOException {
43 errorsToIgnore.addAll(TestUtils.getIgnoredErrorMessages(MapPaintPreferenceTestIT.class));
44 }
45
46 /**
47 * Returns list of map paint styles to test.
48 * @return list of map paint styles to test
49 * @throws Exception if an error occurs
50 */
51 public static List<Object[]> data() throws Exception {
52 ImageProvider.clearCache();
53 return getTestParameters(new MapPaintPreference.MapPaintSourceEditor().loadAndGetAvailableSources());
54 }
55
56 /**
57 * Test that map paint style is valid.
58 * @param displayName displayed name
59 * @param url URL
60 * @param source source entry to test
61 */
62 @ParameterizedTest(name = "{0} - {1}")
63 @MethodSource("data")
64 void testStyleValidity(String displayName, String url, ExtendedSourceEntry source) {
65 assumeFalse(isIgnoredSubstring(source, source.url));
66 StyleSource style = MapPaintStyles.addStyle(source);
67 if (style instanceof MapCSSStyleSource) {
68 // Force loading of all icons to detect missing ones
69 for (MapCSSRule rule : ((MapCSSStyleSource) style).rules) {
70 for (Instruction instruction : rule.declaration.instructions) {
71 if (instruction instanceof AssignmentInstruction) {
72 AssignmentInstruction ai = (AssignmentInstruction) instruction;
73 if (StyleKeys.ICON_IMAGE.equals(ai.key)
74 || StyleKeys.FILL_IMAGE.equals(ai.key)
75 || StyleKeys.REPEAT_IMAGE.equals(ai.key)) {
76 if (ai.val instanceof String) {
77 MapPaintStyles.getIconProvider(new IconReference((String) ai.val, style), true);
78 }
79 }
80 }
81 }
82 }
83 }
84
85 List<String> ignoredErrors = new ArrayList<>();
86 List<Throwable> errors = new ArrayList<>(style.getErrors());
87 errors.stream().map(Throwable::getMessage).filter(s -> isIgnoredSubstring(source, s)).forEach(ignoredErrors::add);
88 errors.removeIf(e -> ignoredErrors.contains(e.getMessage()));
89
90 List<String> warnings = new ArrayList<>(style.getWarnings());
91 warnings.stream().filter(s -> isIgnoredSubstring(source, s)).forEach(ignoredErrors::add);
92 warnings.removeAll(ignoredErrors);
93
94 // #16567 - Shouldn't be necessary to print displayName if Ant worked properly
95 // See https://josm.openstreetmap.de/ticket/16567#comment:53
96 // See https://bz.apache.org/bugzilla/show_bug.cgi?id=64564
97 // See https://github.com/apache/ant/pull/121
98 assertTrue(errors.isEmpty() && warnings.isEmpty(), displayName + " => " + errors + '\n' + warnings);
99 assumeTrue(ignoredErrors.isEmpty(), ignoredErrors.toString());
100 }
101}
Note: See TracBrowser for help on using the repository browser.