Skip to content

Commit

Permalink
Rearrange tests and fix dependency submission
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebemish committed Nov 18, 2023
1 parent 587cc38 commit ecc1f00
Show file tree
Hide file tree
Showing 13 changed files with 1,071 additions and 1,004 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ jobs:
uses: mikepenz/[email protected]
with:
gradle-build-module: |-
:annotations
:runtime
:compile
:groovy
:javac
:opensesame-annotations
:opensesame-runtime
:opensesame-compile
:opensesame-groovy
:opensesame-javac
gradle-build-configuration: |-
compileClasspath
10 changes: 5 additions & 5 deletions .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ jobs:
uses: mikepenz/[email protected]
with:
gradle-build-module: |-
:annotations
:runtime
:compile
:groovy
:javac
:opensesame-annotations
:opensesame-runtime
:opensesame-compile
:opensesame-groovy
:opensesame-javac
gradle-build-configuration: |-
compileClasspath
Original file line number Diff line number Diff line change
@@ -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()))
}
}
Original file line number Diff line number Diff line change
@@ -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"
})
}
}
Loading

0 comments on commit ecc1f00

Please sign in to comment.