anchor.diff:      });
   
       testUsingContext('Does not catch generic RPC error', () async {
  -      final MockAndroidDevice device = MockAndroidDevice();
  -      final MockHotRunner mockHotRunner = MockHotRunner();
  -      final MockHotRunnerFactory mockHotRunnerFactory = MockHotRunnerFactory();
  -      when(device.portForwarder).thenReturn(const NoOpDevicePortForwarder());
  -
  -      when(mockHotRunner.attach(
  -        appStartedCompleter: anyNamed('appStartedCompleter'),
  -        allowExistingDdsInstance: true,
  -        enableDevTools: anyNamed('enableDevTools'),
  -      )).thenAnswer((_) async {
  +      final FakeAndroidDevice device = FakeAndroidDevice(id: '1')
  +        ..portForwarder = const NoOpDevicePortForwarder()
  +        ..onGetLogReader = () => NoOpDeviceLogReader('test');
  +      final FakeHotRunner hotRunner = FakeHotRunner();
  +      final FakeHotRunnerFactory hotRunnerFactory = FakeHotRunnerFactory()
  +        ..hotRunner = hotRunner;
  +
  +      hotRunner.onAttach = (
  +        Completer<DebugConnectionInfo> connectionInfoCompleter,
  +        Completer<void> appStartedCompleter,
  +        bool allowExistingDdsInstance,
  +        bool enableDevTools,
  +      ) async {
           await null;
           throw vm_service.RPCError('flutter._listViews', RPCErrorCodes.kInvalidParams, '');
  -      });
  -      when(mockHotRunnerFactory.build(
  -        any,
  -        target: anyNamed('target'),
  -        debuggingOptions: anyNamed('debuggingOptions'),
  -        packagesFilePath: anyNamed('packagesFilePath'),
  -        flutterProject: anyNamed('flutterProject'),
  -        ipv6: false,
  -      )).thenReturn(mockHotRunner);
  +      };
  +
   
         testDeviceManager.addDevice(device);
  -      when(device.getLogReader(includePastLogs: anyNamed('includePastLogs')))
  -        .thenAnswer((_) {
  -          return NoOpDeviceLogReader('test');
  -        });
         testFileSystem.file('lib/main.dart').createSync();
   
  -      final AttachCommand command = AttachCommand(hotRunnerFactory: mockHotRunnerFactory);
  +      final AttachCommand command = AttachCommand(hotRunnerFactory: hotRunnerFactory);
         await expectLater(createTestCommandRunner(command).run(<String>[
           'attach',
         ]), throwsA(isA<vm_service.RPCError>()));
  
positive.code:       });
  
        testUsingContext('exits when ipv6 is specified and debug-port is not', () async {
          when(device.getLogReader(includePastLogs: anyNamed('includePastLogs')))
            .thenAnswer((_) {
              // Now that the reader is used, start writing messages to it.
              fakeLogReader.addLine('Foo');
              fakeLogReader.addLine('Observatory listening on http://127.0.0.1:$devicePort');
              return fakeLogReader;
            });
          testDeviceManager.addDevice(device);
  
          final AttachCommand command = AttachCommand();
  
negative.code:           ],
          );
          await completer.future;
          expect(portForwarder.devicePort, null);
          expect(portForwarder.hostPort, 42);
  
          await expectLoggerInterruptEndsTask(task, logger);
          await loggerSubscription.cancel();
  