Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Add Basic Junit Tests to some plugins #4108

Merged
merged 7 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/google_sign_in/google_sign_in/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ 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'
testImplementation 'org.mockito:mockito-inline:3.9.0'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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.mockito.Mockito.mock;

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.onMethodCall(new MethodCall("signIn", null), null);
}
}
2 changes: 2 additions & 0 deletions packages/local_auth/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ 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'
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'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

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);
plugin.onMethodCall(new MethodCall("isDeviceSupported", null), mockResult);
verify(mockResult).success(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ android {
lintOptions {
disable 'InvalidPackage'
}
dependencies {
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-inline:3.9.0'
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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 org.junit.Test;

public class SharedPreferencesTest {
// This is only a placeholder test and doesn't actually initialize the plugin.
@Test
public void initPluginDoesNotThrow() {
final SharedPreferencesPlugin plugin = new SharedPreferencesPlugin();
}
}
2 changes: 2 additions & 0 deletions packages/video_player/video_player/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,7 @@ 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'
testImplementation 'org.mockito:mockito-inline:3.9.0'
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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 org.junit.Test;

public class VideoPlayerTest {
// This is only a placeholder test and doesn't actually initialize the plugin.
@Test
public void initPluginDoesNotThrow() {
final VideoPlayerPlugin plugin = new VideoPlayerPlugin();
}
}
1 change: 1 addition & 0 deletions packages/webview_flutter/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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;

import android.webkit.WebViewClient;
import org.junit.Test;

public class WebViewTest {
@Test
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");
}
}