source: josm/trunk/test/unit/org/openstreetmap/josm/gui/preferences/validator/ValidatorTagCheckerRulesPreferenceTestIT.java

Last change on this file was 18893, checked in by taylor.smock, 6 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: 3.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.preferences.validator;
3
4import static org.junit.jupiter.api.Assertions.assertFalse;
5import static org.junit.jupiter.api.Assertions.assertTrue;
6import static org.junit.jupiter.api.Assumptions.assumeFalse;
7import static org.junit.jupiter.api.Assumptions.assumeTrue;
8
9import java.io.IOException;
10import java.util.ArrayList;
11import java.util.HashSet;
12import java.util.List;
13import java.util.Set;
14
15import org.junit.jupiter.api.BeforeAll;
16import org.junit.jupiter.api.Timeout;
17import org.junit.jupiter.api.parallel.Execution;
18import org.junit.jupiter.api.parallel.ExecutionMode;
19import org.junit.jupiter.params.ParameterizedTest;
20import org.junit.jupiter.params.provider.MethodSource;
21import org.openstreetmap.josm.TestUtils;
22import org.openstreetmap.josm.data.preferences.sources.ExtendedSourceEntry;
23import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker;
24import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.ParseResult;
25import org.openstreetmap.josm.gui.preferences.AbstractExtendedSourceEntryTestCase;
26import org.openstreetmap.josm.testutils.annotations.HTTPS;
27
28/**
29 * Integration tests of {@link ValidatorTagCheckerRulesPreference} class.
30 */
31@HTTPS
32@Timeout(20)
33class ValidatorTagCheckerRulesPreferenceTestIT extends AbstractExtendedSourceEntryTestCase {
34 /**
35 * Setup test
36 * @throws IOException in case of I/O error
37 */
38 @BeforeAll
39 public static void beforeClass() throws IOException {
40 errorsToIgnore.addAll(TestUtils.getIgnoredErrorMessages(ValidatorTagCheckerRulesPreferenceTestIT.class));
41 }
42
43 /**
44 * Returns list of entries to test.
45 * @return list of entries to test
46 * @throws Exception in case of error
47 */
48 public static List<Object[]> data() throws Exception {
49 return getTestParameters(new ValidatorTagCheckerRulesPreference.TagCheckerRulesSourceEditor()
50 .loadAndGetAvailableSources());
51 }
52
53 /**
54 * Test that available tag checker rule is valid.
55 * @param displayName displayed name
56 * @param url URL
57 * @param source source entry to test
58 * @throws Exception in case of error
59 */
60 @Execution(ExecutionMode.CONCURRENT)
61 @ParameterizedTest(name = "{0} - {1}")
62 @MethodSource("data")
63 void testValidityOfAvailableRule(String displayName, String url, ExtendedSourceEntry source) throws Exception {
64 assumeFalse(isIgnoredSubstring(source, source.url));
65 List<String> ignoredErrors = new ArrayList<>();
66 Set<String> errors = new HashSet<>();
67 System.out.print(source.url);
68 try {
69 ParseResult result = new MapCSSTagChecker().addMapCSS(source.url);
70 assertFalse(result.parseChecks.isEmpty(), result::toString);
71 System.out.println(result.parseErrors.isEmpty() ? " => OK" : " => KO");
72 result.parseErrors.forEach(e -> handleException(source, e, errors, ignoredErrors));
73 } catch (IOException e) {
74 System.out.println(" => KO");
75 e.printStackTrace();
76 handleException(source, e, errors, ignoredErrors);
77 }
78 // #16567 - Shouldn't be necessary to print displayName if Ant worked properly
79 // See https://josm.openstreetmap.de/ticket/16567#comment:53
80 // See https://bz.apache.org/bugzilla/show_bug.cgi?id=64564
81 // See https://github.com/apache/ant/pull/121
82 assertTrue(errors.isEmpty(), displayName + " => " + errors);
83 assumeTrue(ignoredErrors.isEmpty(), ignoredErrors.toString());
84 }
85}
Note: See TracBrowser for help on using the repository browser.