From 4c3d300bcefb59e1474fd6daad512d542ed9225b Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Fri, 25 Jun 2021 11:29:26 -0700 Subject: [PATCH 1/7] add unit tests --- .../google_sign_in/android/build.gradle | 1 + .../plugins/googlesignin/GoogleSignInTest.java | 12 ++++++++++++ packages/local_auth/android/build.gradle | 1 + .../io/flutter/plugins/localauth/LocalAuthTest.java | 12 ++++++++++++ .../shared_preferences/android/build.gradle | 3 +++ .../sharedpreferences/SharedPreferencesTest.java | 12 ++++++++++++ .../video_player/video_player/android/build.gradle | 1 + .../flutter/plugins/videoplayer/VideoPlayerTest.java | 12 ++++++++++++ packages/webview_flutter/android/build.gradle | 1 + .../flutter/plugins/webviewflutter/WebViewTest.java | 12 ++++++++++++ 10 files changed, 67 insertions(+) create mode 100644 packages/google_sign_in/google_sign_in/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java create mode 100644 packages/local_auth/android/src/test/java/io/flutter/plugins/localauth/LocalAuthTest.java create mode 100644 packages/shared_preferences/shared_preferences/android/src/test/java/io/flutter/plugins/sharedpreferences/SharedPreferencesTest.java create mode 100644 packages/video_player/video_player/android/src/test/java/io/flutter/plugins/videoplayer/VideoPlayerTest.java create mode 100644 packages/webview_flutter/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewTest.java diff --git a/packages/google_sign_in/google_sign_in/android/build.gradle b/packages/google_sign_in/google_sign_in/android/build.gradle index a112470c3886..9d3982eebff9 100644 --- a/packages/google_sign_in/google_sign_in/android/build.gradle +++ b/packages/google_sign_in/google_sign_in/android/build.gradle @@ -36,4 +36,5 @@ android { dependencies { implementation 'com.google.android.gms:play-services-auth:16.0.1' implementation 'com.google.guava:guava:20.0' + testImplementation 'junit:junit:4.12' } diff --git a/packages/google_sign_in/google_sign_in/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java b/packages/google_sign_in/google_sign_in/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java new file mode 100644 index 000000000000..19d421fdf285 --- /dev/null +++ b/packages/google_sign_in/google_sign_in/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java @@ -0,0 +1,12 @@ +package io.flutter.plugins.googlesignin; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class GoogleSignInTest { + @Test + public void aTest() { + assertEquals(2, 2); + } +} \ No newline at end of file diff --git a/packages/local_auth/android/build.gradle b/packages/local_auth/android/build.gradle index 8878cfbcfc3e..db39428a31fe 100644 --- a/packages/local_auth/android/build.gradle +++ b/packages/local_auth/android/build.gradle @@ -37,6 +37,7 @@ dependencies { api "androidx.core:core:1.3.2" api "androidx.biometric:biometric:1.1.0" api "androidx.fragment:fragment:1.3.2" + testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test:rules:1.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' diff --git a/packages/local_auth/android/src/test/java/io/flutter/plugins/localauth/LocalAuthTest.java b/packages/local_auth/android/src/test/java/io/flutter/plugins/localauth/LocalAuthTest.java new file mode 100644 index 000000000000..6b7b84eea9a8 --- /dev/null +++ b/packages/local_auth/android/src/test/java/io/flutter/plugins/localauth/LocalAuthTest.java @@ -0,0 +1,12 @@ +package io.flutter.plugins.localauth; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class LocalAuthTest { + @Test + public void aTest() { + assertEquals(2, 2); + } +} diff --git a/packages/shared_preferences/shared_preferences/android/build.gradle b/packages/shared_preferences/shared_preferences/android/build.gradle index 4d2336436022..777042e0a1b1 100644 --- a/packages/shared_preferences/shared_preferences/android/build.gradle +++ b/packages/shared_preferences/shared_preferences/android/build.gradle @@ -39,4 +39,7 @@ android { lintOptions { disable 'InvalidPackage' } + dependencies { + testImplementation 'junit:junit:4.12' + } } diff --git a/packages/shared_preferences/shared_preferences/android/src/test/java/io/flutter/plugins/sharedpreferences/SharedPreferencesTest.java b/packages/shared_preferences/shared_preferences/android/src/test/java/io/flutter/plugins/sharedpreferences/SharedPreferencesTest.java new file mode 100644 index 000000000000..051b048d6704 --- /dev/null +++ b/packages/shared_preferences/shared_preferences/android/src/test/java/io/flutter/plugins/sharedpreferences/SharedPreferencesTest.java @@ -0,0 +1,12 @@ +package io.flutter.plugins.sharedpreferences; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class SharedPreferencesTest { + @Test + public void aTest() { + assertEquals(2, 2); + } +} \ No newline at end of file diff --git a/packages/video_player/video_player/android/build.gradle b/packages/video_player/video_player/android/build.gradle index 2f0f5c16c37a..9ab31e92f9dc 100644 --- a/packages/video_player/video_player/android/build.gradle +++ b/packages/video_player/video_player/android/build.gradle @@ -54,5 +54,6 @@ android { implementation 'com.google.android.exoplayer:exoplayer-hls:2.12.1' implementation 'com.google.android.exoplayer:exoplayer-dash:2.12.1' implementation 'com.google.android.exoplayer:exoplayer-smoothstreaming:2.12.1' + testImplementation 'junit:junit:4.12' } } diff --git a/packages/video_player/video_player/android/src/test/java/io/flutter/plugins/videoplayer/VideoPlayerTest.java b/packages/video_player/video_player/android/src/test/java/io/flutter/plugins/videoplayer/VideoPlayerTest.java new file mode 100644 index 000000000000..fad966df8876 --- /dev/null +++ b/packages/video_player/video_player/android/src/test/java/io/flutter/plugins/videoplayer/VideoPlayerTest.java @@ -0,0 +1,12 @@ +package io.flutter.plugins.videoplayer; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class VideoPlayerTest { + @Test + public void aTest() { + assertEquals(2, 2); + } +} \ No newline at end of file diff --git a/packages/webview_flutter/android/build.gradle b/packages/webview_flutter/android/build.gradle index 0ad39b773746..45f769b4bc59 100644 --- a/packages/webview_flutter/android/build.gradle +++ b/packages/webview_flutter/android/build.gradle @@ -36,5 +36,6 @@ android { dependencies { implementation 'androidx.annotation:annotation:1.0.0' implementation 'androidx.webkit:webkit:1.0.0' + testImplementation 'junit:junit:4.12' } } diff --git a/packages/webview_flutter/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewTest.java b/packages/webview_flutter/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewTest.java new file mode 100644 index 000000000000..97c4f69ee533 --- /dev/null +++ b/packages/webview_flutter/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewTest.java @@ -0,0 +1,12 @@ +package io.flutter.plugins.webviewflutter; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class WebViewTest { + @Test + public void aTest() { + assertEquals(2, 2); + } +} \ No newline at end of file From 3136f12c59848d6bd0a5fe60bac95ba83390c40e Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Fri, 25 Jun 2021 11:39:05 -0700 Subject: [PATCH 2/7] formatting --- .../io/flutter/plugins/googlesignin/GoogleSignInTest.java | 6 +++--- .../java/io/flutter/plugins/localauth/LocalAuthTest.java | 4 ++-- .../plugins/sharedpreferences/SharedPreferencesTest.java | 6 +++--- .../io/flutter/plugins/videoplayer/VideoPlayerTest.java | 6 +++--- .../java/io/flutter/plugins/webviewflutter/WebViewTest.java | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/google_sign_in/google_sign_in/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java b/packages/google_sign_in/google_sign_in/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java index 19d421fdf285..af5c558d8776 100644 --- a/packages/google_sign_in/google_sign_in/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java +++ b/packages/google_sign_in/google_sign_in/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java @@ -1,12 +1,12 @@ package io.flutter.plugins.googlesignin; -import org.junit.Test; - import static org.junit.Assert.assertEquals; +import org.junit.Test; + public class GoogleSignInTest { @Test public void aTest() { assertEquals(2, 2); } -} \ No newline at end of file +} diff --git a/packages/local_auth/android/src/test/java/io/flutter/plugins/localauth/LocalAuthTest.java b/packages/local_auth/android/src/test/java/io/flutter/plugins/localauth/LocalAuthTest.java index 6b7b84eea9a8..8617276b7cf8 100644 --- a/packages/local_auth/android/src/test/java/io/flutter/plugins/localauth/LocalAuthTest.java +++ b/packages/local_auth/android/src/test/java/io/flutter/plugins/localauth/LocalAuthTest.java @@ -1,9 +1,9 @@ package io.flutter.plugins.localauth; -import org.junit.Test; - import static org.junit.Assert.assertEquals; +import org.junit.Test; + public class LocalAuthTest { @Test public void aTest() { diff --git a/packages/shared_preferences/shared_preferences/android/src/test/java/io/flutter/plugins/sharedpreferences/SharedPreferencesTest.java b/packages/shared_preferences/shared_preferences/android/src/test/java/io/flutter/plugins/sharedpreferences/SharedPreferencesTest.java index 051b048d6704..c9bb32e0b433 100644 --- a/packages/shared_preferences/shared_preferences/android/src/test/java/io/flutter/plugins/sharedpreferences/SharedPreferencesTest.java +++ b/packages/shared_preferences/shared_preferences/android/src/test/java/io/flutter/plugins/sharedpreferences/SharedPreferencesTest.java @@ -1,12 +1,12 @@ package io.flutter.plugins.sharedpreferences; -import org.junit.Test; - import static org.junit.Assert.assertEquals; +import org.junit.Test; + public class SharedPreferencesTest { @Test public void aTest() { assertEquals(2, 2); } -} \ No newline at end of file +} diff --git a/packages/video_player/video_player/android/src/test/java/io/flutter/plugins/videoplayer/VideoPlayerTest.java b/packages/video_player/video_player/android/src/test/java/io/flutter/plugins/videoplayer/VideoPlayerTest.java index fad966df8876..9dcd90982723 100644 --- a/packages/video_player/video_player/android/src/test/java/io/flutter/plugins/videoplayer/VideoPlayerTest.java +++ b/packages/video_player/video_player/android/src/test/java/io/flutter/plugins/videoplayer/VideoPlayerTest.java @@ -1,12 +1,12 @@ package io.flutter.plugins.videoplayer; -import org.junit.Test; - import static org.junit.Assert.assertEquals; +import org.junit.Test; + public class VideoPlayerTest { @Test public void aTest() { assertEquals(2, 2); } -} \ No newline at end of file +} diff --git a/packages/webview_flutter/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewTest.java b/packages/webview_flutter/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewTest.java index 97c4f69ee533..d62788b25be4 100644 --- a/packages/webview_flutter/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewTest.java +++ b/packages/webview_flutter/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewTest.java @@ -1,12 +1,12 @@ package io.flutter.plugins.webviewflutter; -import org.junit.Test; - import static org.junit.Assert.assertEquals; +import org.junit.Test; + public class WebViewTest { @Test public void aTest() { assertEquals(2, 2); } -} \ No newline at end of file +} From 75c5e22ed17f52b95b8b60f6d5ac4d2205e5d2a3 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Fri, 25 Jun 2021 11:52:46 -0700 Subject: [PATCH 3/7] license --- .../io/flutter/plugins/googlesignin/GoogleSignInTest.java | 4 ++++ .../test/java/io/flutter/plugins/localauth/LocalAuthTest.java | 4 ++++ .../plugins/sharedpreferences/SharedPreferencesTest.java | 4 ++++ .../java/io/flutter/plugins/videoplayer/VideoPlayerTest.java | 4 ++++ .../java/io/flutter/plugins/webviewflutter/WebViewTest.java | 4 ++++ 5 files changed, 20 insertions(+) diff --git a/packages/google_sign_in/google_sign_in/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java b/packages/google_sign_in/google_sign_in/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java index af5c558d8776..67e8f802bfd9 100644 --- a/packages/google_sign_in/google_sign_in/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java +++ b/packages/google_sign_in/google_sign_in/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java @@ -1,3 +1,7 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + package io.flutter.plugins.googlesignin; import static org.junit.Assert.assertEquals; diff --git a/packages/local_auth/android/src/test/java/io/flutter/plugins/localauth/LocalAuthTest.java b/packages/local_auth/android/src/test/java/io/flutter/plugins/localauth/LocalAuthTest.java index 8617276b7cf8..3d3527e63142 100644 --- a/packages/local_auth/android/src/test/java/io/flutter/plugins/localauth/LocalAuthTest.java +++ b/packages/local_auth/android/src/test/java/io/flutter/plugins/localauth/LocalAuthTest.java @@ -1,3 +1,7 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + package io.flutter.plugins.localauth; import static org.junit.Assert.assertEquals; diff --git a/packages/shared_preferences/shared_preferences/android/src/test/java/io/flutter/plugins/sharedpreferences/SharedPreferencesTest.java b/packages/shared_preferences/shared_preferences/android/src/test/java/io/flutter/plugins/sharedpreferences/SharedPreferencesTest.java index c9bb32e0b433..61cdb23dd0b4 100644 --- a/packages/shared_preferences/shared_preferences/android/src/test/java/io/flutter/plugins/sharedpreferences/SharedPreferencesTest.java +++ b/packages/shared_preferences/shared_preferences/android/src/test/java/io/flutter/plugins/sharedpreferences/SharedPreferencesTest.java @@ -1,3 +1,7 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + package io.flutter.plugins.sharedpreferences; import static org.junit.Assert.assertEquals; diff --git a/packages/video_player/video_player/android/src/test/java/io/flutter/plugins/videoplayer/VideoPlayerTest.java b/packages/video_player/video_player/android/src/test/java/io/flutter/plugins/videoplayer/VideoPlayerTest.java index 9dcd90982723..34436f7e64f5 100644 --- a/packages/video_player/video_player/android/src/test/java/io/flutter/plugins/videoplayer/VideoPlayerTest.java +++ b/packages/video_player/video_player/android/src/test/java/io/flutter/plugins/videoplayer/VideoPlayerTest.java @@ -1,3 +1,7 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + package io.flutter.plugins.videoplayer; import static org.junit.Assert.assertEquals; diff --git a/packages/webview_flutter/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewTest.java b/packages/webview_flutter/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewTest.java index d62788b25be4..fa575159ec36 100644 --- a/packages/webview_flutter/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewTest.java +++ b/packages/webview_flutter/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewTest.java @@ -1,3 +1,7 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + package io.flutter.plugins.webviewflutter; import static org.junit.Assert.assertEquals; From 481f8561d12f47f7efc5c43e06bb4bcd89f3d967 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Mon, 28 Jun 2021 12:20:04 -0700 Subject: [PATCH 4/7] arbitrary tests --- .../google_sign_in/android/build.gradle | 1 + .../googlesignin/GoogleSignInTest.java | 18 +++++-- packages/local_auth/android/build.gradle | 1 + .../plugins/localauth/LocalAuthTest.java | 12 ++++- .../shared_preferences/android/build.gradle | 1 + .../video_player/android/build.gradle | 1 + .../webviewflutter/FlutterWebViewClient.java | 2 +- .../plugins/webviewflutter/WebViewTest.java | 53 ++++++++++++++++++- 8 files changed, 80 insertions(+), 9 deletions(-) diff --git a/packages/google_sign_in/google_sign_in/android/build.gradle b/packages/google_sign_in/google_sign_in/android/build.gradle index 9d3982eebff9..c95ba17c10d7 100644 --- a/packages/google_sign_in/google_sign_in/android/build.gradle +++ b/packages/google_sign_in/google_sign_in/android/build.gradle @@ -37,4 +37,5 @@ dependencies { implementation 'com.google.android.gms:play-services-auth:16.0.1' implementation 'com.google.guava:guava:20.0' testImplementation 'junit:junit:4.12' + testImplementation 'org.mockito:mockito-inline:3.9.0' } diff --git a/packages/google_sign_in/google_sign_in/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java b/packages/google_sign_in/google_sign_in/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java index 67e8f802bfd9..8eb9db7997e0 100644 --- a/packages/google_sign_in/google_sign_in/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java +++ b/packages/google_sign_in/google_sign_in/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java @@ -4,13 +4,23 @@ package io.flutter.plugins.googlesignin; -import static org.junit.Assert.assertEquals; +import android.content.Context; + +import static org.mockito.Mockito.mock; import org.junit.Test; +import io.flutter.plugin.common.BinaryMessenger; +import io.flutter.plugin.common.MethodCall; + public class GoogleSignInTest { - @Test - public void aTest() { - assertEquals(2, 2); + @Test(expected = IllegalStateException.class) + public void signInThrowsWithoutActivity() { + final GoogleSignInPlugin plugin = new GoogleSignInPlugin(); + plugin.initInstance(mock(BinaryMessenger.class), + mock(Context.class), + mock(GoogleSignInWrapper.class)); + + plugin.onMethodCall(new MethodCall("signIn", null), null); } } diff --git a/packages/local_auth/android/build.gradle b/packages/local_auth/android/build.gradle index db39428a31fe..4b0995e65946 100644 --- a/packages/local_auth/android/build.gradle +++ b/packages/local_auth/android/build.gradle @@ -38,6 +38,7 @@ dependencies { api "androidx.biometric:biometric:1.1.0" api "androidx.fragment:fragment:1.3.2" testImplementation 'junit:junit:4.12' + testImplementation 'org.mockito:mockito-inline:3.9.0' androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test:rules:1.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' diff --git a/packages/local_auth/android/src/test/java/io/flutter/plugins/localauth/LocalAuthTest.java b/packages/local_auth/android/src/test/java/io/flutter/plugins/localauth/LocalAuthTest.java index 3d3527e63142..a330ee1b383e 100644 --- a/packages/local_auth/android/src/test/java/io/flutter/plugins/localauth/LocalAuthTest.java +++ b/packages/local_auth/android/src/test/java/io/flutter/plugins/localauth/LocalAuthTest.java @@ -5,12 +5,20 @@ package io.flutter.plugins.localauth; import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import org.junit.Test; +import io.flutter.plugin.common.MethodCall; +import io.flutter.plugin.common.MethodChannel; + public class LocalAuthTest { @Test - public void aTest() { - assertEquals(2, 2); + public void isDeviceSupportedReturnsFalse() { + final LocalAuthPlugin plugin = new LocalAuthPlugin(); + final MethodChannel.Result mockResult = mock(MethodChannel.Result.class); + plugin.onMethodCall(new MethodCall("isDeviceSupported", null), mockResult); + verify(mockResult).success(false); } } diff --git a/packages/shared_preferences/shared_preferences/android/build.gradle b/packages/shared_preferences/shared_preferences/android/build.gradle index 777042e0a1b1..9f7eeca84512 100644 --- a/packages/shared_preferences/shared_preferences/android/build.gradle +++ b/packages/shared_preferences/shared_preferences/android/build.gradle @@ -41,5 +41,6 @@ android { } dependencies { testImplementation 'junit:junit:4.12' + testImplementation 'org.mockito:mockito-inline:3.9.0' } } diff --git a/packages/video_player/video_player/android/build.gradle b/packages/video_player/video_player/android/build.gradle index 9ab31e92f9dc..558b4123be11 100644 --- a/packages/video_player/video_player/android/build.gradle +++ b/packages/video_player/video_player/android/build.gradle @@ -55,5 +55,6 @@ android { implementation 'com.google.android.exoplayer:exoplayer-dash:2.12.1' implementation 'com.google.android.exoplayer:exoplayer-smoothstreaming:2.12.1' testImplementation 'junit:junit:4.12' + testImplementation 'org.mockito:mockito-inline:3.9.0' } } diff --git a/packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterWebViewClient.java b/packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterWebViewClient.java index 148be952db6e..4e7056f1468c 100644 --- a/packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterWebViewClient.java +++ b/packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterWebViewClient.java @@ -36,7 +36,7 @@ class FlutterWebViewClient { this.methodChannel = methodChannel; } - private static String errorCodeToString(int errorCode) { + static String errorCodeToString(int errorCode) { switch (errorCode) { case WebViewClient.ERROR_AUTHENTICATION: return "authentication"; diff --git a/packages/webview_flutter/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewTest.java b/packages/webview_flutter/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewTest.java index fa575159ec36..1e646655c500 100644 --- a/packages/webview_flutter/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewTest.java +++ b/packages/webview_flutter/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewTest.java @@ -4,13 +4,62 @@ package io.flutter.plugins.webviewflutter; +import android.webkit.WebViewClient; + import static org.junit.Assert.assertEquals; import org.junit.Test; public class WebViewTest { @Test - public void aTest() { - assertEquals(2, 2); + public void errorCodes() { + assertEquals( + FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_AUTHENTICATION), + "authentication"); + assertEquals( + FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_BAD_URL), + "badUrl"); + assertEquals( + FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_CONNECT), + "connect"); + assertEquals( + FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_FAILED_SSL_HANDSHAKE), + "failedSslHandshake"); + assertEquals( + FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_FILE), + "file"); + assertEquals( + FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_FILE_NOT_FOUND), + "fileNotFound"); + assertEquals( + FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_HOST_LOOKUP), + "hostLookup"); + assertEquals( + FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_IO), + "io"); + assertEquals( + FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_PROXY_AUTHENTICATION), + "proxyAuthentication"); + assertEquals( + FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_REDIRECT_LOOP), + "redirectLoop"); + assertEquals( + FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_TIMEOUT), + "timeout"); + assertEquals( + FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_TOO_MANY_REQUESTS), + "tooManyRequests"); + assertEquals( + FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_UNKNOWN), + "unknown"); + assertEquals( + FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_UNSAFE_RESOURCE), + "unsafeResource"); + assertEquals( + FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_UNSUPPORTED_AUTH_SCHEME), + "unsupportedAuthScheme"); + assertEquals( + FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_UNSUPPORTED_SCHEME), + "unsupportedScheme"); } } From 1c88867ea3b3e4a02e430011ea36c8c10be2c4dc Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Mon, 28 Jun 2021 12:24:17 -0700 Subject: [PATCH 5/7] formatting and initializing plugins in tests --- .../googlesignin/GoogleSignInTest.java | 11 +++--- .../plugins/localauth/LocalAuthTest.java | 6 ++-- .../SharedPreferencesTest.java | 6 ++-- .../plugins/videoplayer/VideoPlayerTest.java | 5 ++- .../plugins/webviewflutter/WebViewTest.java | 36 ++++++------------- 5 files changed, 20 insertions(+), 44 deletions(-) diff --git a/packages/google_sign_in/google_sign_in/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java b/packages/google_sign_in/google_sign_in/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java index 8eb9db7997e0..4e7be75aa7cf 100644 --- a/packages/google_sign_in/google_sign_in/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java +++ b/packages/google_sign_in/google_sign_in/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java @@ -4,22 +4,19 @@ package io.flutter.plugins.googlesignin; -import android.content.Context; - import static org.mockito.Mockito.mock; -import org.junit.Test; - +import android.content.Context; import io.flutter.plugin.common.BinaryMessenger; import io.flutter.plugin.common.MethodCall; +import org.junit.Test; public class GoogleSignInTest { @Test(expected = IllegalStateException.class) public void signInThrowsWithoutActivity() { final GoogleSignInPlugin plugin = new GoogleSignInPlugin(); - plugin.initInstance(mock(BinaryMessenger.class), - mock(Context.class), - mock(GoogleSignInWrapper.class)); + plugin.initInstance( + mock(BinaryMessenger.class), mock(Context.class), mock(GoogleSignInWrapper.class)); plugin.onMethodCall(new MethodCall("signIn", null), null); } diff --git a/packages/local_auth/android/src/test/java/io/flutter/plugins/localauth/LocalAuthTest.java b/packages/local_auth/android/src/test/java/io/flutter/plugins/localauth/LocalAuthTest.java index a330ee1b383e..522185fc9dd3 100644 --- a/packages/local_auth/android/src/test/java/io/flutter/plugins/localauth/LocalAuthTest.java +++ b/packages/local_auth/android/src/test/java/io/flutter/plugins/localauth/LocalAuthTest.java @@ -4,20 +4,18 @@ package io.flutter.plugins.localauth; -import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import org.junit.Test; - import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodChannel; +import org.junit.Test; public class LocalAuthTest { @Test public void isDeviceSupportedReturnsFalse() { final LocalAuthPlugin plugin = new LocalAuthPlugin(); - final MethodChannel.Result mockResult = mock(MethodChannel.Result.class); + final MethodChannel.Result mockResult = mock(MethodChannel.Result.class); plugin.onMethodCall(new MethodCall("isDeviceSupported", null), mockResult); verify(mockResult).success(false); } diff --git a/packages/shared_preferences/shared_preferences/android/src/test/java/io/flutter/plugins/sharedpreferences/SharedPreferencesTest.java b/packages/shared_preferences/shared_preferences/android/src/test/java/io/flutter/plugins/sharedpreferences/SharedPreferencesTest.java index 61cdb23dd0b4..50fa98893eb0 100644 --- a/packages/shared_preferences/shared_preferences/android/src/test/java/io/flutter/plugins/sharedpreferences/SharedPreferencesTest.java +++ b/packages/shared_preferences/shared_preferences/android/src/test/java/io/flutter/plugins/sharedpreferences/SharedPreferencesTest.java @@ -4,13 +4,11 @@ package io.flutter.plugins.sharedpreferences; -import static org.junit.Assert.assertEquals; - import org.junit.Test; public class SharedPreferencesTest { @Test - public void aTest() { - assertEquals(2, 2); + public void initPlugin() { + final SharedPreferencesPlugin plugin = new SharedPreferencesPlugin(); } } diff --git a/packages/video_player/video_player/android/src/test/java/io/flutter/plugins/videoplayer/VideoPlayerTest.java b/packages/video_player/video_player/android/src/test/java/io/flutter/plugins/videoplayer/VideoPlayerTest.java index 34436f7e64f5..81dcf5830a1a 100644 --- a/packages/video_player/video_player/android/src/test/java/io/flutter/plugins/videoplayer/VideoPlayerTest.java +++ b/packages/video_player/video_player/android/src/test/java/io/flutter/plugins/videoplayer/VideoPlayerTest.java @@ -4,13 +4,12 @@ package io.flutter.plugins.videoplayer; -import static org.junit.Assert.assertEquals; import org.junit.Test; public class VideoPlayerTest { @Test - public void aTest() { - assertEquals(2, 2); + public void initPlugin() { + final VideoPlayerPlugin plugin = new VideoPlayerPlugin(); } } diff --git a/packages/webview_flutter/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewTest.java b/packages/webview_flutter/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewTest.java index 1e646655c500..131a5a3eb53a 100644 --- a/packages/webview_flutter/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewTest.java +++ b/packages/webview_flutter/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewTest.java @@ -4,10 +4,9 @@ package io.flutter.plugins.webviewflutter; -import android.webkit.WebViewClient; - import static org.junit.Assert.assertEquals; +import android.webkit.WebViewClient; import org.junit.Test; public class WebViewTest { @@ -16,42 +15,27 @@ public void errorCodes() { assertEquals( FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_AUTHENTICATION), "authentication"); - assertEquals( - FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_BAD_URL), - "badUrl"); - assertEquals( - FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_CONNECT), - "connect"); + assertEquals(FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_BAD_URL), "badUrl"); + assertEquals(FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_CONNECT), "connect"); assertEquals( FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_FAILED_SSL_HANDSHAKE), "failedSslHandshake"); + assertEquals(FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_FILE), "file"); assertEquals( - FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_FILE), - "file"); + FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_FILE_NOT_FOUND), "fileNotFound"); assertEquals( - FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_FILE_NOT_FOUND), - "fileNotFound"); - assertEquals( - FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_HOST_LOOKUP), - "hostLookup"); - assertEquals( - FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_IO), - "io"); + FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_HOST_LOOKUP), "hostLookup"); + assertEquals(FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_IO), "io"); assertEquals( FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_PROXY_AUTHENTICATION), "proxyAuthentication"); assertEquals( - FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_REDIRECT_LOOP), - "redirectLoop"); - assertEquals( - FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_TIMEOUT), - "timeout"); + FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_REDIRECT_LOOP), "redirectLoop"); + assertEquals(FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_TIMEOUT), "timeout"); assertEquals( FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_TOO_MANY_REQUESTS), "tooManyRequests"); - assertEquals( - FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_UNKNOWN), - "unknown"); + assertEquals(FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_UNKNOWN), "unknown"); assertEquals( FlutterWebViewClient.errorCodeToString(WebViewClient.ERROR_UNSAFE_RESOURCE), "unsafeResource"); From c08e287397c0facc7c87dac71b2448032d56ef67 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Mon, 28 Jun 2021 19:41:44 -0700 Subject: [PATCH 6/7] Update packages/video_player/video_player/android/src/test/java/io/flutter/plugins/videoplayer/VideoPlayerTest.java Co-authored-by: Emmanuel Garcia --- .../java/io/flutter/plugins/videoplayer/VideoPlayerTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/video_player/video_player/android/src/test/java/io/flutter/plugins/videoplayer/VideoPlayerTest.java b/packages/video_player/video_player/android/src/test/java/io/flutter/plugins/videoplayer/VideoPlayerTest.java index 81dcf5830a1a..319fd0a2231d 100644 --- a/packages/video_player/video_player/android/src/test/java/io/flutter/plugins/videoplayer/VideoPlayerTest.java +++ b/packages/video_player/video_player/android/src/test/java/io/flutter/plugins/videoplayer/VideoPlayerTest.java @@ -3,8 +3,6 @@ // found in the LICENSE file. package io.flutter.plugins.videoplayer; - - import org.junit.Test; public class VideoPlayerTest { From 907988990a9d1e0a7b52ce6556721ad7ba050e09 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Mon, 28 Jun 2021 19:47:23 -0700 Subject: [PATCH 7/7] add comment about tests --- .../plugins/sharedpreferences/SharedPreferencesTest.java | 3 ++- .../java/io/flutter/plugins/videoplayer/VideoPlayerTest.java | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/shared_preferences/shared_preferences/android/src/test/java/io/flutter/plugins/sharedpreferences/SharedPreferencesTest.java b/packages/shared_preferences/shared_preferences/android/src/test/java/io/flutter/plugins/sharedpreferences/SharedPreferencesTest.java index 50fa98893eb0..13d0ff8b40c1 100644 --- a/packages/shared_preferences/shared_preferences/android/src/test/java/io/flutter/plugins/sharedpreferences/SharedPreferencesTest.java +++ b/packages/shared_preferences/shared_preferences/android/src/test/java/io/flutter/plugins/sharedpreferences/SharedPreferencesTest.java @@ -7,8 +7,9 @@ import org.junit.Test; public class SharedPreferencesTest { + // This is only a placeholder test and doesn't actually initialize the plugin. @Test - public void initPlugin() { + public void initPluginDoesNotThrow() { final SharedPreferencesPlugin plugin = new SharedPreferencesPlugin(); } } diff --git a/packages/video_player/video_player/android/src/test/java/io/flutter/plugins/videoplayer/VideoPlayerTest.java b/packages/video_player/video_player/android/src/test/java/io/flutter/plugins/videoplayer/VideoPlayerTest.java index 319fd0a2231d..ec960b7a4480 100644 --- a/packages/video_player/video_player/android/src/test/java/io/flutter/plugins/videoplayer/VideoPlayerTest.java +++ b/packages/video_player/video_player/android/src/test/java/io/flutter/plugins/videoplayer/VideoPlayerTest.java @@ -3,11 +3,13 @@ // found in the LICENSE file. package io.flutter.plugins.videoplayer; + import org.junit.Test; public class VideoPlayerTest { + // This is only a placeholder test and doesn't actually initialize the plugin. @Test - public void initPlugin() { + public void initPluginDoesNotThrow() { final VideoPlayerPlugin plugin = new VideoPlayerPlugin(); } }