From 08023b2aeaacc9aa698ffd695c513846bffe21bc Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Mon, 6 Dec 2021 21:04:59 +0100 Subject: [PATCH] Apply PR feedback --- .../FlutterAssetManagerHostApiImpl.java | 6 ++++++ .../FlutterAssetManagerHostApiImplTest.java | 15 +++++++++++++++ .../webview_flutter_android/pubspec.yaml | 7 +------ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterAssetManagerHostApiImpl.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterAssetManagerHostApiImpl.java index f15d78d53d2b..791912adb815 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterAssetManagerHostApiImpl.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterAssetManagerHostApiImpl.java @@ -7,6 +7,7 @@ import android.webkit.WebView; import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.FlutterAssetManagerHostApi; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -27,6 +28,11 @@ public FlutterAssetManagerHostApiImpl(FlutterAssetManager flutterAssetManager) { public List list(String path) { try { String[] paths = flutterAssetManager.list(path); + + if (paths == null) { + return new ArrayList<>(); + } + return Arrays.asList(paths); } catch (IOException ex) { throw new RuntimeException(ex.getMessage()); diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/FlutterAssetManagerHostApiImplTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/FlutterAssetManagerHostApiImplTest.java index b8ab9499040e..72d43f2509f2 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/FlutterAssetManagerHostApiImplTest.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/FlutterAssetManagerHostApiImplTest.java @@ -6,12 +6,14 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import org.junit.Before; import org.junit.Test; @@ -43,6 +45,19 @@ public void list() { } } + @Test + public void list_returns_empty_list_when_no_results() { + try { + when(mockFlutterAssetManager.list("test/path")) + .thenReturn(null); + List actualFilePaths = testFlutterAssetManagerHostApiImpl.list("test/path"); + verify(mockFlutterAssetManager).list("test/path"); + assertArrayEquals(new String[] {}, actualFilePaths.toArray()); + } catch (IOException ex) { + fail(); + } + } + @Test(expected = RuntimeException.class) public void list_should_convert_io_exception_to_runtime_exception() { try { diff --git a/packages/webview_flutter/webview_flutter_android/pubspec.yaml b/packages/webview_flutter/webview_flutter_android/pubspec.yaml index 9fe5b146eafc..294baaeb1e12 100644 --- a/packages/webview_flutter/webview_flutter_android/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_android/pubspec.yaml @@ -4,9 +4,6 @@ repository: https://github.com/flutter/plugins/tree/master/packages/webview_flut issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview%22 version: 2.5.0 -# TODO(mvanbeusekom): Remove when webview_flutter_platform_interface no longer referenced through path reference. -publish_to: none - environment: sdk: ">=2.14.0 <3.0.0" flutter: ">=2.5.0" @@ -22,9 +19,7 @@ flutter: dependencies: flutter: sdk: flutter - # TODO(mvanbeusekom): Update to pub.dev dependency once version 1.8.0 is released. - webview_flutter_platform_interface: - path: ../webview_flutter_platform_interface + webview_flutter_platform_interface: ^1.8.0 dev_dependencies: build_runner: ^2.1.4