Commits

Wesley Wolfe authored 9869166c2ee
Rewrite BukkitMirrorTest
No tags

src/test/java/org/bukkit/BukkitMirrorTest.java

Modified
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 +@RunWith(Parameterized.class)
10 22 public class BukkitMirrorTest {
23 +
24 + @Parameters(name="{index}: {1}")
25 + public static List<Object[]> data() {
26 + return Lists.transform(Arrays.asList(Server.class.getDeclaredMethods()), new Function<Method, Object[]>() {
27 + @Override
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 + @Parameter(0)
38 + public Method server;
39 +
40 + @Parameter(1)
41 + public String name;
42 +
43 + private Method bukkit;
44 +
45 + @Before
46 + public void makeBukkit() throws Throwable {
47 + bukkit = Bukkit.class.getDeclaredMethod(server.getName(), server.getParameterTypes());
48 + }
49 +
50 + @Test
51 + public void isStatic() throws Throwable {
52 + assertThat(Modifier.isStatic(bukkit.getModifiers()), is(true));
53 + }
54 +
55 + @Test
56 + public void isDeprecated() throws Throwable {
57 + assertThat(bukkit.isAnnotationPresent(Deprecated.class), is(server.isAnnotationPresent(Deprecated.class)));
58 + }
59 +
60 + @Test
61 + public void returnType() throws Throwable {
62 + assertThat(bukkit.getReturnType(), is((Object) server.getReturnType()));
63 + assertThat(bukkit.getGenericReturnType(), is(server.getGenericReturnType()));
64 + }
65 +
66 + @Test
67 + public void parameterTypes() throws Throwable {
68 + assertThat(bukkit.getGenericParameterTypes(), is(server.getGenericParameterTypes()));
69 + }
70 +
11 71 @Test
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 }

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut