Skip to content

Commit

Permalink
CASL-534 access-based test
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Amanowicz <[email protected]>
  • Loading branch information
Amaneusz committed Sep 26, 2024
1 parent bf53851 commit 159a8a6
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

import kotlin.reflect.full.IllegalCallableAccessException;
import org.junit.jupiter.api.Test;

class JavaProxyTest {
Expand All @@ -32,7 +33,7 @@ void shouldAllowProxyingInJava() {
ProxyParent parent = new ProxyParent();

// When:
var child = parent.proxy(Platform.klassOf(ProxyParent.class));
var child = parent.proxy(Platform.klassOf(ProxyChild.class));

// Then:
assertNotNull(child);
Expand All @@ -50,9 +51,26 @@ void shouldFailForProxyWithoutNonArgConstructor() {
});
}

@Test
void shouldFailForProxyWithUnsifficientVisibility() {
// Given:
ProxyParent parent = new ProxyParent();

// Then:
assertThrows(IllegalCallableAccessException.class, () -> {
parent.proxy(Platform.klassOf(ProxyChildWithoutPublicConstructor.class));
});
}

static class ProxyParent extends AnyObject {}

static class ProxyChild extends ProxyParent {}
public static class ProxyChild extends ProxyParent {}

public static class ProxyChildWithoutPublicConstructor extends ProxyParent {
ProxyChildWithoutPublicConstructor() {
// hello from package-private
}
}

static class ProxyChildWithoutNonArgConstructor extends ProxyParent {
ProxyChildWithoutNonArgConstructor(String unusedParam) {}
Expand Down

0 comments on commit 159a8a6

Please sign in to comment.