@@ -684,11 +684,54 @@ void main() {
684684 );
685685 });
686686
687- testWidgets ('dispose throws UnimplementedError' , (tester) async {
688- expect (
689- () => CameraPlatform .instance.dispose (cameraId),
690- throwsUnimplementedError,
691- );
687+ group ('dispose' , () {
688+ testWidgets (
689+ 'throws CameraException '
690+ 'with notFound error '
691+ 'if the camera does not exist' , (tester) async {
692+ expect (
693+ () => CameraPlatform .instance.dispose (cameraId),
694+ throwsA (
695+ isA <CameraException >().having (
696+ (e) => e.code,
697+ 'code' ,
698+ CameraErrorCodes .notFound,
699+ ),
700+ ),
701+ );
702+ });
703+
704+ testWidgets ('disposes the correct camera' , (tester) async {
705+ const firstCameraId = 0 ;
706+ const secondCameraId = 1 ;
707+
708+ final firstCamera = MockCamera ();
709+ final secondCamera = MockCamera ();
710+
711+ when (firstCamera.dispose).thenAnswer ((_) => Future .value ());
712+ when (secondCamera.dispose).thenAnswer ((_) => Future .value ());
713+
714+ // Save cameras in the camera plugin.
715+ (CameraPlatform .instance as CameraPlugin ).cameras.addAll ({
716+ firstCameraId: firstCamera,
717+ secondCameraId: secondCamera,
718+ });
719+
720+ // Dispose the first camera.
721+ await CameraPlatform .instance.dispose (firstCameraId);
722+
723+ // The first camera should be disposed.
724+ verify (firstCamera.dispose).called (1 );
725+ verifyNever (secondCamera.dispose);
726+
727+ // The first camera should be removed from the camera plugin.
728+ expect (
729+ (CameraPlatform .instance as CameraPlugin ).cameras,
730+ equals ({
731+ secondCameraId: secondCamera,
732+ }),
733+ );
734+ });
692735 });
693736
694737 group ('getCamera' , () {
0 commit comments