source: josm/trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/ConditionFactoryTest.java@ 18037

Last change on this file since 18037 was 18037, checked in by Don-vip, 3 years ago

fix #21064 - Add JUnit 5 extension for preferences (patch by taylor.smock)

  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.mappaint.mapcss;
3
4import static org.junit.jupiter.api.Assertions.assertThrows;
5
6import org.junit.jupiter.api.Test;
7import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.Context;
8import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.Op;
9import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.PseudoClasses;
10import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
11
12import net.trajano.commons.testing.UtilityClassTestUtil;
13
14import java.lang.reflect.Method;
15import java.lang.reflect.Modifier;
16
17/**
18 * Unit tests of {@link ConditionFactory}.
19 */
20@BasicPreferences
21class ConditionFactoryTest {
22 /**
23 * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/14368">#14368</a>.
24 */
25 @Test
26 void testTicket14368() {
27 assertThrows(MapCSSException.class,
28 () -> ConditionFactory.createKeyValueCondition("name", "Rodovia ([A-Z]{2,3}-[0-9]{2,4}", Op.REGEX, Context.PRIMITIVE, false));
29 }
30
31 /**
32 * Tests that {@code PseudoClasses} satisfies utility class criteria.
33 * @throws ReflectiveOperationException if an error occurs
34 */
35 @Test
36 void testUtilityClass() throws ReflectiveOperationException {
37 UtilityClassTestUtil.assertUtilityClassWellDefined(PseudoClasses.class);
38 }
39
40 /**
41 * Tests that all functions have been registered to {@link ConditionFactory.PseudoClassCondition#CONDITION_MAP}
42 */
43 @Test
44 void testAllPseudoClassesRegistered() {
45 for (Method method : PseudoClasses.class.getDeclaredMethods()) {
46 if (!Modifier.isPublic(method.getModifiers()) || method.toString().contains("$jacocoInit")) {
47 return;
48 }
49 String name = method.getName().replaceFirst("^_new$", "new");
50 Context context = name.equals("sameTags") ? Context.LINK : Context.PRIMITIVE;
51 ConditionFactory.PseudoClassCondition.createPseudoClassCondition(name, false, context);
52 ConditionFactory.PseudoClassCondition.createPseudoClassCondition(name, true, context);
53 }
54 }
55}
Note: See TracBrowser for help on using the repository browser.