mirror of
https://github.com/flutter/packages.git
synced 2025-07-01 23:51:55 +08:00
[camerax] Mock InstanceManager
in unit tests (#4121)
Ensures that `InstanceManager` is mocked (once) for all `camera_android_camerax` tests. Fixes https://github.com/flutter/flutter/issues/127661.
This commit is contained in:
@ -16,18 +16,19 @@ import 'test_camerax_library.g.dart';
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
// Mocks the call to clear the native InstanceManager.
|
||||
TestInstanceManagerHostApi.setup(MockTestInstanceManagerHostApi());
|
||||
|
||||
group('Analyzer', () {
|
||||
setUp(() {});
|
||||
|
||||
tearDown(() {
|
||||
TestAnalyzerHostApi.setup(null);
|
||||
TestInstanceManagerHostApi.setup(null);
|
||||
});
|
||||
|
||||
test('HostApi create', () {
|
||||
final MockTestAnalyzerHostApi mockApi = MockTestAnalyzerHostApi();
|
||||
TestAnalyzerHostApi.setup(mockApi);
|
||||
TestInstanceManagerHostApi.setup(MockTestInstanceManagerHostApi());
|
||||
|
||||
final InstanceManager instanceManager = InstanceManager(
|
||||
onWeakReferenceRemoved: (_) {},
|
||||
|
@ -98,9 +98,6 @@ void main() {
|
||||
return cameraClosingEventSent && cameraErrorSent;
|
||||
}
|
||||
|
||||
// Mocks the call to clear the native InstanceManager.
|
||||
TestInstanceManagerHostApi.setup(MockTestInstanceManagerHostApi());
|
||||
|
||||
test('Should fetch CameraDescription instances for available cameras',
|
||||
() async {
|
||||
// Arrange
|
||||
|
@ -7,17 +7,17 @@ import 'package:camera_android_camerax/src/instance_manager.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
|
||||
import 'camera_state_error_test.mocks.dart';
|
||||
import 'test_camerax_library.g.dart';
|
||||
|
||||
@GenerateMocks(<Type>[TestInstanceManagerHostApi])
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
group('CameraStateError', () {
|
||||
tearDown(() {
|
||||
TestInstanceManagerHostApi.setup(null);
|
||||
});
|
||||
// Mocks the call to clear the native InstanceManager.
|
||||
TestInstanceManagerHostApi.setup(MockTestInstanceManagerHostApi());
|
||||
|
||||
group('CameraStateError', () {
|
||||
test(
|
||||
'FlutterAPI create makes call to create CameraStateError instance with expected identifier',
|
||||
() {
|
||||
|
@ -20,10 +20,6 @@ void main() {
|
||||
TestInstanceManagerHostApi.setup(MockTestInstanceManagerHostApi());
|
||||
|
||||
group('CameraState', () {
|
||||
tearDown(() {
|
||||
TestInstanceManagerHostApi.setup(null);
|
||||
});
|
||||
|
||||
test(
|
||||
'FlutterAPI create makes call to create CameraState instance with expected identifier',
|
||||
() {
|
||||
|
@ -26,14 +26,12 @@ void main() {
|
||||
|
||||
tearDown(() {
|
||||
TestImageAnalysisHostApi.setup(null);
|
||||
TestInstanceManagerHostApi.setup(null);
|
||||
});
|
||||
|
||||
test('HostApi create', () {
|
||||
final MockTestImageAnalysisHostApi mockApi =
|
||||
MockTestImageAnalysisHostApi();
|
||||
TestImageAnalysisHostApi.setup(mockApi);
|
||||
TestInstanceManagerHostApi.setup(MockTestInstanceManagerHostApi());
|
||||
|
||||
final InstanceManager instanceManager = InstanceManager(
|
||||
onWeakReferenceRemoved: (_) {},
|
||||
|
@ -12,10 +12,13 @@ import 'package:mockito/mockito.dart';
|
||||
import 'image_capture_test.mocks.dart';
|
||||
import 'test_camerax_library.g.dart';
|
||||
|
||||
@GenerateMocks(<Type>[TestImageCaptureHostApi])
|
||||
@GenerateMocks(<Type>[TestImageCaptureHostApi, TestInstanceManagerHostApi])
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
// Mocks the call to clear the native InstanceManager.
|
||||
TestInstanceManagerHostApi.setup(MockTestInstanceManagerHostApi());
|
||||
|
||||
group('ImageCapture', () {
|
||||
tearDown(() => TestImageCaptureHostApi.setup(null));
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
// Mocks generated by Mockito 5.4.0 from annotations
|
||||
// Mocks generated by Mockito 5.4.1 from annotations
|
||||
// in camera_android_camerax/test/image_capture_test.dart.
|
||||
// Do not manually edit this file.
|
||||
|
||||
// @dart=2.19
|
||||
|
||||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||
import 'dart:async' as _i4;
|
||||
|
||||
@ -71,3 +73,22 @@ class MockTestImageCaptureHostApi extends _i1.Mock
|
||||
returnValue: _i4.Future<String>.value(''),
|
||||
) as _i4.Future<String>);
|
||||
}
|
||||
|
||||
/// A class which mocks [TestInstanceManagerHostApi].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockTestInstanceManagerHostApi extends _i1.Mock
|
||||
implements _i2.TestInstanceManagerHostApi {
|
||||
MockTestInstanceManagerHostApi() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
void clear() => super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#clear,
|
||||
[],
|
||||
),
|
||||
returnValueForMissingStub: null,
|
||||
);
|
||||
}
|
||||
|
@ -22,11 +22,8 @@ void main() {
|
||||
TestInstanceManagerHostApi.setup(MockTestInstanceManagerHostApi());
|
||||
|
||||
group('ImageProxy', () {
|
||||
setUp(() {});
|
||||
|
||||
tearDown(() {
|
||||
TestImageProxyHostApi.setup(null);
|
||||
TestInstanceManagerHostApi.setup(null);
|
||||
});
|
||||
|
||||
test('getPlanes', () async {
|
||||
|
@ -24,7 +24,6 @@ void main() {
|
||||
group('LiveData', () {
|
||||
tearDown(() {
|
||||
TestLiveDataHostApi.setup(null);
|
||||
TestInstanceManagerHostApi.setup(null);
|
||||
});
|
||||
|
||||
test('observe makes call to add observer to LiveData instance', () async {
|
||||
@ -103,7 +102,6 @@ void main() {
|
||||
test('getValue returns expected value', () async {
|
||||
final MockTestLiveDataHostApi mockApi = MockTestLiveDataHostApi();
|
||||
TestLiveDataHostApi.setup(mockApi);
|
||||
TestInstanceManagerHostApi.setup(MockTestInstanceManagerHostApi());
|
||||
|
||||
final InstanceManager instanceManager = InstanceManager(
|
||||
onWeakReferenceRemoved: (_) {},
|
||||
|
@ -17,16 +17,17 @@ import 'test_camerax_library.g.dart';
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
// Mocks the call to clear the native InstanceManager.
|
||||
TestInstanceManagerHostApi.setup(MockTestInstanceManagerHostApi());
|
||||
|
||||
group('Observer', () {
|
||||
tearDown(() {
|
||||
TestObserverHostApi.setup(null);
|
||||
TestInstanceManagerHostApi.setup(null);
|
||||
});
|
||||
|
||||
test('HostApi create makes call to create Observer instance', () {
|
||||
final MockTestObserverHostApi mockApi = MockTestObserverHostApi();
|
||||
TestObserverHostApi.setup(mockApi);
|
||||
TestInstanceManagerHostApi.setup(MockTestInstanceManagerHostApi());
|
||||
|
||||
final InstanceManager instanceManager = InstanceManager(
|
||||
onWeakReferenceRemoved: (_) {},
|
||||
@ -47,7 +48,6 @@ void main() {
|
||||
() {
|
||||
final MockTestObserverHostApi mockApi = MockTestObserverHostApi();
|
||||
TestObserverHostApi.setup(mockApi);
|
||||
TestInstanceManagerHostApi.setup(MockTestInstanceManagerHostApi());
|
||||
|
||||
final Observer<String> cameraStateObserver =
|
||||
Observer<String>.detached(onChanged: (Object value) {});
|
||||
|
@ -20,12 +20,6 @@ void main() {
|
||||
TestInstanceManagerHostApi.setup(MockTestInstanceManagerHostApi());
|
||||
|
||||
group('PlaneProxy', () {
|
||||
setUp(() {});
|
||||
|
||||
tearDown(() {
|
||||
TestInstanceManagerHostApi.setup(null);
|
||||
});
|
||||
|
||||
test('FlutterAPI create', () {
|
||||
final InstanceManager instanceManager = InstanceManager(
|
||||
onWeakReferenceRemoved: (_) {},
|
||||
|
@ -18,8 +18,6 @@ void main() {
|
||||
TestInstanceManagerHostApi.setup(MockTestInstanceManagerHostApi());
|
||||
|
||||
group('ZoomState', () {
|
||||
tearDown(() => TestInstanceManagerHostApi.setup(null));
|
||||
|
||||
test('flutterApi create makes call to create expected ZoomState', () {
|
||||
final InstanceManager instanceManager = InstanceManager(
|
||||
onWeakReferenceRemoved: (_) {},
|
||||
|
Reference in New Issue
Block a user