From dd7077e64e8825a41fd1bfcd75ddde93263d45a0 Mon Sep 17 00:00:00 2001 From: Jacob Clark Date: Tue, 30 Jun 2020 23:11:37 +0100 Subject: [PATCH] test(android): add tests for PluginMethodHandler (#3153) --- android/capacitor/build.gradle | 3 +- .../getcapacitor/PluginMethodHandleTest.java | 44 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 android/capacitor/src/test/java/com/getcapacitor/PluginMethodHandleTest.java diff --git a/android/capacitor/build.gradle b/android/capacitor/build.gradle index 34262e4f9..d4e4fd028 100644 --- a/android/capacitor/build.gradle +++ b/android/capacitor/build.gradle @@ -71,4 +71,5 @@ dependencies { androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion" implementation "org.apache.cordova:framework:$cordovaAndroidVersion" testImplementation 'org.json:json:20140107' -} \ No newline at end of file + testImplementation 'org.mockito:mockito-inline:2.13.0' +} diff --git a/android/capacitor/src/test/java/com/getcapacitor/PluginMethodHandleTest.java b/android/capacitor/src/test/java/com/getcapacitor/PluginMethodHandleTest.java new file mode 100644 index 000000000..1c4aeee37 --- /dev/null +++ b/android/capacitor/src/test/java/com/getcapacitor/PluginMethodHandleTest.java @@ -0,0 +1,44 @@ +package com.getcapacitor; + +import org.junit.Test; + +import java.lang.reflect.Method; + +import static org.junit.Assert.assertEquals; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; + +public class PluginMethodHandleTest { + @Test + public void getNameReturnsMethodName() { + PluginMethod pluginMethod = mock(PluginMethod.class); + Method mockMethod = mock(Method.class); + + given(mockMethod.getName()).willReturn("methodName"); + PluginMethodHandle pluginMethodHandle = new PluginMethodHandle(mockMethod, pluginMethod); + + assertEquals(pluginMethodHandle.getName(), "methodName"); + } + + @Test + public void getMethodHandleReturnsMethodHandle() { + PluginMethod pluginMethod = mock(PluginMethod.class); + Method mockMethod = mock(Method.class); + + given(pluginMethod.returnType()).willReturn("returnType"); + PluginMethodHandle pluginMethodHandle = new PluginMethodHandle(mockMethod, pluginMethod); + + assertEquals(pluginMethodHandle.getReturnType(), "returnType"); + } + + + @Test + public void getMethodReturnsMethod() { + PluginMethod pluginMethod = mock(PluginMethod.class); + Method mockMethod = mock(Method.class); + + PluginMethodHandle pluginMethodHandle = new PluginMethodHandle(mockMethod, pluginMethod); + + assertEquals(pluginMethodHandle.getMethod(), mockMethod); + } +}