1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.mappaint.mapcss;
|
---|
3 |
|
---|
4 | import org.junit.jupiter.api.extension.RegisterExtension;
|
---|
5 | import org.junit.jupiter.api.Test;
|
---|
6 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
7 |
|
---|
8 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
9 | import net.trajano.commons.testing.UtilityClassTestUtil;
|
---|
10 |
|
---|
11 | import java.lang.reflect.Method;
|
---|
12 | import java.lang.reflect.Modifier;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * Unit tests of {@link ExpressionFactory}.
|
---|
16 | */
|
---|
17 | class ExpressionFactoryTest {
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Setup rule
|
---|
21 | */
|
---|
22 | @RegisterExtension
|
---|
23 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
24 | public JOSMTestRules test = new JOSMTestRules();
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Tests that {@code Functions} satisfies utility class criteria.
|
---|
28 | * @throws ReflectiveOperationException if an error occurs
|
---|
29 | */
|
---|
30 | @Test
|
---|
31 | void testUtilityClass() throws ReflectiveOperationException {
|
---|
32 | UtilityClassTestUtil.assertUtilityClassWellDefined(Functions.class);
|
---|
33 | }
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Tests that all functions have been registered to {@link ExpressionFactory#FACTORY_MAP}
|
---|
37 | *
|
---|
38 | * For instance to register {@link Functions#osm_id}, {@code FACTORY_MAP.put("osm_id", Factory.ofEnv(Functions::osm_id))}
|
---|
39 | */
|
---|
40 | @Test
|
---|
41 | void testNoUnregisteredFunctions() {
|
---|
42 | for (Method m : Functions.class.getDeclaredMethods()) {
|
---|
43 | if (!Modifier.isPrivate(m.getModifiers()) && !ExpressionFactory.FACTORY_MAP.containsKey(m.getName())) {
|
---|
44 | throw new AssertionError(m + " has not registered in ExpressionFactory.FACTORY_MAP");
|
---|
45 | }
|
---|
46 | }
|
---|
47 | }
|
---|
48 | }
|
---|