Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing test and low android compileSdk #13

Merged
merged 1 commit into from
Dec 19, 2022
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: 1 addition & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
4 changes: 3 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ class _MyAppState extends State<MyApp> {
children: <Widget>[
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'),
],
Expand Down
31 changes: 12 additions & 19 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions lib/headset_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -49,7 +50,7 @@ class HeadsetEvent {
case 1:
return HeadsetState.CONNECT;
default:
return null;
return HeadsetState.DISCONNECT;
}
}

Expand Down
31 changes: 12 additions & 19 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
20 changes: 16 additions & 4 deletions test/headset_connection_event_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<T?> invokeMethod<T>(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<int>('getCurrentState')).thenAnswer((Invocation invoke) => Future<int>.value(0));
when(_methodChannel.invokeMethod<int>('getCurrentState'))
.thenAnswer((Invocation invoke) => Future<int?>.value(0));

expect(await _he.getCurrentState, HeadsetState.DISCONNECT);

when(_methodChannel.invokeMethod<int>('getCurrentState')).thenAnswer((Invocation invoke) => Future<int>.value(1));
when(_methodChannel.invokeMethod<int>('getCurrentState'))
.thenAnswer((Invocation invoke) => Future<int>.value(1));
expect(await _he.getCurrentState, HeadsetState.CONNECT);

when(_methodChannel.invokeMethod<int>('getCurrentState')).thenAnswer((Invocation invoke) => Future<int>.value(-1));
when(_methodChannel.invokeMethod<int>('getCurrentState'))
.thenAnswer((Invocation invoke) => Future<int>.value(-1));
expect(await _he.getCurrentState, HeadsetState.DISCONNECT);
});
}