Commits
Wesley Wolfe authored 9869166c2ee
1 1 | package org.bukkit; |
2 2 | |
3 + | import static org.hamcrest.Matchers.*; |
3 4 | import static org.junit.Assert.*; |
4 5 | |
5 6 | import java.lang.reflect.Method; |
6 7 | import java.lang.reflect.Modifier; |
8 + | import java.util.Arrays; |
9 + | import java.util.List; |
7 10 | |
11 + | import org.junit.Before; |
8 12 | import org.junit.Test; |
13 + | import org.junit.runner.RunWith; |
14 + | import org.junit.runners.Parameterized; |
15 + | import org.junit.runners.Parameterized.Parameter; |
16 + | import org.junit.runners.Parameterized.Parameters; |
9 17 | |
18 + | import com.google.common.base.Function; |
19 + | import com.google.common.collect.Lists; |
20 + | |
21 + | Parameterized.class) | (
10 22 | public class BukkitMirrorTest { |
23 + | |
24 + | name="{index}: {1}") | (
25 + | public static List<Object[]> data() { |
26 + | return Lists.transform(Arrays.asList(Server.class.getDeclaredMethods()), new Function<Method, Object[]>() { |
27 + | |
28 + | public Object[] apply(Method input) { |
29 + | return new Object[] { |
30 + | input, |
31 + | input.toGenericString().substring("public abstract ".length()).replace("(", "{").replace(")", "}") |
32 + | }; |
33 + | } |
34 + | }); |
35 + | } |
36 + | |
37 + | 0) | (
38 + | public Method server; |
39 + | |
40 + | 1) | (
41 + | public String name; |
42 + | |
43 + | private Method bukkit; |
44 + | |
45 + | |
46 + | public void makeBukkit() throws Throwable { |
47 + | bukkit = Bukkit.class.getDeclaredMethod(server.getName(), server.getParameterTypes()); |
48 + | } |
49 + | |
50 + | |
51 + | public void isStatic() throws Throwable { |
52 + | assertThat(Modifier.isStatic(bukkit.getModifiers()), is(true)); |
53 + | } |
54 + | |
55 + | |
56 + | public void isDeprecated() throws Throwable { |
57 + | assertThat(bukkit.isAnnotationPresent(Deprecated.class), is(server.isAnnotationPresent(Deprecated.class))); |
58 + | } |
59 + | |
60 + | |
61 + | public void returnType() throws Throwable { |
62 + | assertThat(bukkit.getReturnType(), is((Object) server.getReturnType())); |
63 + | assertThat(bukkit.getGenericReturnType(), is(server.getGenericReturnType())); |
64 + | } |
65 + | |
66 + | |
67 + | public void parameterTypes() throws Throwable { |
68 + | assertThat(bukkit.getGenericParameterTypes(), is(server.getGenericParameterTypes())); |
69 + | } |
70 + | |
11 71 | |
12 - | public final void test() throws NoSuchMethodException { |
13 - | Method[] serverMethods = Server.class.getDeclaredMethods(); |
14 - | for(Method method : serverMethods) { |
15 - | Method mirrorMethod = Bukkit.class.getDeclaredMethod(method.getName(), method.getParameterTypes()); |
16 - | assertTrue("Bukkit." + method.getName() + " must be static!", Modifier.isStatic(mirrorMethod.getModifiers())); |
17 - | } |
72 + | public void declaredException() throws Throwable { |
73 + | assertThat(bukkit.getGenericExceptionTypes(), is(server.getGenericExceptionTypes())); |
18 74 | } |
19 75 | } |