[flutter_tools] update iOS deploy tests for best practices (#53343)

diff --git a/packages/flutter_tools/test/general.shard/ios/devices_test.dart b/packages/flutter_tools/test/general.shard/ios/devices_test.dart
index 98d561d..84d9f6e 100644
--- a/packages/flutter_tools/test/general.shard/ios/devices_test.dart
+++ b/packages/flutter_tools/test/general.shard/ios/devices_test.dart
@@ -176,60 +176,6 @@
       });
     }
 
-    group('ios-deploy wrappers', () {
-      const String appId = '789';
-      const String deviceId = 'device-123';
-      IOSDevice device;
-      IOSDeploy iosDeploy;
-      FakeProcessManager fakeProcessManager;
-      const String iosDeployPath = '/path/to/ios-deploy';
-
-      setUp(() {
-        when(mockArtifacts.getArtifactPath(Artifact.iosDeploy, platform: TargetPlatform.ios))
-          .thenReturn(iosDeployPath);
-      });
-
-      testWithoutContext('isAppInstalled() catches ProcessException from ios-deploy', () async {
-        final MockIOSApp mockApp = MockIOSApp();
-        when(mockApp.id).thenReturn(appId);
-        fakeProcessManager = FakeProcessManager.list(<FakeCommand>[
-          FakeCommand(
-            command: const <String>[
-              iosDeployPath,
-              '--id',
-              deviceId,
-              '--exists',
-              '--bundle_id',
-              appId,
-            ],
-            onRun: () => throw const ProcessException('ios-deploy', <String>[]),
-          )
-        ]);
-        iosDeploy = IOSDeploy(
-          artifacts: mockArtifacts,
-          cache: mockCache,
-          logger: logger,
-          platform: macPlatform,
-          processManager: fakeProcessManager,
-        );
-        device = IOSDevice(
-          deviceId,
-          artifacts: mockArtifacts,
-          fileSystem: mockFileSystem,
-          logger: logger,
-          platform: macPlatform,
-          iosDeploy: iosDeploy,
-          iMobileDevice: iMobileDevice,
-          name: 'iPhone 1',
-          sdkVersion: '13.3',
-          cpuArchitecture: DarwinArch.arm64,
-        );
-
-        final bool result = await device.isAppInstalled(mockApp);
-        expect(result, false);
-      });
-    });
-
     group('.dispose()', () {
       IOSDevice device;
       MockIOSApp appPackage1;
diff --git a/packages/flutter_tools/test/general.shard/ios/ios_deploy_test.dart b/packages/flutter_tools/test/general.shard/ios/ios_deploy_test.dart
index 57cc81e..677fb8b 100644
--- a/packages/flutter_tools/test/general.shard/ios/ios_deploy_test.dart
+++ b/packages/flutter_tools/test/general.shard/ios/ios_deploy_test.dart
@@ -2,11 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-import 'dart:io' show Process;
-
 import 'package:flutter_tools/src/artifacts.dart';
 import 'package:flutter_tools/src/base/logger.dart';
-import 'package:flutter_tools/src/build_info.dart';
 import 'package:flutter_tools/src/cache.dart';
 import 'package:flutter_tools/src/ios/ios_deploy.dart';
 import 'package:mockito/mockito.dart';
@@ -14,105 +11,87 @@
 import 'package:process/process.dart';
 
 import '../../src/common.dart';
-import '../../src/mocks.dart';
+import '../../src/context.dart';
+
+void main () {
+  testWithoutContext('IOSDeploy.iosDeployEnv returns path with /usr/bin first', () {
+    final IOSDeploy iosDeploy = setUpIOSDeploy(FakeProcessManager.any());
+    final Map<String, String> environment = iosDeploy.iosDeployEnv;
+
+    expect(environment['PATH'], startsWith('/usr/bin'));
+  });
+
+  testWithoutContext('IOSDeploy.uninstallApp calls ios-deploy with correct arguments and returns 0 on success', () async {
+    const String deviceId = '123';
+    const String bundleId = 'com.example.app';
+    final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
+      const FakeCommand(command: <String>[
+        'ios-deploy',
+        '--id',
+        deviceId,
+        '--uninstall_only',
+        '--bundle_id',
+        bundleId,
+      ])
+    ]);
+    final IOSDeploy iosDeploy = setUpIOSDeploy(processManager);
+    final int exitCode = await iosDeploy.uninstallApp(
+      deviceId: deviceId,
+      bundleId: bundleId,
+    );
+
+    expect(exitCode, 0);
+    expect(processManager.hasRemainingExpectations, false);
+  });
+
+  testWithoutContext('IOSDeploy.uninstallApp returns non-zero exit code when ios-deploy does the same', () async {
+    const String deviceId = '123';
+    const String bundleId = 'com.example.app';
+    final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
+      const FakeCommand(command: <String>[
+        'ios-deploy',
+        '--id',
+        deviceId,
+        '--uninstall_only',
+        '--bundle_id',
+        bundleId,
+      ], exitCode: 1)
+    ]);
+    final IOSDeploy iosDeploy = setUpIOSDeploy(processManager);
+    final int exitCode = await iosDeploy.uninstallApp(
+      deviceId: deviceId,
+      bundleId: bundleId,
+    );
+
+    expect(exitCode, 1);
+    expect(processManager.hasRemainingExpectations, false);
+  });
+}
+
+IOSDeploy setUpIOSDeploy(ProcessManager processManager) {
+  const MapEntry<String, String> kDyLdLibEntry = MapEntry<String, String>(
+    'DYLD_LIBRARY_PATH', '/path/to/libs',
+  );
+  final FakePlatform macPlatform = FakePlatform(
+    operatingSystem: 'macos',
+    environment: <String, String>{
+      'PATH': '/usr/local/bin:/usr/bin'
+    }
+  );
+  final MockArtifacts artifacts = MockArtifacts();
+  final MockCache cache = MockCache();
+
+  when(cache.dyLdLibEntry).thenReturn(kDyLdLibEntry);
+  when(artifacts.getArtifactPath(Artifact.iosDeploy, platform: anyNamed('platform')))
+    .thenReturn('ios-deploy');
+  return IOSDeploy(
+    logger: BufferLogger.test(),
+    platform: macPlatform,
+    processManager: processManager,
+    artifacts: artifacts,
+    cache: cache,
+  );
+}
 
 class MockArtifacts extends Mock implements Artifacts {}
 class MockCache extends Mock implements Cache {}
