package eu.mikroskeem.test.shuriken.reflect;

import eu.mikroskeem.shuriken.reflect.Reflect;
import eu.mikroskeem.shuriken.reflect.wrappers.ClassWrapper;
import eu.mikroskeem.test.shuriken.reflect.classes.TestClassOne;
import eu.mikroskeem.test.shuriken.reflect.classes.TestClassTwo;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import static eu.mikroskeem.shuriken.reflect.wrappers.TypeWrapper.of;

public class ClassWrapperTester {
    @Test
    public void testClassFinding() throws Exception {
        Class<?> testClass = TestClassOne.class;
        String className = testClass.getName();

        ClassWrapper<?> cw = Reflect.getClass(className).orElse(null);
        Assertions.assertNotNull(cw, "Class wrapper shouldn't be null!");
        Assertions.assertEquals(testClass, cw.getWrappedClass(), "Classes weren't equal!");
        Assertions.assertNull(cw.getClassInstance(), "Class instance shouldn't be set!");
    }

    @Test
    public void testClassConstructing() throws Exception {
        Class<TestClassOne> testClass = TestClassOne.class;
        ClassWrapper<TestClassOne> cw = Reflect.wrapClass(testClass).construct();
        Assertions.assertNotNull(cw.getClassInstance(), "Class instance shouldn't be null!");
    }

    @Test
    public void testClassConstructingWithArgs() throws Exception {
        Class<TestClassTwo> testClass = TestClassTwo.class;
        ClassWrapper<TestClassTwo> cw = Reflect.wrapClass(testClass)
                .construct(of("foo"));
        Assertions.assertNotNull(cw.getClassInstance(), "Class instance shouldn't be null!");
        TestClassTwo inst = cw.getClassInstance();
        Assertions.assertEquals("foo", inst.getA());
    }

    @Test
    public void testClassConstructingWithInvalidArgs() throws Exception {
        Class<TestClassTwo> testClass = TestClassTwo.class;
        ClassWrapper<TestClassTwo> cw = Reflect.wrapClass(testClass);
        NoSuchMethodException e = Assertions.assertThrows(NoSuchMethodException.class, ()->{
            Reflect.construct(cw, of(1));
        });
        Assertions.assertNull(cw.getClassInstance(), "Class instance should be null!");
    }
}

@@ -2171,11 +2171,369 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testInstanceWrapping() throws Exception %7B%0A        Class%3CTestClassOne%3E testClass = TestClassOne.class;%0A        TestClassOne testClassOne = new TestClassOne();%0A        ClassWrapper%3CTestClassOne%3E cw = Reflect.wrapInstance(testClassOne);%0A        Assertions.assertEquals(testClass, cw.getWrappedClass(), %22Classes should match!%22);%0A    %7D
 %0A%7D%0A

Add unit test