Skip to content

Commit 9f588d2

Browse files
authored
Merge pull request #1 from jwson-automation/patch-1
fix: update unit tests to test actual plugin methods ( delete getPlatformVersion in test code )
2 parents 0bd9db0 + 175b432 commit 9f588d2

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

android/src/test/kotlin/dev/openflutter/flutter_advertising_id/FlutterAdvertisingIdPluginTest.kt

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dev.openflutter.flutter_advertising_id
22

3+
import android.content.Context
34
import io.flutter.plugin.common.MethodCall
45
import io.flutter.plugin.common.MethodChannel
56
import kotlin.test.Test
@@ -12,16 +13,48 @@ import org.mockito.Mockito
1213
* line by running `./gradlew testDebugUnitTest` in the `example/android/` directory, or
1314
* you can run them directly from IDEs that support JUnit such as Android Studio.
1415
*/
15-
1616
internal class FlutterAdvertisingIdPluginTest {
1717
@Test
18-
fun onMethodCall_getPlatformVersion_returnsExpectedValue() {
18+
fun onMethodCall_getAdvertisingId_withoutContext_returnsNull() {
19+
val plugin = FlutterAdvertisingIdPlugin()
20+
21+
val call = MethodCall("getAdvertisingId", false)
22+
val mockResult: MethodChannel.Result = Mockito.mock(MethodChannel.Result::class.java)
23+
plugin.onMethodCall(call, mockResult)
24+
25+
Mockito.verify(mockResult).success(null)
26+
}
27+
28+
@Test
29+
fun onMethodCall_limitAdTrackingEnabled_withoutContext_returnsNull() {
30+
val plugin = FlutterAdvertisingIdPlugin()
31+
32+
val call = MethodCall("limitAdTrackingEnabled", null)
33+
val mockResult: MethodChannel.Result = Mockito.mock(MethodChannel.Result::class.java)
34+
plugin.onMethodCall(call, mockResult)
35+
36+
Mockito.verify(mockResult).success(null)
37+
}
38+
39+
@Test
40+
fun onMethodCall_authorizationStatus_returnsAuthorized() {
41+
val plugin = FlutterAdvertisingIdPlugin()
42+
43+
val call = MethodCall("authorizationStatus", null)
44+
val mockResult: MethodChannel.Result = Mockito.mock(MethodChannel.Result::class.java)
45+
plugin.onMethodCall(call, mockResult)
46+
47+
Mockito.verify(mockResult).success(3)
48+
}
49+
50+
@Test
51+
fun onMethodCall_unknownMethod_returnsNotImplemented() {
1952
val plugin = FlutterAdvertisingIdPlugin()
2053

21-
val call = MethodCall("getPlatformVersion", null)
54+
val call = MethodCall("unknownMethod", null)
2255
val mockResult: MethodChannel.Result = Mockito.mock(MethodChannel.Result::class.java)
2356
plugin.onMethodCall(call, mockResult)
2457

25-
Mockito.verify(mockResult).success("Android " + android.os.Build.VERSION.RELEASE)
58+
Mockito.verify(mockResult).notImplemented()
2659
}
2760
}

0 commit comments

Comments
 (0)