1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.math4.core.jdkmath;
18
19 import java.util.List;
20 import java.util.ArrayList;
21 import java.lang.reflect.Method;
22 import java.lang.reflect.Modifier;
23 import java.lang.reflect.Type;
24
25 import org.junit.Test;
26 import org.junit.Assert;
27
28
29
30
31 public class JdkMathTest {
32
33 private static final String LINE_SEP = System.lineSeparator();
34
35
36
37
38
39
40
41 @Test
42 public void checkMissingMethods() {
43 final String runtimeVersion = System.getProperty("java.runtime.version");
44 final boolean doTest = runtimeVersion.matches("^1\\.8\\..*");
45 org.junit.Assume.assumeTrue(doTest);
46
47 final List<String> notFound = compareClassMethods(StrictMath.class,
48 JdkMath.class);
49 if (!notFound.isEmpty()) {
50 final StringBuilder sb = new StringBuilder();
51 sb.append("JdkMath is missing the following StrictMath methods:");
52 for (String m : notFound) {
53 sb.append(LINE_SEP).append(m);
54 }
55 Assert.fail(sb.toString());
56 }
57 }
58
59
60
61
62
63
64 private List<String> compareClassMethods(Class<?> class1,
65 Class<?> class2) {
66 final List<String> notFound = new ArrayList<>();
67 for (Method method1 : class1.getDeclaredMethods()) {
68 if (Modifier.isPublic(method1.getModifiers())) {
69 final Type[] params = method1.getGenericParameterTypes();
70 try {
71 class2.getDeclaredMethod(method1.getName(), (Class[]) params);
72 } catch (NoSuchMethodException e) {
73 notFound.add(method1.toString());
74 }
75 }
76 }
77
78 return notFound;
79 }
80 }