From ecc1f0067e5d3efa5761d2cc1f771caf6e2eb6f0 Mon Sep 17 00:00:00 2001 From: Luke Bemish Date: Sat, 18 Nov 2023 22:16:12 +0000 Subject: [PATCH] Rearrange tests and fix dependency submission --- .github/workflows/release.yml | 10 +- .github/workflows/snapshot.yml | 10 +- .../test/groovy/Open/TestInstance.groovy | 142 +++++ .../test/groovy/Open/TestMisc.groovy | 141 +++++ .../test/groovy/Open/TestStatic.groovy | 139 +++++ .../test/groovy/Open/TestTypes.groovy | 113 ++++ .../TestMisc.groovy} | 4 +- .../opensesame/test/groovy/TestOpen.groovy | 497 ------------------ .../test/javac/Open/TestInstance.java | 140 +++++ .../opensesame/test/javac/Open/TestMisc.java | 136 +++++ .../test/javac/Open/TestStatic.java | 137 +++++ .../opensesame/test/javac/Open/TestTypes.java | 111 ++++ .../opensesame/test/javac/TestOpen.java | 495 ----------------- 13 files changed, 1071 insertions(+), 1004 deletions(-) create mode 100644 groovy/src/test/groovy/dev/lukebemish/opensesame/test/groovy/Open/TestInstance.groovy create mode 100644 groovy/src/test/groovy/dev/lukebemish/opensesame/test/groovy/Open/TestMisc.groovy create mode 100644 groovy/src/test/groovy/dev/lukebemish/opensesame/test/groovy/Open/TestStatic.groovy create mode 100644 groovy/src/test/groovy/dev/lukebemish/opensesame/test/groovy/Open/TestTypes.groovy rename groovy/src/test/groovy/dev/lukebemish/opensesame/test/groovy/{TestOpenClass.groovy => OpenClass/TestMisc.groovy} (98%) delete mode 100644 groovy/src/test/groovy/dev/lukebemish/opensesame/test/groovy/TestOpen.groovy create mode 100644 javac/src/test/java/dev/lukebemish/opensesame/test/javac/Open/TestInstance.java create mode 100644 javac/src/test/java/dev/lukebemish/opensesame/test/javac/Open/TestMisc.java create mode 100644 javac/src/test/java/dev/lukebemish/opensesame/test/javac/Open/TestStatic.java create mode 100644 javac/src/test/java/dev/lukebemish/opensesame/test/javac/Open/TestTypes.java delete mode 100644 javac/src/test/java/dev/lukebemish/opensesame/test/javac/TestOpen.java diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8dbb9a4..6857639 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -41,10 +41,10 @@ jobs: uses: mikepenz/gradle-dependency-submission@v0.9.0 with: gradle-build-module: |- - :annotations - :runtime - :compile - :groovy - :javac + :opensesame-annotations + :opensesame-runtime + :opensesame-compile + :opensesame-groovy + :opensesame-javac gradle-build-configuration: |- compileClasspath \ No newline at end of file diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml index 3384bd7..ce2dbd4 100644 --- a/.github/workflows/snapshot.yml +++ b/.github/workflows/snapshot.yml @@ -53,10 +53,10 @@ jobs: uses: mikepenz/gradle-dependency-submission@v0.9.0 with: gradle-build-module: |- - :annotations - :runtime - :compile - :groovy - :javac + :opensesame-annotations + :opensesame-runtime + :opensesame-compile + :opensesame-groovy + :opensesame-javac gradle-build-configuration: |- compileClasspath diff --git a/groovy/src/test/groovy/dev/lukebemish/opensesame/test/groovy/Open/TestInstance.groovy b/groovy/src/test/groovy/dev/lukebemish/opensesame/test/groovy/Open/TestInstance.groovy new file mode 100644 index 0000000..6187ab1 --- /dev/null +++ b/groovy/src/test/groovy/dev/lukebemish/opensesame/test/groovy/Open/TestInstance.groovy @@ -0,0 +1,142 @@ +package dev.lukebemish.opensesame.test.groovy.Open + +import dev.lukebemish.opensesame.annotations.Open +import dev.lukebemish.opensesame.test.target.Public +import groovy.transform.CompileStatic +import org.junit.jupiter.api.Test + +import static org.junit.jupiter.api.Assertions.assertEquals + +@CompileStatic +class TestInstance { + @Open( + name = 'privateInstance', + targetClass = Public, + type = Open.Type.VIRTUAL + ) + private static String publicPrivateInstance(Public instance) { + throw new RuntimeException() + } + + @Test + void testPrivateInstance() { + assertEquals("privateInstance", publicPrivateInstance(new Public())) + } + + @Open( + name = 'protectedInstance', + targetClass = Public, + type = Open.Type.VIRTUAL + ) + private static String publicProtectedInstance(Public instance) { + throw new RuntimeException() + } + + @Test + void testProtectedInstance() { + assertEquals("protectedInstance", publicProtectedInstance(new Public())) + } + + @Open( + name = 'packagePrivateInstance', + targetClass = Public, + type = Open.Type.VIRTUAL + ) + private static String publicPackagePrivateInstance(Public instance) { + throw new RuntimeException() + } + + @Test + void testPackagePrivateInstance() { + assertEquals("packagePrivateInstance", publicPackagePrivateInstance(new Public())) + } + + @Open( + name = 'privateInstanceField', + targetClass = Public, + type = Open.Type.GET_INSTANCE + ) + private static String publicPrivateInstanceField(Public instance) { + throw new RuntimeException() + } + + @Open( + name = 'privateInstanceField', + targetClass = Public, + type = Open.Type.SET_INSTANCE + ) + private static void publicPrivateInstanceField(Public instance, String value) { + throw new RuntimeException() + } + + @Test + void testPrivateInstanceField() { + var instance = new Public() + publicPrivateInstanceField(instance, "test") + assertEquals("test", publicPrivateInstanceField(instance)) + } + + @Open( + name = 'protectedInstanceField', + targetClass = Public, + type = Open.Type.GET_INSTANCE + ) + private static String publicProtectedInstanceField(Public instance) { + throw new RuntimeException() + } + + @Open( + name = 'protectedInstanceField', + targetClass = Public, + type = Open.Type.SET_INSTANCE + ) + private static void publicProtectedInstanceField(Public instance, String value) { + throw new RuntimeException() + } + + @Test + void testProtectedInstanceField() { + var instance = new Public() + publicProtectedInstanceField(instance, "test") + assertEquals("test", publicProtectedInstanceField(instance)) + } + + @Open( + name = 'packagePrivateInstanceField', + targetClass = Public, + type = Open.Type.GET_INSTANCE + ) + private static String publicPackagePrivateInstanceField(Public instance) { + throw new RuntimeException() + } + + @Open( + name = 'packagePrivateInstanceField', + targetClass = Public, + type = Open.Type.SET_INSTANCE + ) + private static void publicPackagePrivateInstanceField(Public instance, String value) { + throw new RuntimeException() + } + + @Test + void testPackagePrivateInstanceField() { + var instance = new Public() + publicPackagePrivateInstanceField(instance, "test") + assertEquals("test", publicPackagePrivateInstanceField(instance)) + } + + @Open( + name = 'privateFinalInstanceField', + targetClass = Public, + type = Open.Type.GET_INSTANCE + ) + private static String publicPrivateFinalInstanceField(Public instance) { + throw new RuntimeException() + } + + @Test + void testPrivateFinalInstanceField() { + assertEquals("privateFinalInstanceField", publicPrivateFinalInstanceField(new Public())) + } +} diff --git a/groovy/src/test/groovy/dev/lukebemish/opensesame/test/groovy/Open/TestMisc.groovy b/groovy/src/test/groovy/dev/lukebemish/opensesame/test/groovy/Open/TestMisc.groovy new file mode 100644 index 0000000..c2e1a9a --- /dev/null +++ b/groovy/src/test/groovy/dev/lukebemish/opensesame/test/groovy/Open/TestMisc.groovy @@ -0,0 +1,141 @@ +package dev.lukebemish.opensesame.test.groovy.Open + + +import dev.lukebemish.opensesame.annotations.Open +import dev.lukebemish.opensesame.test.target.Public +import groovy.transform.CompileStatic +import groovy.transform.PackageScope +import org.junit.jupiter.api.Test + +import static org.junit.jupiter.api.Assertions.assertEquals +import static org.junit.jupiter.api.Assertions.assertThrows + +@CompileStatic +class TestMisc { + @Open( + name = 'privateInstanceOverloaded', + targetClass = Public, + type = Open.Type.VIRTUAL + ) + private static String publicPrivateInstanceOverloaded(Public instance) { + throw new RuntimeException() + } + + @Test + void testPrivateInstanceOverloaded() { + assertEquals("privateInstanceOverloaded", publicPrivateInstanceOverloaded(new Public())) + assertEquals("privateInstanceOverloaded", publicPrivateInstanceOverloaded(new Public.PublicSubclass())) + } + + @Open( + targetName = 'dev.lukebemish.opensesame.test.target.Public$Private', + type = Open.Type.CONSTRUCT + ) + @PackageScope + static Object privatePrivateConstructor() { + throw new RuntimeException() + } + + @Open( + name = 'privateInstance', + targetName = 'dev.lukebemish.opensesame.test.target.Public$Private', + type = Open.Type.VIRTUAL + ) + private static String privatePrivateInstance(Object instance) { + throw new RuntimeException() + } + + @Test + void testPrivateClass() { + Object instance = privatePrivateConstructor() + assertEquals("Private", instance.toString()) + assertEquals("privateInstance", privatePrivateInstance(instance)) + } + + @Open( + targetName = 'dev.lukebemish.opensesame.test.target.Public$PrivateCtor', + type = Open.Type.CONSTRUCT + ) + private static Public.PrivateCtor privateConstructor() { + throw new RuntimeException() + } + + @Test + void testPrivateConstructor() { + Public.PrivateCtor instance = privateConstructor() + assertEquals("PrivateCtor", instance.toString()) + } + + @Open( + targetName = 'dev.lukebemish.opensesame.test.target.PackagePrivate', + type = Open.Type.CONSTRUCT + ) + private static Object packagePrivateConstructor() { + throw new RuntimeException() + } + + @Open( + name = 'privateInstance', + targetName = 'dev.lukebemish.opensesame.test.target.PackagePrivate', + type = Open.Type.VIRTUAL + ) + private static String packagePrivateInstance(Object instance) { + throw new RuntimeException() + } + + @Test + void testPackagePrivateClass() { + Object instance = packagePrivateConstructor() + assertEquals("PackagePrivate", instance.toString()) + assertEquals("privateInstance", packagePrivateInstance(instance)) + } + + @Open( + name = 'hiddenByModules', + targetName = 'dev.lukebemish.opensesame.test.target.hidden.Hidden', + type = Open.Type.STATIC, + unsafe = true + ) + private static String hiddenByModules() { + throw new RuntimeException() + } + + @Open( + name = 'hiddenByModulesPrivate', + targetName = 'dev.lukebemish.opensesame.test.target.hidden.Hidden', + type = Open.Type.STATIC, + unsafe = true + ) + private static String hiddenByModulesPrivate() { + throw new RuntimeException() + } + + @Test + void testModuleBreaking() { + assertEquals('hiddenByModules', hiddenByModules()) + assertEquals('hiddenByModulesPrivate', hiddenByModulesPrivate()) + assertThrows(IllegalAccessException, { + Class hidden = Class.forName("dev.lukebemish.opensesame.test.target.hidden.Hidden") + hidden.getDeclaredMethod("hiddenByModules").invoke(null) + }) + } + + @Open( + targetName = 'dev.lukebemish.opensesame.test.target.Public$Private', + type = Open.Type.ARRAY + ) + private static Object[] privateArrayConstructor(int i) { + throw new RuntimeException() + } + + @Test + void testPrivateArrayConstructor() { + Object[] array = privateArrayConstructor(2) + assertEquals(2, array.length) + array[0] = privatePrivateConstructor() + assertEquals("Private", array[0].toString()) + assertThrows(ArrayStoreException, { + array[1] = "stuff" + }) + } +} diff --git a/groovy/src/test/groovy/dev/lukebemish/opensesame/test/groovy/Open/TestStatic.groovy b/groovy/src/test/groovy/dev/lukebemish/opensesame/test/groovy/Open/TestStatic.groovy new file mode 100644 index 0000000..f69a820 --- /dev/null +++ b/groovy/src/test/groovy/dev/lukebemish/opensesame/test/groovy/Open/TestStatic.groovy @@ -0,0 +1,139 @@ +package dev.lukebemish.opensesame.test.groovy.Open + +import dev.lukebemish.opensesame.annotations.Open +import dev.lukebemish.opensesame.test.target.Public +import groovy.transform.CompileStatic +import org.junit.jupiter.api.Test + +import static org.junit.jupiter.api.Assertions.assertEquals + +@CompileStatic +class TestStatic { + @Open( + name = 'privateStatic', + targetClass = Public, + type = Open.Type.STATIC + ) + private static String publicPrivateStatic() { + throw new RuntimeException() + } + + @Test + void testPrivateStatic() { + assertEquals("privateStatic", publicPrivateStatic()) + } + + @Open( + name = 'protectedStatic', + targetClass = Public, + type = Open.Type.STATIC + ) + private static String publicProtectedStatic() { + throw new RuntimeException() + } + + @Test + void testProtectedStatic() { + assertEquals("protectedStatic", publicProtectedStatic()) + } + + @Open( + name = 'packagePrivateStatic', + targetClass = Public, + type = Open.Type.STATIC + ) + private static String publicPackagePrivateStatic() { + throw new RuntimeException() + } + + @Test + void testPackagePrivateStatic() { + assertEquals("packagePrivateStatic", publicPackagePrivateStatic()) + } + + @Open( + name = 'privateStaticField', + targetClass = Public, + type = Open.Type.GET_STATIC + ) + private static String publicPrivateStaticField() { + throw new RuntimeException() + } + + @Open( + name = 'privateStaticField', + targetClass = Public, + type = Open.Type.SET_STATIC + ) + private static void publicPrivateStaticField(String value) { + throw new RuntimeException() + } + + @Test + void testPrivateStaticField() { + publicPrivateStaticField("test") + assertEquals("test", publicPrivateStaticField()) + } + + @Open( + name = 'protectedStaticField', + targetClass = Public, + type = Open.Type.GET_STATIC + ) + private static String publicProtectedStaticField() { + throw new RuntimeException() + } + + @Open( + name = 'protectedStaticField', + targetClass = Public, + type = Open.Type.SET_STATIC + ) + private static void publicProtectedStaticField(String value) { + throw new RuntimeException() + } + + @Test + void testProtectedStaticField() { + publicProtectedStaticField("test") + assertEquals("test", publicProtectedStaticField()) + } + + @Open( + name = 'packagePrivateStaticField', + targetClass = Public, + type = Open.Type.GET_STATIC + ) + private static String publicPackagePrivateStaticField() { + throw new RuntimeException() + } + + @Open( + name = 'packagePrivateStaticField', + targetClass = Public, + type = Open.Type.SET_STATIC + ) + private static void publicPackagePrivateStaticField(String value) { + throw new RuntimeException() + } + + @Test + void testPackagePrivateStaticField() { + publicPackagePrivateStaticField("test") + assertEquals("test", publicPackagePrivateStaticField()) + } + + @Open( + name = 'privateFinalStaticField', + targetClass = Public, + type = Open.Type.GET_STATIC + ) + private static String publicPrivateFinalStaticField() { + throw new RuntimeException() + } + + @Test + void testPrivateFinalStaticField() { + assertEquals("privateFinalStaticField", publicPrivateFinalStaticField()) + } +} diff --git a/groovy/src/test/groovy/dev/lukebemish/opensesame/test/groovy/Open/TestTypes.groovy b/groovy/src/test/groovy/dev/lukebemish/opensesame/test/groovy/Open/TestTypes.groovy new file mode 100644 index 0000000..d5559ae --- /dev/null +++ b/groovy/src/test/groovy/dev/lukebemish/opensesame/test/groovy/Open/TestTypes.groovy @@ -0,0 +1,113 @@ +package dev.lukebemish.opensesame.test.groovy.Open + +import dev.lukebemish.opensesame.annotations.Coerce +import dev.lukebemish.opensesame.annotations.Open +import dev.lukebemish.opensesame.test.target.Public +import groovy.transform.CompileStatic +import org.junit.jupiter.api.Test + +import static org.junit.jupiter.api.Assertions.assertArrayEquals +import static org.junit.jupiter.api.Assertions.assertEquals + +@CompileStatic +class TestTypes { + @Open( + name = 'voidReturn', + targetClass = Public, + type = Open.Type.STATIC + ) + private static void publicVoidReturn() { + throw new RuntimeException() + } + + @Test + void testVoidReturn() { + int count = Public.voidReturnCounter + publicVoidReturn() + assertEquals(Public.voidReturnCounter, count + 1) + } + + @Open( + name = 'primitiveReturn', + targetClass = Public, + type = Open.Type.STATIC + ) + private static int publicPrimitiveReturn() { + throw new RuntimeException() + } + + @Test + void testPrimitiveReturn() { + assertEquals(publicPrimitiveReturn(), 5) + } + + @Open( + name = 'privateReturn', + targetClass = Public, + type = Open.Type.STATIC + ) + private static @Coerce(targetName = 'dev.lukebemish.opensesame.test.target.Public$Private') Object publicPrivateReturn() { + throw new RuntimeException() + } + + @Test + void testPrivateReturn() { + assertEquals("Private", publicPrivateReturn().toString()) + } + + @Open( + name = 'arrayReturn', + targetClass = Public, + type = Open.Type.STATIC + ) + private static String[] publicArrayReturn() { + throw new RuntimeException() + } + + @Test + void testArrayReturn() { + assertArrayEquals(new String[] {"a", "b"}, publicArrayReturn()) + } + + @Open( + name = 'primitiveArgument', + targetClass = Public, + type = Open.Type.STATIC + ) + private static String publicPrimitiveArgument(int value) { + throw new RuntimeException() + } + + @Test + void testPrimitiveArgument() { + assertEquals('5', publicPrimitiveArgument(5)) + } + + @Open( + name = 'privateArgument', + targetClass = Public, + type = Open.Type.STATIC + ) + private static String publicPrivateArgument(@Coerce(targetName = 'dev.lukebemish.opensesame.test.target.Public$Private') Object value) { + throw new RuntimeException() + } + + @Test + void testPrivateArgument() { + assertEquals("Private1", publicPrivateArgument(TestMisc.privatePrivateConstructor())) + } + + @Open( + name = 'arrayArgument', + targetClass = Public, + type = Open.Type.STATIC + ) + private static String publicArrayArgument(String[] value) { + throw new RuntimeException() + } + + @Test + void testArrayArgument() { + assertEquals("a", publicArrayArgument(new String[]{"a", "b"})) + } +} diff --git a/groovy/src/test/groovy/dev/lukebemish/opensesame/test/groovy/TestOpenClass.groovy b/groovy/src/test/groovy/dev/lukebemish/opensesame/test/groovy/OpenClass/TestMisc.groovy similarity index 98% rename from groovy/src/test/groovy/dev/lukebemish/opensesame/test/groovy/TestOpenClass.groovy rename to groovy/src/test/groovy/dev/lukebemish/opensesame/test/groovy/OpenClass/TestMisc.groovy index ad9239c..8442951 100644 --- a/groovy/src/test/groovy/dev/lukebemish/opensesame/test/groovy/TestOpenClass.groovy +++ b/groovy/src/test/groovy/dev/lukebemish/opensesame/test/groovy/OpenClass/TestMisc.groovy @@ -1,4 +1,4 @@ -package dev.lukebemish.opensesame.test.groovy +package dev.lukebemish.opensesame.test.groovy.OpenClass import dev.lukebemish.opensesame.annotations.groovy.OpenClass @@ -11,7 +11,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals @CompileStatic @SuppressWarnings('GroovyAccessibility') -class TestOpenClass { +class TestMisc { @Test @OpenClass(Public) void testPrivateInstance() { diff --git a/groovy/src/test/groovy/dev/lukebemish/opensesame/test/groovy/TestOpen.groovy b/groovy/src/test/groovy/dev/lukebemish/opensesame/test/groovy/TestOpen.groovy deleted file mode 100644 index 3384d35..0000000 --- a/groovy/src/test/groovy/dev/lukebemish/opensesame/test/groovy/TestOpen.groovy +++ /dev/null @@ -1,497 +0,0 @@ -package dev.lukebemish.opensesame.test.groovy - -import dev.lukebemish.opensesame.annotations.Coerce -import dev.lukebemish.opensesame.annotations.Open -import dev.lukebemish.opensesame.test.target.Public -import groovy.transform.CompileStatic -import org.junit.jupiter.api.Test - -import static org.junit.jupiter.api.Assertions.* - -@CompileStatic -class TestOpen { - @Open( - name = 'privateInstance', - targetClass = Public, - type = Open.Type.VIRTUAL - ) - private static String publicPrivateInstance(Public instance) { - throw new RuntimeException() - } - - @Test - void testPrivateInstance() { - assertEquals("privateInstance", publicPrivateInstance(new Public())) - } - - @Open( - name = 'privateInstanceOverloaded', - targetClass = Public, - type = Open.Type.VIRTUAL - ) - private static String publicPrivateInstanceOverloaded(Public instance) { - throw new RuntimeException() - } - - @Test - void testPrivateInstanceOverloaded() { - assertEquals("privateInstanceOverloaded", publicPrivateInstanceOverloaded(new Public())) - assertEquals("privateInstanceOverloaded", publicPrivateInstanceOverloaded(new Public.PublicSubclass())) - } - - @Open( - name = 'protectedInstance', - targetClass = Public, - type = Open.Type.VIRTUAL - ) - private static String publicProtectedInstance(Public instance) { - throw new RuntimeException() - } - - @Test - void testProtectedInstance() { - assertEquals("protectedInstance", publicProtectedInstance(new Public())) - } - - @Open( - name = 'packagePrivateInstance', - targetClass = Public, - type = Open.Type.VIRTUAL - ) - private static String publicPackagePrivateInstance(Public instance) { - throw new RuntimeException() - } - - @Test - void testPackagePrivateInstance() { - assertEquals("packagePrivateInstance", publicPackagePrivateInstance(new Public())) - } - - @Open( - name = 'privateInstanceField', - targetClass = Public, - type = Open.Type.GET_INSTANCE - ) - private static String publicPrivateInstanceField(Public instance) { - throw new RuntimeException() - } - - @Open( - name = 'privateInstanceField', - targetClass = Public, - type = Open.Type.SET_INSTANCE - ) - private static void publicPrivateInstanceField(Public instance, String value) { - throw new RuntimeException() - } - - @Test - void testPrivateInstanceField() { - var instance = new Public() - publicPrivateInstanceField(instance, "test") - assertEquals("test", publicPrivateInstanceField(instance)) - } - - @Open( - name = 'protectedInstanceField', - targetClass = Public, - type = Open.Type.GET_INSTANCE - ) - private static String publicProtectedInstanceField(Public instance) { - throw new RuntimeException() - } - - @Open( - name = 'protectedInstanceField', - targetClass = Public, - type = Open.Type.SET_INSTANCE - ) - private static void publicProtectedInstanceField(Public instance, String value) { - throw new RuntimeException() - } - - @Test - void testProtectedInstanceField() { - var instance = new Public() - publicProtectedInstanceField(instance, "test") - assertEquals("test", publicProtectedInstanceField(instance)) - } - - @Open( - name = 'packagePrivateInstanceField', - targetClass = Public, - type = Open.Type.GET_INSTANCE - ) - private static String publicPackagePrivateInstanceField(Public instance) { - throw new RuntimeException() - } - - @Open( - name = 'packagePrivateInstanceField', - targetClass = Public, - type = Open.Type.SET_INSTANCE - ) - private static void publicPackagePrivateInstanceField(Public instance, String value) { - throw new RuntimeException() - } - - @Test - void testPackagePrivateInstanceField() { - var instance = new Public() - publicPackagePrivateInstanceField(instance, "test") - assertEquals("test", publicPackagePrivateInstanceField(instance)) - } - - @Open( - name = 'privateFinalInstanceField', - targetClass = Public, - type = Open.Type.GET_INSTANCE - ) - private static String publicPrivateFinalInstanceField(Public instance) { - throw new RuntimeException() - } - - @Test - void testPrivateFinalInstanceField() { - assertEquals("privateFinalInstanceField", publicPrivateFinalInstanceField(new Public())) - } - - @Open( - name = 'privateStatic', - targetClass = Public, - type = Open.Type.STATIC - ) - private static String publicPrivateStatic() { - throw new RuntimeException() - } - - @Test - void testPrivateStatic() { - assertEquals("privateStatic", publicPrivateStatic()) - } - - @Open( - name = 'protectedStatic', - targetClass = Public, - type = Open.Type.STATIC - ) - private static String publicProtectedStatic() { - throw new RuntimeException() - } - - @Test - void testProtectedStatic() { - assertEquals("protectedStatic", publicProtectedStatic()) - } - - @Open( - name = 'packagePrivateStatic', - targetClass = Public, - type = Open.Type.STATIC - ) - private static String publicPackagePrivateStatic() { - throw new RuntimeException() - } - - @Test - void testPackagePrivateStatic() { - assertEquals("packagePrivateStatic", publicPackagePrivateStatic()) - } - - @Open( - name = 'privateStaticField', - targetClass = Public, - type = Open.Type.GET_STATIC - ) - private static String publicPrivateStaticField() { - throw new RuntimeException() - } - - @Open( - name = 'privateStaticField', - targetClass = Public, - type = Open.Type.SET_STATIC - ) - private static void publicPrivateStaticField(String value) { - throw new RuntimeException() - } - - @Test - void testPrivateStaticField() { - publicPrivateStaticField("test") - assertEquals("test", publicPrivateStaticField()) - } - - @Open( - name = 'protectedStaticField', - targetClass = Public, - type = Open.Type.GET_STATIC - ) - private static String publicProtectedStaticField() { - throw new RuntimeException() - } - - @Open( - name = 'protectedStaticField', - targetClass = Public, - type = Open.Type.SET_STATIC - ) - private static void publicProtectedStaticField(String value) { - throw new RuntimeException() - } - - @Test - void testProtectedStaticField() { - publicProtectedStaticField("test") - assertEquals("test", publicProtectedStaticField()) - } - - @Open( - name = 'packagePrivateStaticField', - targetClass = Public, - type = Open.Type.GET_STATIC - ) - private static String publicPackagePrivateStaticField() { - throw new RuntimeException() - } - - @Open( - name = 'packagePrivateStaticField', - targetClass = Public, - type = Open.Type.SET_STATIC - ) - private static void publicPackagePrivateStaticField(String value) { - throw new RuntimeException() - } - - @Test - void testPackagePrivateStaticField() { - publicPackagePrivateStaticField("test") - assertEquals("test", publicPackagePrivateStaticField()) - } - - @Open( - name = 'privateFinalStaticField', - targetClass = Public, - type = Open.Type.GET_STATIC - ) - private static String publicPrivateFinalStaticField() { - throw new RuntimeException() - } - - @Test - void testPrivateFinalStaticField() { - assertEquals("privateFinalStaticField", publicPrivateFinalStaticField()) - } - - @Open( - targetName = 'dev.lukebemish.opensesame.test.target.Public$Private', - type = Open.Type.CONSTRUCT - ) - private static Object privatePrivateConstructor() { - throw new RuntimeException() - } - - @Open( - name = 'privateInstance', - targetName = 'dev.lukebemish.opensesame.test.target.Public$Private', - type = Open.Type.VIRTUAL - ) - private static String privatePrivateInstance(Object instance) { - throw new RuntimeException() - } - - @Test - void testPrivateClass() { - Object instance = privatePrivateConstructor() - assertEquals("Private", instance.toString()) - assertEquals("privateInstance", privatePrivateInstance(instance)) - } - - @Open( - targetName = 'dev.lukebemish.opensesame.test.target.Public$PrivateCtor', - type = Open.Type.CONSTRUCT - ) - private static Public.PrivateCtor privateConstructor() { - throw new RuntimeException() - } - - @Test - void testPrivateConstructor() { - Public.PrivateCtor instance = privateConstructor() - assertEquals("PrivateCtor", instance.toString()) - } - - @Open( - targetName = 'dev.lukebemish.opensesame.test.target.PackagePrivate', - type = Open.Type.CONSTRUCT - ) - private static Object packagePrivateConstructor() { - throw new RuntimeException() - } - - @Open( - name = 'privateInstance', - targetName = 'dev.lukebemish.opensesame.test.target.PackagePrivate', - type = Open.Type.VIRTUAL - ) - private static String packagePrivateInstance(Object instance) { - throw new RuntimeException() - } - - @Test - void testPackagePrivateClass() { - Object instance = packagePrivateConstructor() - assertEquals("PackagePrivate", instance.toString()) - assertEquals("privateInstance", packagePrivateInstance(instance)) - } - - @Open( - name = 'voidReturn', - targetClass = Public, - type = Open.Type.STATIC - ) - private static void publicVoidReturn() { - throw new RuntimeException() - } - - @Test - void testVoidReturn() { - int count = Public.voidReturnCounter - publicVoidReturn() - assertEquals(Public.voidReturnCounter, count + 1) - } - - @Open( - name = 'primitiveReturn', - targetClass = Public, - type = Open.Type.STATIC - ) - private static int publicPrimitiveReturn() { - throw new RuntimeException() - } - - @Test - void testPrimitiveReturn() { - assertEquals(publicPrimitiveReturn(), 5) - } - - @Open( - name = 'privateReturn', - targetClass = Public, - type = Open.Type.STATIC - ) - private static @Coerce(targetName = 'dev.lukebemish.opensesame.test.target.Public$Private') Object publicPrivateReturn() { - throw new RuntimeException() - } - - @Test - void testPrivateReturn() { - assertEquals("Private", publicPrivateReturn().toString()) - } - - @Open( - name = 'arrayReturn', - targetClass = Public, - type = Open.Type.STATIC - ) - private static String[] publicArrayReturn() { - throw new RuntimeException() - } - - @Test - void testArrayReturn() { - assertArrayEquals(new String[] {"a", "b"}, publicArrayReturn()) - } - - @Open( - name = 'primitiveArgument', - targetClass = Public, - type = Open.Type.STATIC - ) - private static String publicPrimitiveArgument(int value) { - throw new RuntimeException() - } - - @Test - void testPrimitiveArgument() { - assertEquals('5', publicPrimitiveArgument(5)) - } - - @Open( - name = 'privateArgument', - targetClass = Public, - type = Open.Type.STATIC - ) - private static String publicPrivateArgument(@Coerce(targetName = 'dev.lukebemish.opensesame.test.target.Public$Private') Object value) { - throw new RuntimeException() - } - - @Test - void testPrivateArgument() { - assertEquals("Private1", publicPrivateArgument(privatePrivateConstructor())) - } - - @Open( - name = 'arrayArgument', - targetClass = Public, - type = Open.Type.STATIC - ) - private static String publicArrayArgument(String[] value) { - throw new RuntimeException() - } - - @Test - void testArrayArgument() { - assertEquals("a", publicArrayArgument(new String[]{"a", "b"})) - } - - @Open( - name = 'hiddenByModules', - targetName = 'dev.lukebemish.opensesame.test.target.hidden.Hidden', - type = Open.Type.STATIC, - unsafe = true - ) - private static String hiddenByModules() { - throw new RuntimeException() - } - - @Open( - name = 'hiddenByModulesPrivate', - targetName = 'dev.lukebemish.opensesame.test.target.hidden.Hidden', - type = Open.Type.STATIC, - unsafe = true - ) - private static String hiddenByModulesPrivate() { - throw new RuntimeException() - } - - @Test - void testModuleBreaking() { - assertEquals('hiddenByModules', hiddenByModules()) - assertEquals('hiddenByModulesPrivate', hiddenByModulesPrivate()) - assertThrows(IllegalAccessException, { - Class hidden = Class.forName("dev.lukebemish.opensesame.test.target.hidden.Hidden") - hidden.getDeclaredMethod("hiddenByModules").invoke(null) - }) - } - - @Open( - targetName = 'dev.lukebemish.opensesame.test.target.Public$Private', - type = Open.Type.ARRAY - ) - private static Object[] privateArrayConstructor(int i) { - throw new RuntimeException() - } - - @Test - void testPrivateArrayConstructor() { - Object[] array = privateArrayConstructor(2) - assertEquals(2, array.length) - array[0] = privatePrivateConstructor() - assertEquals("Private", array[0].toString()) - assertThrows(ArrayStoreException, { - array[1] = "stuff" - }) - } -} diff --git a/javac/src/test/java/dev/lukebemish/opensesame/test/javac/Open/TestInstance.java b/javac/src/test/java/dev/lukebemish/opensesame/test/javac/Open/TestInstance.java new file mode 100644 index 0000000..63d9f37 --- /dev/null +++ b/javac/src/test/java/dev/lukebemish/opensesame/test/javac/Open/TestInstance.java @@ -0,0 +1,140 @@ +package dev.lukebemish.opensesame.test.javac.Open; + +import dev.lukebemish.opensesame.annotations.Open; +import dev.lukebemish.opensesame.test.target.Public; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class TestInstance { + @Open( + name = "privateInstance", + targetClass = Public.class, + type = Open.Type.VIRTUAL + ) + private static String publicPrivateInstance(Public instance) { + throw new RuntimeException(); + } + + @Test + void testPrivateInstance() { + assertEquals("privateInstance", publicPrivateInstance(new Public())); + } + + @Open( + name = "protectedInstance", + targetClass = Public.class, + type = Open.Type.VIRTUAL + ) + private static String publicProtectedInstance(Public instance) { + throw new RuntimeException(); + } + + @Test + void testProtectedInstance() { + assertEquals("protectedInstance", publicProtectedInstance(new Public())); + } + + @Open( + name = "packagePrivateInstance", + targetClass = Public.class, + type = Open.Type.VIRTUAL + ) + private static String publicPackagePrivateInstance(Public instance) { + throw new RuntimeException(); + } + + @Test + void testPackagePrivateInstance() { + assertEquals("packagePrivateInstance", publicPackagePrivateInstance(new Public())); + } + + @Open( + name = "privateInstanceField", + targetClass = Public.class, + type = Open.Type.GET_INSTANCE + ) + private static String publicPrivateInstanceField(Public instance) { + throw new RuntimeException(); + } + + @Open( + name = "privateInstanceField", + targetClass = Public.class, + type = Open.Type.SET_INSTANCE + ) + private static void publicPrivateInstanceField(Public instance, String value) { + throw new RuntimeException(); + } + + @Test + void testPrivateInstanceField() { + var instance = new Public(); + publicPrivateInstanceField(instance, "test"); + assertEquals("test", publicPrivateInstanceField(instance)); + } + + @Open( + name = "protectedInstanceField", + targetClass = Public.class, + type = Open.Type.GET_INSTANCE + ) + private static String publicProtectedInstanceField(Public instance) { + throw new RuntimeException(); + } + + @Open( + name = "protectedInstanceField", + targetClass = Public.class, + type = Open.Type.SET_INSTANCE + ) + private static void publicProtectedInstanceField(Public instance, String value) { + throw new RuntimeException(); + } + + @Test + void testProtectedInstanceField() { + var instance = new Public(); + publicProtectedInstanceField(instance, "test"); + assertEquals("test", publicProtectedInstanceField(instance)); + } + + @Open( + name = "packagePrivateInstanceField", + targetClass = Public.class, + type = Open.Type.GET_INSTANCE + ) + private static String publicPackagePrivateInstanceField(Public instance) { + throw new RuntimeException(); + } + + @Open( + name = "packagePrivateInstanceField", + targetClass = Public.class, + type = Open.Type.SET_INSTANCE + ) + private static void publicPackagePrivateInstanceField(Public instance, String value) { + throw new RuntimeException(); + } + + @Test + void testPackagePrivateInstanceField() { + var instance = new Public(); + publicPackagePrivateInstanceField(instance, "test"); + assertEquals("test", publicPackagePrivateInstanceField(instance)); + } + + @Open( + name = "privateFinalInstanceField", + targetClass = Public.class, + type = Open.Type.GET_INSTANCE + ) + private static String publicPrivateFinalInstanceField(Public instance) { + throw new RuntimeException(); + } + + @Test + void testPrivateFinalInstanceField() { + assertEquals("privateFinalInstanceField", publicPrivateFinalInstanceField(new Public())); + } +} diff --git a/javac/src/test/java/dev/lukebemish/opensesame/test/javac/Open/TestMisc.java b/javac/src/test/java/dev/lukebemish/opensesame/test/javac/Open/TestMisc.java new file mode 100644 index 0000000..7bef148 --- /dev/null +++ b/javac/src/test/java/dev/lukebemish/opensesame/test/javac/Open/TestMisc.java @@ -0,0 +1,136 @@ +package dev.lukebemish.opensesame.test.javac.Open; + +import dev.lukebemish.opensesame.annotations.Open; +import dev.lukebemish.opensesame.test.target.Public; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +class TestMisc { + @Open( + name = "privateInstanceOverloaded", + targetClass = Public.class, + type = Open.Type.VIRTUAL + ) + private static String publicPrivateInstanceOverloaded(Public instance) { + throw new RuntimeException(); + } + + @Test + void testPrivateInstanceOverloaded() { + assertEquals("privateInstanceOverloaded", publicPrivateInstanceOverloaded(new Public())); + assertEquals("privateInstanceOverloaded", publicPrivateInstanceOverloaded(new Public.PublicSubclass())); + } + + @Open( + targetName = "dev.lukebemish.opensesame.test.target.Public$Private", + type = Open.Type.CONSTRUCT + ) + static Object privatePrivateConstructor() { + throw new RuntimeException(); + } + + @Open( + name = "privateInstance", + targetName = "dev.lukebemish.opensesame.test.target.Public$Private", + type = Open.Type.VIRTUAL + ) + private static String privatePrivateInstance(Object instance) { + throw new RuntimeException(); + } + + @Test + void testPrivateClass() { + Object instance = privatePrivateConstructor(); + assertEquals("Private", instance.toString()); + assertEquals("privateInstance", privatePrivateInstance(instance)); + } + + @Open( + targetName = "dev.lukebemish.opensesame.test.target.Public$PrivateCtor", + type = Open.Type.CONSTRUCT + ) + private static Public.PrivateCtor privateConstructor() { + throw new RuntimeException(); + } + + @Test + void testPrivateConstructor() { + Public.PrivateCtor instance = privateConstructor(); + assertEquals("PrivateCtor", instance.toString()); + } + + @Open( + targetName = "dev.lukebemish.opensesame.test.target.PackagePrivate", + type = Open.Type.CONSTRUCT + ) + private static Object packagePrivateConstructor() { + throw new RuntimeException(); + } + + @Open( + name = "privateInstance", + targetName = "dev.lukebemish.opensesame.test.target.PackagePrivate", + type = Open.Type.VIRTUAL + ) + private static String packagePrivateInstance(Object instance) { + throw new RuntimeException(); + } + + @Test + void testPackagePrivateClass() { + Object instance = packagePrivateConstructor(); + assertEquals("PackagePrivate", instance.toString()); + assertEquals("privateInstance", packagePrivateInstance(instance)); + } + + @Open( + name = "hiddenByModules", + targetName = "dev.lukebemish.opensesame.test.target.hidden.Hidden", + type = Open.Type.STATIC, + unsafe = true + ) + private static String hiddenByModules() { + throw new RuntimeException(); + } + + @Open( + name = "hiddenByModulesPrivate", + targetName = "dev.lukebemish.opensesame.test.target.hidden.Hidden", + type = Open.Type.STATIC, + unsafe = true + ) + private static String hiddenByModulesPrivate() { + throw new RuntimeException(); + } + + @Test + void testModuleBreaking() { + assertEquals("hiddenByModules", hiddenByModules()); + assertEquals("hiddenByModulesPrivate", hiddenByModulesPrivate()); + assertThrows(IllegalAccessException.class, () -> { + Class hidden = Class.forName("dev.lukebemish.opensesame.test.target.hidden.Hidden"); + hidden.getDeclaredMethod("hiddenByModules").invoke(null); + }); + } + + @Open( + targetName = "dev.lukebemish.opensesame.test.target.Public$Private", + type = Open.Type.ARRAY + ) + private static Object[] privateArrayConstructor(int i) { + throw new RuntimeException(); + } + + @Test + void testPrivateArrayConstructor() { + Object[] array = privateArrayConstructor(2); + assertEquals(2, array.length); + array[0] = privatePrivateConstructor(); + assertEquals("Private", array[0].toString()); + assertThrows(ArrayStoreException.class, () -> { + array[1] = "stuff"; + }); + } +} diff --git a/javac/src/test/java/dev/lukebemish/opensesame/test/javac/Open/TestStatic.java b/javac/src/test/java/dev/lukebemish/opensesame/test/javac/Open/TestStatic.java new file mode 100644 index 0000000..fd524a7 --- /dev/null +++ b/javac/src/test/java/dev/lukebemish/opensesame/test/javac/Open/TestStatic.java @@ -0,0 +1,137 @@ +package dev.lukebemish.opensesame.test.javac.Open; + +import dev.lukebemish.opensesame.annotations.Open; +import dev.lukebemish.opensesame.test.target.Public; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class TestStatic { + @Open( + name = "privateStatic", + targetClass = Public.class, + type = Open.Type.STATIC + ) + private static String publicPrivateStatic() { + throw new RuntimeException(); + } + + @Test + void testPrivateStatic() { + assertEquals("privateStatic", publicPrivateStatic()); + } + + @Open( + name = "protectedStatic", + targetClass = Public.class, + type = Open.Type.STATIC + ) + private static String publicProtectedStatic() { + throw new RuntimeException(); + } + + @Test + void testProtectedStatic() { + assertEquals("protectedStatic", publicProtectedStatic()); + } + + @Open( + name = "packagePrivateStatic", + targetClass = Public.class, + type = Open.Type.STATIC + ) + private static String publicPackagePrivateStatic() { + throw new RuntimeException(); + } + + @Test + void testPackagePrivateStatic() { + assertEquals("packagePrivateStatic", publicPackagePrivateStatic()); + } + + @Open( + name = "privateStaticField", + targetClass = Public.class, + type = Open.Type.GET_STATIC + ) + private static String publicPrivateStaticField() { + throw new RuntimeException(); + } + + @Open( + name = "privateStaticField", + targetClass = Public.class, + type = Open.Type.SET_STATIC + ) + private static void publicPrivateStaticField(String value) { + throw new RuntimeException(); + } + + @Test + void testPrivateStaticField() { + publicPrivateStaticField("test"); + assertEquals("test", publicPrivateStaticField()); + } + + @Open( + name = "protectedStaticField", + targetClass = Public.class, + type = Open.Type.GET_STATIC + ) + private static String publicProtectedStaticField() { + throw new RuntimeException(); + } + + @Open( + name = "protectedStaticField", + targetClass = Public.class, + type = Open.Type.SET_STATIC + ) + private static void publicProtectedStaticField(String value) { + throw new RuntimeException(); + } + + @Test + void testProtectedStaticField() { + publicProtectedStaticField("test"); + assertEquals("test", publicProtectedStaticField()); + } + + @Open( + name = "packagePrivateStaticField", + targetClass = Public.class, + type = Open.Type.GET_STATIC + ) + private static String publicPackagePrivateStaticField() { + throw new RuntimeException(); + } + + @Open( + name = "packagePrivateStaticField", + targetClass = Public.class, + type = Open.Type.SET_STATIC + ) + private static void publicPackagePrivateStaticField(String value) { + throw new RuntimeException(); + } + + @Test + void testPackagePrivateStaticField() { + publicPackagePrivateStaticField("test"); + assertEquals("test", publicPackagePrivateStaticField()); + } + + @Open( + name = "privateFinalStaticField", + targetClass = Public.class, + type = Open.Type.GET_STATIC + ) + private static String publicPrivateFinalStaticField() { + throw new RuntimeException(); + } + + @Test + void testPrivateFinalStaticField() { + assertEquals("privateFinalStaticField", publicPrivateFinalStaticField()); + } +} diff --git a/javac/src/test/java/dev/lukebemish/opensesame/test/javac/Open/TestTypes.java b/javac/src/test/java/dev/lukebemish/opensesame/test/javac/Open/TestTypes.java new file mode 100644 index 0000000..f2b7c64 --- /dev/null +++ b/javac/src/test/java/dev/lukebemish/opensesame/test/javac/Open/TestTypes.java @@ -0,0 +1,111 @@ +package dev.lukebemish.opensesame.test.javac.Open; + +import dev.lukebemish.opensesame.annotations.Coerce; +import dev.lukebemish.opensesame.annotations.Open; +import dev.lukebemish.opensesame.test.target.Public; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; + +class TestTypes { + @Open( + name = "voidReturn", + targetClass = Public.class, + type = Open.Type.STATIC + ) + private static void publicVoidReturn() { + throw new RuntimeException(); + } + + @Test + void testVoidReturn() { + int count = Public.voidReturnCounter; + publicVoidReturn(); + assertEquals(Public.voidReturnCounter, count + 1); + } + + @Open( + name = "primitiveReturn", + targetClass = Public.class, + type = Open.Type.STATIC + ) + private static int publicPrimitiveReturn() { + throw new RuntimeException(); + } + + @Test + void testPrimitiveReturn() { + assertEquals(publicPrimitiveReturn(), 5); + } + + @Open( + name = "privateReturn", + targetClass = Public.class, + type = Open.Type.STATIC + ) + private static @Coerce(targetName = "dev.lukebemish.opensesame.test.target.Public$Private") Object publicPrivateReturn() { + throw new RuntimeException(); + } + + @Test + void testPrivateReturn() { + assertEquals("Private", publicPrivateReturn().toString()); + } + + @Open( + name = "arrayReturn", + targetClass = Public.class, + type = Open.Type.STATIC + ) + private static String[] publicArrayReturn() { + throw new RuntimeException(); + } + + @Test + void testArrayReturn() { + assertArrayEquals(new String[] {"a", "b"}, publicArrayReturn()); + } + + @Open( + name = "primitiveArgument", + targetClass = Public.class, + type = Open.Type.STATIC + ) + private static String publicPrimitiveArgument(int value) { + throw new RuntimeException(); + } + + @Test + void testPrimitiveArgument() { + assertEquals("5", publicPrimitiveArgument(5)); + } + + @Open( + name = "privateArgument", + targetClass = Public.class, + type = Open.Type.STATIC + ) + private static String publicPrivateArgument(@Coerce(targetName = "dev.lukebemish.opensesame.test.target.Public$Private") Object value) { + throw new RuntimeException(); + } + + @Test + void testPrivateArgument() { + assertEquals("Private1", publicPrivateArgument(TestMisc.privatePrivateConstructor())); + } + + @Open( + name = "arrayArgument", + targetClass = Public.class, + type = Open.Type.STATIC + ) + private static String publicArrayArgument(String[] value) { + throw new RuntimeException(); + } + + @Test + void testArrayArgument() { + assertEquals("a", publicArrayArgument(new String[]{"a", "b"})); + } +} diff --git a/javac/src/test/java/dev/lukebemish/opensesame/test/javac/TestOpen.java b/javac/src/test/java/dev/lukebemish/opensesame/test/javac/TestOpen.java deleted file mode 100644 index 6b90f76..0000000 --- a/javac/src/test/java/dev/lukebemish/opensesame/test/javac/TestOpen.java +++ /dev/null @@ -1,495 +0,0 @@ -package dev.lukebemish.opensesame.test.javac; - -import dev.lukebemish.opensesame.annotations.Coerce; -import dev.lukebemish.opensesame.annotations.Open; -import dev.lukebemish.opensesame.test.target.Public; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -class TestOpen { - @Open( - name = "privateInstance", - targetClass = Public.class, - type = Open.Type.VIRTUAL - ) - private static String publicPrivateInstance(Public instance) { - throw new RuntimeException(); - } - - @Test - void testPrivateInstance() { - assertEquals("privateInstance", publicPrivateInstance(new Public())); - } - - @Open( - name = "privateInstanceOverloaded", - targetClass = Public.class, - type = Open.Type.VIRTUAL - ) - private static String publicPrivateInstanceOverloaded(Public instance) { - throw new RuntimeException(); - } - - @Test - void testPrivateInstanceOverloaded() { - assertEquals("privateInstanceOverloaded", publicPrivateInstanceOverloaded(new Public())); - assertEquals("privateInstanceOverloaded", publicPrivateInstanceOverloaded(new Public.PublicSubclass())); - } - - @Open( - name = "protectedInstance", - targetClass = Public.class, - type = Open.Type.VIRTUAL - ) - private static String publicProtectedInstance(Public instance) { - throw new RuntimeException(); - } - - @Test - void testProtectedInstance() { - assertEquals("protectedInstance", publicProtectedInstance(new Public())); - } - - @Open( - name = "packagePrivateInstance", - targetClass = Public.class, - type = Open.Type.VIRTUAL - ) - private static String publicPackagePrivateInstance(Public instance) { - throw new RuntimeException(); - } - - @Test - void testPackagePrivateInstance() { - assertEquals("packagePrivateInstance", publicPackagePrivateInstance(new Public())); - } - - @Open( - name = "privateInstanceField", - targetClass = Public.class, - type = Open.Type.GET_INSTANCE - ) - private static String publicPrivateInstanceField(Public instance) { - throw new RuntimeException(); - } - - @Open( - name = "privateInstanceField", - targetClass = Public.class, - type = Open.Type.SET_INSTANCE - ) - private static void publicPrivateInstanceField(Public instance, String value) { - throw new RuntimeException(); - } - - @Test - void testPrivateInstanceField() { - var instance = new Public(); - publicPrivateInstanceField(instance, "test"); - assertEquals("test", publicPrivateInstanceField(instance)); - } - - @Open( - name = "protectedInstanceField", - targetClass = Public.class, - type = Open.Type.GET_INSTANCE - ) - private static String publicProtectedInstanceField(Public instance) { - throw new RuntimeException(); - } - - @Open( - name = "protectedInstanceField", - targetClass = Public.class, - type = Open.Type.SET_INSTANCE - ) - private static void publicProtectedInstanceField(Public instance, String value) { - throw new RuntimeException(); - } - - @Test - void testProtectedInstanceField() { - var instance = new Public(); - publicProtectedInstanceField(instance, "test"); - assertEquals("test", publicProtectedInstanceField(instance)); - } - - @Open( - name = "packagePrivateInstanceField", - targetClass = Public.class, - type = Open.Type.GET_INSTANCE - ) - private static String publicPackagePrivateInstanceField(Public instance) { - throw new RuntimeException(); - } - - @Open( - name = "packagePrivateInstanceField", - targetClass = Public.class, - type = Open.Type.SET_INSTANCE - ) - private static void publicPackagePrivateInstanceField(Public instance, String value) { - throw new RuntimeException(); - } - - @Test - void testPackagePrivateInstanceField() { - var instance = new Public(); - publicPackagePrivateInstanceField(instance, "test"); - assertEquals("test", publicPackagePrivateInstanceField(instance)); - } - - @Open( - name = "privateFinalInstanceField", - targetClass = Public.class, - type = Open.Type.GET_INSTANCE - ) - private static String publicPrivateFinalInstanceField(Public instance) { - throw new RuntimeException(); - } - - @Test - void testPrivateFinalInstanceField() { - assertEquals("privateFinalInstanceField", publicPrivateFinalInstanceField(new Public())); - } - - @Open( - name = "privateStatic", - targetClass = Public.class, - type = Open.Type.STATIC - ) - private static String publicPrivateStatic() { - throw new RuntimeException(); - } - - @Test - void testPrivateStatic() { - assertEquals("privateStatic", publicPrivateStatic()); - } - - @Open( - name = "protectedStatic", - targetClass = Public.class, - type = Open.Type.STATIC - ) - private static String publicProtectedStatic() { - throw new RuntimeException(); - } - - @Test - void testProtectedStatic() { - assertEquals("protectedStatic", publicProtectedStatic()); - } - - @Open( - name = "packagePrivateStatic", - targetClass = Public.class, - type = Open.Type.STATIC - ) - private static String publicPackagePrivateStatic() { - throw new RuntimeException(); - } - - @Test - void testPackagePrivateStatic() { - assertEquals("packagePrivateStatic", publicPackagePrivateStatic()); - } - - @Open( - name = "privateStaticField", - targetClass = Public.class, - type = Open.Type.GET_STATIC - ) - private static String publicPrivateStaticField() { - throw new RuntimeException(); - } - - @Open( - name = "privateStaticField", - targetClass = Public.class, - type = Open.Type.SET_STATIC - ) - private static void publicPrivateStaticField(String value) { - throw new RuntimeException(); - } - - @Test - void testPrivateStaticField() { - publicPrivateStaticField("test"); - assertEquals("test", publicPrivateStaticField()); - } - - @Open( - name = "protectedStaticField", - targetClass = Public.class, - type = Open.Type.GET_STATIC - ) - private static String publicProtectedStaticField() { - throw new RuntimeException(); - } - - @Open( - name = "protectedStaticField", - targetClass = Public.class, - type = Open.Type.SET_STATIC - ) - private static void publicProtectedStaticField(String value) { - throw new RuntimeException(); - } - - @Test - void testProtectedStaticField() { - publicProtectedStaticField("test"); - assertEquals("test", publicProtectedStaticField()); - } - - @Open( - name = "packagePrivateStaticField", - targetClass = Public.class, - type = Open.Type.GET_STATIC - ) - private static String publicPackagePrivateStaticField() { - throw new RuntimeException(); - } - - @Open( - name = "packagePrivateStaticField", - targetClass = Public.class, - type = Open.Type.SET_STATIC - ) - private static void publicPackagePrivateStaticField(String value) { - throw new RuntimeException(); - } - - @Test - void testPackagePrivateStaticField() { - publicPackagePrivateStaticField("test"); - assertEquals("test", publicPackagePrivateStaticField()); - } - - @Open( - name = "privateFinalStaticField", - targetClass = Public.class, - type = Open.Type.GET_STATIC - ) - private static String publicPrivateFinalStaticField() { - throw new RuntimeException(); - } - - @Test - void testPrivateFinalStaticField() { - assertEquals("privateFinalStaticField", publicPrivateFinalStaticField()); - } - - @Open( - targetName = "dev.lukebemish.opensesame.test.target.Public$Private", - type = Open.Type.CONSTRUCT - ) - private static Object privatePrivateConstructor() { - throw new RuntimeException(); - } - - @Open( - name = "privateInstance", - targetName = "dev.lukebemish.opensesame.test.target.Public$Private", - type = Open.Type.VIRTUAL - ) - private static String privatePrivateInstance(Object instance) { - throw new RuntimeException(); - } - - @Test - void testPrivateClass() { - Object instance = privatePrivateConstructor(); - assertEquals("Private", instance.toString()); - assertEquals("privateInstance", privatePrivateInstance(instance)); - } - - @Open( - targetName = "dev.lukebemish.opensesame.test.target.Public$PrivateCtor", - type = Open.Type.CONSTRUCT - ) - private static Public.PrivateCtor privateConstructor() { - throw new RuntimeException(); - } - - @Test - void testPrivateConstructor() { - Public.PrivateCtor instance = privateConstructor(); - assertEquals("PrivateCtor", instance.toString()); - } - - @Open( - targetName = "dev.lukebemish.opensesame.test.target.PackagePrivate", - type = Open.Type.CONSTRUCT - ) - private static Object packagePrivateConstructor() { - throw new RuntimeException(); - } - - @Open( - name = "privateInstance", - targetName = "dev.lukebemish.opensesame.test.target.PackagePrivate", - type = Open.Type.VIRTUAL - ) - private static String packagePrivateInstance(Object instance) { - throw new RuntimeException(); - } - - @Test - void testPackagePrivateClass() { - Object instance = packagePrivateConstructor(); - assertEquals("PackagePrivate", instance.toString()); - assertEquals("privateInstance", packagePrivateInstance(instance)); - } - - @Open( - name = "voidReturn", - targetClass = Public.class, - type = Open.Type.STATIC - ) - private static void publicVoidReturn() { - throw new RuntimeException(); - } - - @Test - void testVoidReturn() { - int count = Public.voidReturnCounter; - publicVoidReturn(); - assertEquals(Public.voidReturnCounter, count + 1); - } - - @Open( - name = "primitiveReturn", - targetClass = Public.class, - type = Open.Type.STATIC - ) - private static int publicPrimitiveReturn() { - throw new RuntimeException(); - } - - @Test - void testPrimitiveReturn() { - assertEquals(publicPrimitiveReturn(), 5); - } - - @Open( - name = "privateReturn", - targetClass = Public.class, - type = Open.Type.STATIC - ) - private static @Coerce(targetName = "dev.lukebemish.opensesame.test.target.Public$Private") Object publicPrivateReturn() { - throw new RuntimeException(); - } - - @Test - void testPrivateReturn() { - assertEquals("Private", publicPrivateReturn().toString()); - } - - @Open( - name = "arrayReturn", - targetClass = Public.class, - type = Open.Type.STATIC - ) - private static String[] publicArrayReturn() { - throw new RuntimeException(); - } - - @Test - void testArrayReturn() { - assertArrayEquals(new String[] {"a", "b"}, publicArrayReturn()); - } - - @Open( - name = "primitiveArgument", - targetClass = Public.class, - type = Open.Type.STATIC - ) - private static String publicPrimitiveArgument(int value) { - throw new RuntimeException(); - } - - @Test - void testPrimitiveArgument() { - assertEquals("5", publicPrimitiveArgument(5)); - } - - @Open( - name = "privateArgument", - targetClass = Public.class, - type = Open.Type.STATIC - ) - private static String publicPrivateArgument(@Coerce(targetName = "dev.lukebemish.opensesame.test.target.Public$Private") Object value) { - throw new RuntimeException(); - } - - @Test - void testPrivateArgument() { - assertEquals("Private1", publicPrivateArgument(privatePrivateConstructor())); - } - - @Open( - name = "arrayArgument", - targetClass = Public.class, - type = Open.Type.STATIC - ) - private static String publicArrayArgument(String[] value) { - throw new RuntimeException(); - } - - @Test - void testArrayArgument() { - assertEquals("a", publicArrayArgument(new String[]{"a", "b"})); - } - - @Open( - name = "hiddenByModules", - targetName = "dev.lukebemish.opensesame.test.target.hidden.Hidden", - type = Open.Type.STATIC, - unsafe = true - ) - private static String hiddenByModules() { - throw new RuntimeException(); - } - - @Open( - name = "hiddenByModulesPrivate", - targetName = "dev.lukebemish.opensesame.test.target.hidden.Hidden", - type = Open.Type.STATIC, - unsafe = true - ) - private static String hiddenByModulesPrivate() { - throw new RuntimeException(); - } - - @Test - void testModuleBreaking() { - assertEquals("hiddenByModules", hiddenByModules()); - assertEquals("hiddenByModulesPrivate", hiddenByModulesPrivate()); - assertThrows(IllegalAccessException.class, () -> { - Class hidden = Class.forName("dev.lukebemish.opensesame.test.target.hidden.Hidden"); - hidden.getDeclaredMethod("hiddenByModules").invoke(null); - }); - } - - @Open( - targetName = "dev.lukebemish.opensesame.test.target.Public$Private", - type = Open.Type.ARRAY - ) - private static Object[] privateArrayConstructor(int i) { - throw new RuntimeException(); - } - - @Test - void testPrivateArrayConstructor() { - Object[] array = privateArrayConstructor(2); - assertEquals(2, array.length); - array[0] = privatePrivateConstructor(); - assertEquals("Private", array[0].toString()); - assertThrows(ArrayStoreException.class, () -> { - array[1] = "stuff"; - }); - } -}