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

[android_intent] move unit test to nullsafety #3659

Merged
merged 2 commits into from
Mar 2, 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
3 changes: 2 additions & 1 deletion packages/android_intent/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ dependencies:
meta: ^1.3.0
dev_dependencies:
test: ^1.16.3
mockito: ^5.0.0-nullsafety.7
mockito: ^5.0.0
flutter_test:
sdk: flutter
pedantic: ^1.10.0
build_runner: ^1.11.1

environment:
sdk: ">=2.12.0-259.9.beta <3.0.0"
Expand Down
14 changes: 8 additions & 6 deletions packages/android_intent/test/android_intent_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.9

import 'package:android_intent/flag.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:android_intent/android_intent.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:platform/platform.dart';

import 'android_intent_test.mocks.dart';

@GenerateMocks([MethodChannel])
void main() {
AndroidIntent androidIntent;
MockMethodChannel mockChannel;
late AndroidIntent androidIntent;
late MockMethodChannel mockChannel;

setUp(() {
mockChannel = MockMethodChannel();
when(mockChannel.invokeMethod<bool>('canResolveActivity', any))
.thenAnswer((realInvocation) async => true);
when(mockChannel.invokeMethod<void>('launch', any))
.thenAnswer((realInvocation) async => {});
});

group('AndroidIntent', () {
Expand Down Expand Up @@ -178,5 +182,3 @@ void main() {
});
});
}

class MockMethodChannel extends Mock implements MethodChannel {}
64 changes: 64 additions & 0 deletions packages/android_intent/test/android_intent_test.mocks.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Mocks generated by Mockito 5.0.0 from annotations
// in android_intent/test/android_intent_test.dart.
// Do not manually edit this file.

import 'dart:async' as _i5;

import 'package:flutter/src/services/binary_messenger.dart' as _i3;
import 'package:flutter/src/services/message_codec.dart' as _i2;
import 'package:flutter/src/services/platform_channel.dart' as _i4;
import 'package:mockito/mockito.dart' as _i1;

// ignore_for_file: comment_references
// ignore_for_file: unnecessary_parenthesis

class _FakeMethodCodec extends _i1.Fake implements _i2.MethodCodec {}

class _FakeBinaryMessenger extends _i1.Fake implements _i3.BinaryMessenger {}

/// A class which mocks [MethodChannel].
///
/// See the documentation for Mockito's code generation for more information.
class MockMethodChannel extends _i1.Mock implements _i4.MethodChannel {
MockMethodChannel() {
_i1.throwOnMissingStub(this);
}

@override
String get name =>
(super.noSuchMethod(Invocation.getter(#name), returnValue: '') as String);
@override
_i2.MethodCodec get codec => (super.noSuchMethod(Invocation.getter(#codec),
returnValue: _FakeMethodCodec()) as _i2.MethodCodec);
@override
_i3.BinaryMessenger get binaryMessenger =>
(super.noSuchMethod(Invocation.getter(#binaryMessenger),
returnValue: _FakeBinaryMessenger()) as _i3.BinaryMessenger);
@override
_i5.Future<T?> invokeMethod<T>(String? method, [dynamic arguments]) =>
(super.noSuchMethod(Invocation.method(#invokeMethod, [method, arguments]),
returnValue: Future.value(null)) as _i5.Future<T?>);
@override
_i5.Future<List<T>?> invokeListMethod<T>(String? method,
[dynamic arguments]) =>
(super.noSuchMethod(
Invocation.method(#invokeListMethod, [method, arguments]),
returnValue: Future.value(<T>[])) as _i5.Future<List<T>?>);
@override
_i5.Future<Map<K, V>?> invokeMapMethod<K, V>(String? method,
[dynamic arguments]) =>
(super.noSuchMethod(
Invocation.method(#invokeMapMethod, [method, arguments]),
returnValue: Future.value(<K, V>{})) as _i5.Future<Map<K, V>?>);
@override
bool checkMethodCallHandler(
_i5.Future<dynamic> Function(_i2.MethodCall)? handler) =>
(super.noSuchMethod(Invocation.method(#checkMethodCallHandler, [handler]),
returnValue: false) as bool);
@override
bool checkMockMethodCallHandler(
_i5.Future<dynamic> Function(_i2.MethodCall)? handler) =>
(super.noSuchMethod(
Invocation.method(#checkMockMethodCallHandler, [handler]),
returnValue: false) as bool);
}