-class MockPlatform extends Mock implements Platform {}
-class MockProcess extends Mock implements Process {}
-class MockProcessManager extends Mock implements ProcessManager {}
-
-void main () {
-  group('IOSDeploy()', () {
-    Artifacts mockArtifacts;
-    Cache mockCache;
-    IOSDeploy iosDeploy;
-    Logger logger;
-    Platform mockPlatform;
-    ProcessManager mockProcessManager;
-    const String iosDeployPath = '/path/to/ios-deploy';
-    const String deviceId = '123';
-    const String bundleId = 'com.example.app';
-
-    setUp(() {
-      mockArtifacts = MockArtifacts();
-      when(mockArtifacts.getArtifactPath(Artifact.iosDeploy, platform: TargetPlatform.ios))
-        .thenReturn(iosDeployPath);
-      mockCache = MockCache();
-      const MapEntry<String, String> mapEntry = MapEntry<String, String>('DYLD_LIBRARY_PATH', '/path/to/libs');
-      when(mockCache.dyLdLibEntry).thenReturn(mapEntry);
-      logger = BufferLogger.test();
-      mockPlatform = MockPlatform();
-      when(mockPlatform.environment).thenReturn(<String, String>{
-        'PATH': '/usr/local/bin:/usr/bin',
-      });
-      mockProcessManager = MockProcessManager();
-      iosDeploy = IOSDeploy(
-        artifacts: mockArtifacts,
-        cache: mockCache,
-        logger: logger,
-        platform: mockPlatform,
-        processManager: mockProcessManager,
-      );
-    });
-
-    testWithoutContext('iosDeployEnv returns path with /usr/bin first', () {
-      final Map<String, String> env = iosDeploy.iosDeployEnv;
-      expect(env['PATH'].startsWith('/usr/bin'), true);
-    });
-
-    testWithoutContext('uninstallApp() calls ios-deploy with correct arguments and returns 0 on success', () async {
-      final List<String> args = <String>[
-        iosDeployPath,
-        '--id',
-        deviceId,
-        '--uninstall_only',
-        '--bundle_id',
-        bundleId,
-      ];
-      when(mockProcessManager.start(
-        args,
-        workingDirectory: anyNamed('workingDirectory'),
-        environment: anyNamed('environment'),
-      )).thenAnswer((Invocation invocation) => Future<Process>.value(createMockProcess(exitCode: 0)));
-      final int exitCode = await iosDeploy.uninstallApp(
-        deviceId: deviceId,
-        bundleId: bundleId,
-      );
-
-      verify(mockProcessManager.start(
-        args,
-        workingDirectory: anyNamed('workingDirectory'),
-        environment: anyNamed('environment'),
-      ));
-      expect(exitCode, 0);
-    });
-
-    testWithoutContext('uninstallApp() returns non-zero exit code when ios-deploy does the same', () async {
-      final List<String> args = <String>[
-        iosDeployPath,
-        '--id',
-        deviceId,
-        '--uninstall_only',
-        '--bundle_id',
-        bundleId,
-      ];
-      when(mockProcessManager.start(
-        args,
-        workingDirectory: anyNamed('workingDirectory'),
-        environment: anyNamed('environment'),
-      )).thenAnswer((Invocation invocation) => Future<Process>.value(createMockProcess(exitCode: 1)));
-      final int exitCode = await iosDeploy.uninstallApp(
-        deviceId: deviceId,
-        bundleId: bundleId,
-      );
-
-      verify(mockProcessManager.start(
-        args,
-        workingDirectory: anyNamed('workingDirectory'),
-        environment: anyNamed('environment'),
-      ));
-      expect(exitCode, 1);
-    });
-  });
-}