Add some testing

By: Erik Broes <erikbroes@grum.nl>
This commit is contained in:
CraftBukkit/Spigot
2012-01-29 11:22:11 +01:00
parent ff07115b3c
commit ef756d8eba
6 changed files with 219 additions and 1 deletions

View File

@@ -0,0 +1,21 @@
package org.bukkit.support;
import net.minecraft.server.StatisticList;
import org.junit.BeforeClass;
/**
* If you are getting: java.lang.ExceptionInInitializerError
* at net.minecraft.server.StatisticList.<clinit>(SourceFile:58)
* at net.minecraft.server.Item.<clinit>(SourceFile:252)
* at net.minecraft.server.Block.<clinit>(Block.java:577)
*
* extend this class to solve it.
*/
public abstract class AbstractTestingBase {
@BeforeClass
public static void setup() {
StatisticList.a();
}
}

View File

@@ -0,0 +1,31 @@
package org.bukkit.support;
import java.lang.reflect.Field;
public class Util {
/*
public static <T> T getInternalState(Object object, String fieldName) {
return getInternalState(object.getClass(), object, fieldName);
}
*/
@SuppressWarnings("unchecked")
public static <T> T getInternalState(Class<?> clazz, Object object, String fieldName) {
Field field;
try {
field = clazz.getDeclaredField(fieldName);
} catch (SecurityException e) {
throw new RuntimeException("Not allowed to access " + clazz, e);
} catch (NoSuchFieldException e) {
throw new RuntimeException("Unable to find field " + fieldName, e);
}
field.setAccessible(true);
try {
return (T) field.get(object);
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
}
throw new RuntimeException("Unable to get internal value");
}
}