Initial commit

This commit is contained in:
Frank van der Heijden 2020-12-21 00:07:32 +01:00
commit 9c77777ff3
No known key found for this signature in database
GPG key ID: 26DA56488D314D11
22 changed files with 1561 additions and 0 deletions

View file

@ -0,0 +1,27 @@
package dev.frankheijden.minecraftreflection;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.craftbukkit.v1_16_R3.CraftServer;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
public class BasicReflectionTest {
Server server;
MockedStatic<Bukkit> holder;
@BeforeEach
void setUp() {
server = Mockito.mock(CraftServer.class);
holder = Mockito.mockStatic(Bukkit.class);
holder.when(Bukkit::getServer).thenReturn(server);
}
@AfterEach
void cleanUp() {
holder.close();
}
}

View file

@ -0,0 +1,28 @@
package dev.frankheijden.minecraftreflection;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
class MinecraftReflectionVersionTest extends BasicReflectionTest {
@Test
void testNMS() {
assertEquals("v1_16_R3", MinecraftReflectionVersion.NMS);
}
@Test
void testMajor() {
assertEquals(1, MinecraftReflectionVersion.MAJOR);
}
@Test
void testMinor() {
assertEquals(16, MinecraftReflectionVersion.MINOR);
}
@Test
void testPatch() {
assertEquals(3, MinecraftReflectionVersion.PATCH);
}
}

View file

@ -0,0 +1,30 @@
package dev.frankheijden.minecraftreflection;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.params.provider.Arguments.of;
import java.util.stream.Stream;
import dev.frankheijden.minecraftreflection.utils.ReflectionStringUtils;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
class ReflectionStringUtilsTest {
static Stream<Arguments> stringGenerator() {
return Stream.of(
of("java.lang.String#field", ReflectionStringUtils.field(String.class, "field")),
of("java.lang.Integer#value", ReflectionStringUtils.field(Integer.class, "value")),
of("java.lang.Integer#compareTo(java.lang.Integer)", ReflectionStringUtils.method(Integer.class, "compareTo", Integer.class)),
of("java.lang.Integer#a(java.lang.Integer, java.lang.String)", ReflectionStringUtils.method(Integer.class, "a", Integer.class, String.class))
);
}
@ParameterizedTest
@MethodSource("stringGenerator")
void stringTest(String expected, String actual) {
assertEquals(expected, actual);
}
}

View file

@ -0,0 +1,70 @@
package dev.frankheijden.minecraftreflection;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.params.provider.Arguments.of;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
public class ReflectionTest extends BasicReflectionTest {
static Stream<Arguments> getGenerator() {
return Stream.of(
of(10, new Reflection(Integer.class).<Integer>get(10, "value")),
of(1.5f, new Reflection(Float.class).<Float>get(1.5f, "value")),
of(1.5, new Reflection(Double.class).<Double>get(1.5, "value"))
);
}
@ParameterizedTest
@MethodSource("getGenerator")
<T> void testGet(T expected, T actual) {
assertEquals(expected, actual);
}
static Stream<Arguments> setGenerator() {
return Stream.of(
of(10, new Reflection(Integer.class), new Integer(0), "value", 10),
of(1.5F, new Reflection(Float.class), new Float(0), "value", 1.5F),
of(2.5D, new Reflection(Double.class), new Double(0), "value", 2.5D)
);
}
@ParameterizedTest
@MethodSource("setGenerator")
<T> void testSet(T expected, Reflection reflection, Object instance, String field, T updateValue) {
reflection.set(instance, field, updateValue);
assertEquals(expected, reflection.get(instance, field));
}
@Test
void invoke() {
}
@Test
void testInvoke() {
}
@Test
void getTypes() {
}
@Test
void getAccessibleField() {
}
@Test
void getField() {
}
@Test
void getAccessibleMethod() {
}
@Test
void getMethod() {
}
}

View file

@ -0,0 +1,7 @@
package org.bukkit.craftbukkit.v1_16_R3;
import org.bukkit.Server;
public abstract class CraftServer implements Server {
}