1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.mappaint.mapcss;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
---|
5 |
|
---|
6 | import org.junit.jupiter.api.Test;
|
---|
7 | import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.Context;
|
---|
8 | import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.Op;
|
---|
9 | import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.PseudoClasses;
|
---|
10 | import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
|
---|
11 |
|
---|
12 | import net.trajano.commons.testing.UtilityClassTestUtil;
|
---|
13 |
|
---|
14 | import java.lang.reflect.Method;
|
---|
15 | import java.lang.reflect.Modifier;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Unit tests of {@link ConditionFactory}.
|
---|
19 | */
|
---|
20 | @BasicPreferences
|
---|
21 | class 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 | }
|
---|