summaryrefslogtreecommitdiff
path: root/src/test/java/org
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-06-12 15:59:59 +0100
committerMichael Williamson <mike@zwobble.org>2026-06-12 16:05:11 +0100
commitaa725a130816f954b914e638381862d20d556af5 (patch)
treef0ba9bdb1aeecec5d50fd1c5ed9046552f49fe56 /src/test/java/org
parent466f13161c82289a17b761207da6bdfa4d78596c (diff)
Add visibility to Java methods
Diffstat (limited to 'src/test/java/org')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriterTests.java49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriterTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriterTests.java
index 65fa2a7..96166b0 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriterTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriterTests.java
@@ -117,6 +117,7 @@ public class JavaWriterTests {
List.of(
new JavaMethodDeclaration(
"a",
+ JavaVisibility.PUBLIC,
JavaMethodKind.INSTANCE,
JavaTypeRef.VOID,
List.of(),
@@ -124,6 +125,7 @@ public class JavaWriterTests {
),
new JavaMethodDeclaration(
"b",
+ JavaVisibility.PUBLIC,
JavaMethodKind.INSTANCE,
JavaTypeRef.VOID,
List.of(),
@@ -268,6 +270,7 @@ public class JavaWriterTests {
List.of(
new JavaMethodDeclaration(
"a",
+ JavaVisibility.PUBLIC,
JavaMethodKind.STATIC,
JavaTypeRef.VOID,
List.of(),
@@ -275,6 +278,7 @@ public class JavaWriterTests {
),
new JavaMethodDeclaration(
"b",
+ JavaVisibility.PUBLIC,
JavaMethodKind.STATIC,
JavaTypeRef.VOID,
List.of(),
@@ -400,6 +404,7 @@ public class JavaWriterTests {
List.of(
new JavaMethodDeclaration(
"a",
+ JavaVisibility.PUBLIC,
JavaMethodKind.INSTANCE,
JavaTypeRef.VOID,
List.of(),
@@ -407,6 +412,7 @@ public class JavaWriterTests {
),
new JavaMethodDeclaration(
"b",
+ JavaVisibility.PUBLIC,
JavaMethodKind.INSTANCE,
JavaTypeRef.VOID,
List.of(),
@@ -437,6 +443,7 @@ public class JavaWriterTests {
public void emptyMethodWithoutBody() throws IOException {
var java = new JavaMethodDeclaration(
"a",
+ JavaVisibility.PUBLIC,
JavaMethodKind.INSTANCE,
JavaTypeRef.VOID,
List.of(),
@@ -454,6 +461,7 @@ public class JavaWriterTests {
public void emptyInstanceMethod() throws IOException {
var java = new JavaMethodDeclaration(
"a",
+ JavaVisibility.PUBLIC,
JavaMethodKind.INSTANCE,
JavaTypeRef.VOID,
List.of(),
@@ -469,9 +477,48 @@ public class JavaWriterTests {
}
@Test
+ public void publicInstanceMethod() throws IOException {
+ var java = new JavaMethodDeclaration(
+ "a",
+ JavaVisibility.PUBLIC,
+ JavaMethodKind.INSTANCE,
+ JavaTypeRef.VOID,
+ List.of(),
+ JavaBlock.EMPTY
+ );
+
+ var string = write(writer -> writer.writeMethodDeclaration(java));
+
+ assertThat(string, equalTo("""
+ public void a() {
+ }"""
+ ));
+ }
+
+ @Test
+ public void privateInstanceMethod() throws IOException {
+ var java = new JavaMethodDeclaration(
+ "a",
+ JavaVisibility.PRIVATE,
+ JavaMethodKind.INSTANCE,
+ JavaTypeRef.VOID,
+ List.of(),
+ JavaBlock.EMPTY
+ );
+
+ var string = write(writer -> writer.writeMethodDeclaration(java));
+
+ assertThat(string, equalTo("""
+ private void a() {
+ }"""
+ ));
+ }
+
+ @Test
public void emptyStaticMethod() throws IOException {
var java = new JavaMethodDeclaration(
"a",
+ JavaVisibility.PUBLIC,
JavaMethodKind.STATIC,
JavaTypeRef.VOID,
List.of(),
@@ -490,6 +537,7 @@ public class JavaWriterTests {
public void methodWithParams() throws IOException {
var java = new JavaMethodDeclaration(
"a",
+ JavaVisibility.PUBLIC,
JavaMethodKind.INSTANCE,
JavaTypeRef.VOID,
List.of(
@@ -511,6 +559,7 @@ public class JavaWriterTests {
public void methodWithBody() throws IOException {
var java = new JavaMethodDeclaration(
"a",
+ JavaVisibility.PUBLIC,
JavaMethodKind.INSTANCE,
JavaTypeRef.INT,
List.of(),