diff --git a/launcher/bootstrap/build.gradle.kts b/launcher/bootstrap/build.gradle.kts index 5ea0057..b071501 100644 --- a/launcher/bootstrap/build.gradle.kts +++ b/launcher/bootstrap/build.gradle.kts @@ -62,3 +62,11 @@ tasks.named("jar") { // it's first on SK's classpath and would shadow the real frenchpress. exclude("co/frenchpress/**") } + +dependencies { + testImplementation("junit:junit:4.13.2") +} + +tasks.named("test") { + useJUnit() +} diff --git a/launcher/bootstrap/src/test/java/com/skarm/launcher/bootstrap/NativeBridgePromptTest.java b/launcher/bootstrap/src/test/java/com/skarm/launcher/bootstrap/NativeBridgePromptTest.java new file mode 100644 index 0000000..ddfaf34 --- /dev/null +++ b/launcher/bootstrap/src/test/java/com/skarm/launcher/bootstrap/NativeBridgePromptTest.java @@ -0,0 +1,62 @@ +package com.skarm.launcher.bootstrap; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import java.lang.reflect.Method; + +public class NativeBridgePromptTest { + + @Test + public void testInvokeWithNullMethod() throws Exception { + Method invokeMethod = NativeBridgePrompt.class.getDeclaredMethod("invoke", Method.class, Object[].class); + invokeMethod.setAccessible(true); + + String result = (String) invokeMethod.invoke(null, null, new Object[0]); + assertEquals("", result); + } + + @Test + public void testInvokeWithMethodThrowingException() throws Exception { + Method invokeMethod = NativeBridgePrompt.class.getDeclaredMethod("invoke", Method.class, Object[].class); + invokeMethod.setAccessible(true); + + Method throwingMethod = NativeBridgePromptTest.class.getDeclaredMethod("throwingMethod"); + + String result = (String) invokeMethod.invoke(null, throwingMethod, new Object[0]); + assertEquals("", result); + } + + @Test + public void testInvokeWithValidMethod() throws Exception { + Method invokeMethod = NativeBridgePrompt.class.getDeclaredMethod("invoke", Method.class, Object[].class); + invokeMethod.setAccessible(true); + + Method validMethod = NativeBridgePromptTest.class.getDeclaredMethod("validMethod"); + + String result = (String) invokeMethod.invoke(null, validMethod, new Object[0]); + assertEquals("success", result); + } + + @Test + public void testInvokeWithNullReturn() throws Exception { + Method invokeMethod = NativeBridgePrompt.class.getDeclaredMethod("invoke", Method.class, Object[].class); + invokeMethod.setAccessible(true); + + Method nullReturnMethod = NativeBridgePromptTest.class.getDeclaredMethod("nullReturnMethod"); + + String result = (String) invokeMethod.invoke(null, nullReturnMethod, new Object[0]); + assertEquals("", result); + } + + public static String throwingMethod() { + throw new RuntimeException("Test exception"); + } + + public static String validMethod() { + return "success"; + } + + public static String nullReturnMethod() { + return null; + } +}