From 5613c34499b273a11e728ef70907309a0717f503 Mon Sep 17 00:00:00 2001 From: Rafael Delos Santos Date: Mon, 19 Dec 2022 17:16:02 +1100 Subject: [PATCH] Fix failing test and low android compileSdk --- example/android/app/build.gradle | 2 +- example/lib/main.dart | 4 +++- example/pubspec.lock | 31 ++++++++++--------------- lib/headset_event.dart | 5 ++-- pubspec.lock | 31 ++++++++++--------------- test/headset_connection_event_test.dart | 20 ++++++++++++---- 6 files changed, 47 insertions(+), 46 deletions(-) diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 3e8bd71..6b80513 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -25,7 +25,7 @@ apply plugin: 'com.android.application' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 30 + compileSdkVersion 31 defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). diff --git a/example/lib/main.dart b/example/lib/main.dart index eb5eac1..54da06e 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -46,7 +46,9 @@ class _MyAppState extends State { children: [ Icon( Icons.headset, - color: this._headsetState == HeadsetState.CONNECT ? Colors.green : Colors.red, + color: this._headsetState == HeadsetState.CONNECT + ? Colors.green + : Colors.red, ), Text('State : $_headsetState\n'), ], diff --git a/example/pubspec.lock b/example/pubspec.lock index ed15cd2..9165d17 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.8.2" + version: "2.9.0" boolean_selector: dependency: transitive description: @@ -21,21 +21,14 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.1" + version: "1.2.1" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: transitive description: @@ -56,7 +49,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.3.1" flutter: dependency: "direct main" description: flutter @@ -80,28 +73,28 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.11" + version: "0.12.12" material_color_utilities: dependency: transitive description: name: material_color_utilities url: "https://pub.dartlang.org" source: hosted - version: "0.1.4" + version: "0.1.5" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.8.2" permission_handler: dependency: transitive description: @@ -155,7 +148,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.2" + version: "1.9.0" stack_trace: dependency: transitive description: @@ -176,21 +169,21 @@ packages: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.9" + version: "0.4.12" vector_math: dependency: transitive description: diff --git a/lib/headset_event.dart b/lib/headset_event.dart index 386431f..e870e45 100644 --- a/lib/headset_event.dart +++ b/lib/headset_event.dart @@ -32,7 +32,8 @@ class HeadsetEvent { factory HeadsetEvent() { if (_instance == null) { - final methodChannel = const MethodChannel('flutter.moum/headset_connection_event'); + final methodChannel = + const MethodChannel('flutter.moum/headset_connection_event'); _instance = HeadsetEvent.private(methodChannel); } @@ -49,7 +50,7 @@ class HeadsetEvent { case 1: return HeadsetState.CONNECT; default: - return null; + return HeadsetState.DISCONNECT; } } diff --git a/pubspec.lock b/pubspec.lock index fdb71c9..dc40d53 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -28,7 +28,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.8.2" + version: "2.9.0" boolean_selector: dependency: transitive description: @@ -63,21 +63,14 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.1" + version: "1.2.1" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" code_builder: dependency: transitive description: @@ -119,7 +112,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.3.1" file: dependency: transitive description: @@ -164,21 +157,21 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.11" + version: "0.12.12" material_color_utilities: dependency: transitive description: name: material_color_utilities url: "https://pub.dartlang.org" source: hosted - version: "0.1.4" + version: "0.1.5" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0" mockito: dependency: "direct dev" description: @@ -199,7 +192,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.8.2" pedantic: dependency: transitive description: @@ -274,7 +267,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.2" + version: "1.9.0" stack_trace: dependency: transitive description: @@ -295,21 +288,21 @@ packages: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.9" + version: "0.4.12" typed_data: dependency: transitive description: diff --git a/test/headset_connection_event_test.dart b/test/headset_connection_event_test.dart index 99967c4..8f33a31 100644 --- a/test/headset_connection_event_test.dart +++ b/test/headset_connection_event_test.dart @@ -5,25 +5,37 @@ import 'package:mockito/mockito.dart'; typedef DetectPluggedCallback = Function(HeadsetState payload); -class MockMethodChannel extends Mock implements MethodChannel {} +class MockMethodChannel extends Mock implements MethodChannel { + @override + Future invokeMethod(String method, [dynamic arguments]) { + return super.noSuchMethod(Invocation.getter(#invokeMethod), + returnValue: Future.value(0)); + } +} void main() { late final MockMethodChannel _methodChannel; late final HeadsetEvent _he; setUp(() { + print('setting up'); _methodChannel = MockMethodChannel(); + print('setting headset'); _he = HeadsetEvent.private(_methodChannel); }); test('getCurrentState', () async { - when(_methodChannel.invokeMethod('getCurrentState')).thenAnswer((Invocation invoke) => Future.value(0)); + when(_methodChannel.invokeMethod('getCurrentState')) + .thenAnswer((Invocation invoke) => Future.value(0)); + expect(await _he.getCurrentState, HeadsetState.DISCONNECT); - when(_methodChannel.invokeMethod('getCurrentState')).thenAnswer((Invocation invoke) => Future.value(1)); + when(_methodChannel.invokeMethod('getCurrentState')) + .thenAnswer((Invocation invoke) => Future.value(1)); expect(await _he.getCurrentState, HeadsetState.CONNECT); - when(_methodChannel.invokeMethod('getCurrentState')).thenAnswer((Invocation invoke) => Future.value(-1)); + when(_methodChannel.invokeMethod('getCurrentState')) + .thenAnswer((Invocation invoke) => Future.value(-1)); expect(await _he.getCurrentState, HeadsetState.DISCONNECT); }); }