Skip to content

Commit 94caa8a

Browse files
Add Basic Junit Tests to some plugins (flutter#4108)
1 parent 03f9b49 commit 94caa8a

File tree

11 files changed

+136
-1
lines changed

11 files changed

+136
-1
lines changed

packages/google_sign_in/google_sign_in/android/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,6 @@ android {
3636
dependencies {
3737
implementation 'com.google.android.gms:play-services-auth:16.0.1'
3838
implementation 'com.google.guava:guava:20.0'
39+
testImplementation 'junit:junit:4.12'
40+
testImplementation 'org.mockito:mockito-inline:3.9.0'
3941
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package io.flutter.plugins.googlesignin;
6+
7+
import static org.mockito.Mockito.mock;
8+
9+
import android.content.Context;
10+
import io.flutter.plugin.common.BinaryMessenger;
11+
import io.flutter.plugin.common.MethodCall;
12+
import org.junit.Test;
13+
14+
public class GoogleSignInTest {
15+
@Test(expected = IllegalStateException.class)
16+
public void signInThrowsWithoutActivity() {
17+
final GoogleSignInPlugin plugin = new GoogleSignInPlugin();
18+
plugin.initInstance(
19+
mock(BinaryMessenger.class), mock(Context.class), mock(GoogleSignInWrapper.class));
20+
21+
plugin.onMethodCall(new MethodCall("signIn", null), null);
22+
}
23+
}

packages/local_auth/android/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ dependencies {
3737
api "androidx.core:core:1.3.2"
3838
api "androidx.biometric:biometric:1.1.0"
3939
api "androidx.fragment:fragment:1.3.2"
40+
testImplementation 'junit:junit:4.12'
41+
testImplementation 'org.mockito:mockito-inline:3.9.0'
4042
androidTestImplementation 'androidx.test:runner:1.2.0'
4143
androidTestImplementation 'androidx.test:rules:1.2.0'
4244
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package io.flutter.plugins.localauth;
6+
7+
import static org.mockito.Mockito.mock;
8+
import static org.mockito.Mockito.verify;
9+
10+
import io.flutter.plugin.common.MethodCall;
11+
import io.flutter.plugin.common.MethodChannel;
12+
import org.junit.Test;
13+
14+
public class LocalAuthTest {
15+
@Test
16+
public void isDeviceSupportedReturnsFalse() {
17+
final LocalAuthPlugin plugin = new LocalAuthPlugin();
18+
final MethodChannel.Result mockResult = mock(MethodChannel.Result.class);
19+
plugin.onMethodCall(new MethodCall("isDeviceSupported", null), mockResult);
20+
verify(mockResult).success(false);
21+
}
22+
}

packages/shared_preferences/shared_preferences/android/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,8 @@ android {
3939
lintOptions {
4040
disable 'InvalidPackage'
4141
}
42+
dependencies {
43+
testImplementation 'junit:junit:4.12'
44+
testImplementation 'org.mockito:mockito-inline:3.9.0'
45+
}
4246
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package io.flutter.plugins.sharedpreferences;
6+
7+
import org.junit.Test;
8+
9+
public class SharedPreferencesTest {
10+
// This is only a placeholder test and doesn't actually initialize the plugin.
11+
@Test
12+
public void initPluginDoesNotThrow() {
13+
final SharedPreferencesPlugin plugin = new SharedPreferencesPlugin();
14+
}
15+
}

packages/video_player/video_player/android/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,7 @@ android {
5454
implementation 'com.google.android.exoplayer:exoplayer-hls:2.12.1'
5555
implementation 'com.google.android.exoplayer:exoplayer-dash:2.12.1'
5656
implementation 'com.google.android.exoplayer:exoplayer-smoothstreaming:2.12.1'
57+
testImplementation 'junit:junit:4.12'
58+
testImplementation 'org.mockito:mockito-inline:3.9.0'
5759
}
5860
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package io.flutter.plugins.videoplayer;
6+
7+
import org.junit.Test;
8+
9+
public class VideoPlayerTest {
10+
// This is only a placeholder test and doesn't actually initialize the plugin.
11+
@Test
12+
public void initPluginDoesNotThrow() {
13+
final VideoPlayerPlugin plugin = new VideoPlayerPlugin();
14+
}
15+
}

packages/webview_flutter/android/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ android {
3636
dependencies {
3737
implementation 'androidx.annotation:annotation:1.0.0'
3838
implementation 'androidx.webkit:webkit:1.0.0'
39+
testImplementation 'junit:junit:4.12'
3940
}
4041
}

packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterWebViewClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class FlutterWebViewClient {
3636
this.methodChannel = methodChannel;
3737
}
3838

39-
private static String errorCodeToString(int errorCode) {
39+
static String errorCodeToString(int errorCode) {
4040
switch (errorCode) {
4141
case WebViewClient.ERROR_AUTHENTICATION:
4242
return "authentication";
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package io.flutter.plugins.webviewflutter;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
import android.webkit.WebViewClient;
10+
import org.junit.Test;
11+
12+
public class WebViewTest {
13+
@Test
14+
public void errorCodes() {
15+
assertEquals(
16+
FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_AUTHENTICATION),
17+
"authentication");
18+
assertEquals(FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_BAD_URL), "badUrl");
19+
assertEquals(FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_CONNECT), "connect");
20+
assertEquals(
21+
FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_FAILED_SSL_HANDSHAKE),
22+
"failedSslHandshake");
23+
assertEquals(FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_FILE), "file");
24+
assertEquals(
25+
FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_FILE_NOT_FOUND), "fileNotFound");
26+
assertEquals(
27+
FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_HOST_LOOKUP), "hostLookup");
28+
assertEquals(FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_IO), "io");
29+
assertEquals(
30+
FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_PROXY_AUTHENTICATION),
31+
"proxyAuthentication");
32+
assertEquals(
33+
FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_REDIRECT_LOOP), "redirectLoop");
34+
assertEquals(FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_TIMEOUT), "timeout");
35+
assertEquals(
36+
FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_TOO_MANY_REQUESTS),
37+
"tooManyRequests");
38+
assertEquals(FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_UNKNOWN), "unknown");
39+
assertEquals(
40+
FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_UNSAFE_RESOURCE),
41+
"unsafeResource");
42+
assertEquals(
43+
FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_UNSUPPORTED_AUTH_SCHEME),
44+
"unsupportedAuthScheme");
45+
assertEquals(
46+
FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_UNSUPPORTED_SCHEME),
47+
"unsupportedScheme");
48+
}
49+
}

0 commit comments

Comments
 (0)