Move DEPRECATED_MEMBER_USE to AnalysisContextCollection.

Change-Id: I938891254b2bf3aae7d2c514a27a7ed49f95b775
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/157883
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analyzer/test/src/dart/resolution/context_collection_resolution.dart b/pkg/analyzer/test/src/dart/resolution/context_collection_resolution.dart
index c5ac808..ea9f880 100644
--- a/pkg/analyzer/test/src/dart/resolution/context_collection_resolution.dart
+++ b/pkg/analyzer/test/src/dart/resolution/context_collection_resolution.dart
@@ -16,8 +16,14 @@
 import 'package:analyzer/src/test_utilities/mock_sdk.dart';
 import 'package:analyzer/src/test_utilities/package_mixin.dart';
 import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
+import 'package:analyzer/src/workspace/basic.dart';
+import 'package:analyzer/src/workspace/bazel.dart';
+import 'package:analyzer/src/workspace/gn.dart';
+import 'package:analyzer/src/workspace/package_build.dart';
+import 'package:analyzer/src/workspace/pub.dart';
 import 'package:linter/src/rules.dart';
 import 'package:meta/meta.dart';
+import 'package:test/test.dart';
 
 import 'resolution.dart';
 
@@ -91,10 +97,21 @@
 
   String get workspaceRootPath => '/workspace';
 
+  String get workspaceThirdPartyDartPath {
+    return '$workspaceRootPath/third_party/dart';
+  }
+
   @override
   void setUp() {
     super.setUp();
     newFile('$workspaceRootPath/WORKSPACE', content: '');
+    newFile('$myPackageRootPath/BUILD', content: '');
+  }
+
+  @override
+  void verifyCreatedCollection() {
+    super.verifyCreatedCollection();
+    assertBazelWorkspaceFor(testFilePath);
   }
 }
 
@@ -118,10 +135,33 @@
     _declaredVariables = map;
   }
 
+  void assertBasicWorkspaceFor(String path) {
+    var workspace = contextFor(path).workspace;
+    expect(workspace, TypeMatcher<BasicWorkspace>());
+  }
+
+  void assertBazelWorkspaceFor(String path) {
+    var workspace = contextFor(path).workspace;
+    expect(workspace, TypeMatcher<BazelWorkspace>());
+  }
+
+  void assertGnWorkspaceFor(String path) {
+    var workspace = contextFor(path).workspace;
+    expect(workspace, TypeMatcher<GnWorkspace>());
+  }
+
+  void assertPackageBuildWorkspaceFor(String path) {
+    var workspace = contextFor(path).workspace;
+    expect(workspace, TypeMatcher<PackageBuildWorkspace>());
+  }
+
+  void assertPubWorkspaceFor(String path) {
+    var workspace = contextFor(path).workspace;
+    expect(workspace, TypeMatcher<PubWorkspace>());
+  }
+
   AnalysisContext contextFor(String path) {
-    if (_analysisContextCollection == null) {
-      _createAnalysisContexts();
-    }
+    _createAnalysisContexts();
 
     path = convertPath(path);
     return _analysisContextCollection.contextFor(path);
@@ -163,8 +203,14 @@
     );
   }
 
+  void verifyCreatedCollection() {}
+
   /// Create all analysis contexts in [collectionIncludedPaths].
   void _createAnalysisContexts() {
+    if (_analysisContextCollection != null) {
+      return;
+    }
+
     _analysisContextCollection = AnalysisContextCollectionImpl(
       declaredVariables: _declaredVariables,
       enableIndex: true,
@@ -172,6 +218,8 @@
       resourceProvider: resourceProvider,
       sdkPath: convertPath('/sdk'),
     );
+
+    verifyCreatedCollection();
   }
 }
 
diff --git a/pkg/analyzer/test/src/diagnostics/deprecated_member_use_test.dart b/pkg/analyzer/test/src/diagnostics/deprecated_member_use_test.dart
index c273957..0e37307 100644
--- a/pkg/analyzer/test/src/diagnostics/deprecated_member_use_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/deprecated_member_use_test.dart
@@ -3,58 +3,354 @@
 // BSD-style license that can be found in the LICENSE file.
 
 import 'package:analyzer/src/error/codes.dart';
-import 'package:test/test.dart';
+import 'package:meta/meta.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
-import '../dart/resolution/driver_resolution.dart';
+import '../dart/resolution/context_collection_resolution.dart';
 
 main() {
   defineReflectiveSuite(() {
-    defineReflectiveTests(DeprecatedMemberUseFromSamePackageTest);
-    defineReflectiveTests(DeprecatedMemberUseTest);
+    defineReflectiveTests(DeprecatedMemberUse_BasicWorkspaceTest);
+    defineReflectiveTests(DeprecatedMemberUse_BazelWorkspaceTest);
+    defineReflectiveTests(DeprecatedMemberUse_GnWorkspaceTest);
+    defineReflectiveTests(DeprecatedMemberUse_PackageBuildWorkspaceTest);
+
+    defineReflectiveTests(
+      DeprecatedMemberUseFromSamePackage_BasicWorkspaceTest,
+    );
+    defineReflectiveTests(
+      DeprecatedMemberUseFromSamePackage_BazelWorkspaceTest,
+    );
+    defineReflectiveTests(
+      DeprecatedMemberUseFromSamePackage_PackageBuildWorkspaceTest,
+    );
   });
 }
 
 @reflectiveTest
-class DeprecatedMemberUseFromSamePackageTest extends DriverResolutionTest {
-  test_basicWorkspace() async {
-    configureWorkspace(root: '/workspace');
+class DeprecatedMemberUse_BasicWorkspaceTest extends PubPackageResolutionTest {
+  @override
+  void setUp() {
+    super.setUp();
 
-    newFile('/workspace/lib/deprecated_library.dart', content: r'''
+    writeTestPackageConfig({
+      'aaa': '$workspaceRootPath/aaa',
+    });
+  }
+
+  test_export() async {
+    newFile('$workspaceRootPath/aaa/lib/a.dart', content: r'''
 @deprecated
-library deprecated_library;
-class A {}
+library a;
 ''');
 
-    await assertErrorsInFile('/workspace/lib/test.dart', r'''
-import 'deprecated_library.dart';
-f(A a) {}
+    assertBasicWorkspaceFor(testFilePath);
+
+    await assertErrorsInCode('''
+export 'package:aaa/a.dart';
 ''', [
-      error(HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE, 0, 33),
+      error(HintCode.DEPRECATED_MEMBER_USE, 0, 28),
     ]);
   }
 
-  test_bazelWorkspace() async {
-    configureWorkspace(root: '/workspace');
-
-    newFile('/workspace/WORKSPACE');
-    newFile('/workspace/project/BUILD');
-    newFolder('/workspace/bazel-genfiles');
-
-    newFile('/workspace/project/lib/deprecated_library.dart', content: r'''
-@deprecated
-library deprecated_library;
-class A {}
+  test_fieldGet_implicitGetter() async {
+    newFile('$workspaceRootPath/aaa/lib/a.dart', content: r'''
+class A {
+  @deprecated
+  int foo = 0;
+}
 ''');
 
-    await assertErrorsInFile('/workspace/project/lib/lib1.dart', r'''
-import 'deprecated_library.dart';
-f(A a) {}
+    assertBasicWorkspaceFor(testFilePath);
+
+    await assertErrorsInCode(r'''
+import 'package:aaa/a.dart';
+
+void f(A a) {
+  a.foo;
+}
 ''', [
-      error(HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE, 0, 33),
+      error(HintCode.DEPRECATED_MEMBER_USE, 48, 3),
     ]);
   }
 
+  test_fieldSet_implicitSetter() async {
+    newFile('$workspaceRootPath/aaa/lib/a.dart', content: r'''
+class A {
+  @deprecated
+  int foo = 0;
+}
+''');
+
+    assertBasicWorkspaceFor(testFilePath);
+
+    await assertErrorsInCode(r'''
+import 'package:aaa/a.dart';
+
+void f(A a) {
+  a.foo = 0;
+}
+''', [
+      error(HintCode.DEPRECATED_MEMBER_USE, 48, 3),
+    ]);
+  }
+
+  test_import() async {
+    newFile('$workspaceRootPath/aaa/lib/a.dart', content: r'''
+@deprecated
+library a;
+''');
+
+    assertBasicWorkspaceFor(testFilePath);
+
+    await assertErrorsInCode(r'''
+// ignore:unused_import
+import 'package:aaa/a.dart';
+''', [
+      error(HintCode.DEPRECATED_MEMBER_USE, 24, 28,
+          messageContains: 'package:aaa/a.dart'),
+    ]);
+  }
+
+  test_methodInvocation() async {
+    newFile('$workspaceRootPath/aaa/lib/a.dart', content: r'''
+class A {
+  @deprecated
+  void foo() {}
+}
+''');
+
+    assertBasicWorkspaceFor(testFilePath);
+
+    await assertErrorsInCode(r'''
+import 'package:aaa/a.dart';
+
+void f(A a) {
+  a.foo();
+}
+''', [
+      error(HintCode.DEPRECATED_MEMBER_USE, 48, 3),
+    ]);
+  }
+
+  test_methodInvocation_withMessage() async {
+    newFile('$workspaceRootPath/aaa/lib/a.dart', content: r'''
+class A {
+  @Deprecated('0.9')
+  void foo() {}
+}
+''');
+
+    assertBasicWorkspaceFor(testFilePath);
+
+    await assertErrorsInCode(r'''
+import 'package:aaa/a.dart';
+
+void f(A a) {
+  a.foo();
+}
+''', [
+      error(HintCode.DEPRECATED_MEMBER_USE_WITH_MESSAGE, 48, 3),
+    ]);
+  }
+
+  test_setterInvocation() async {
+    newFile('$workspaceRootPath/aaa/lib/a.dart', content: r'''
+class A {
+  @deprecated
+  set foo(int _) {}
+}
+''');
+
+    assertBasicWorkspaceFor(testFilePath);
+
+    await assertErrorsInCode(r'''
+import 'package:aaa/a.dart';
+
+void f(A a) {
+  a.foo = 0;
+}
+''', [
+      error(HintCode.DEPRECATED_MEMBER_USE, 48, 3),
+    ]);
+  }
+}
+
+@reflectiveTest
+class DeprecatedMemberUse_BazelWorkspaceTest
+    extends BazelWorkspaceResolutionTest {
+  test_dart() async {
+    newFile('$workspaceRootPath/foo/bar/lib/a.dart', content: r'''
+@deprecated
+class A {}
+''');
+
+    await assertErrorsInCode(r'''
+import 'package:foo.bar/a.dart';
+
+void f(A a) {}
+''', [
+      error(HintCode.DEPRECATED_MEMBER_USE, 41, 1),
+    ]);
+  }
+
+  test_thirdPartyDart() async {
+    newFile('$workspaceThirdPartyDartPath/aaa/lib/a.dart', content: r'''
+@deprecated
+class A {}
+''');
+
+    assertBazelWorkspaceFor(testFilePath);
+
+    await assertErrorsInCode(r'''
+import 'package:aaa/a.dart';
+
+void f(A a) {}
+''', [
+      error(HintCode.DEPRECATED_MEMBER_USE, 37, 1),
+    ]);
+  }
+}
+
+@reflectiveTest
+class DeprecatedMemberUse_GnWorkspaceTest extends ContextResolutionTest {
+  @override
+  List<String> get collectionIncludedPaths => [workspaceRootPath];
+
+  String get myPackageLibPath => '$myPackageRootPath/lib';
+
+  String get myPackageRootPath => '$workspaceRootPath/my';
+
+  @override
+  String get testFilePath => '$myPackageLibPath/my.dart';
+
+  String get workspaceRootPath => '/workspace';
+
+  @override
+  void setUp() {
+    super.setUp();
+    newFolder('$workspaceRootPath/.jiri_root');
+  }
+
+  test_differentPackage() async {
+    newFile('$workspaceRootPath/my/pubspec.yaml');
+    newFile('$workspaceRootPath/my/BUILD.gn');
+
+    newFile('$workspaceRootPath/aaa/pubspec.yaml');
+    newFile('$workspaceRootPath/aaa/BUILD.gn');
+
+    _writeWorkspacePackagesFile({
+      'aaa': '$workspaceRootPath/aaa/lib',
+      'my': myPackageLibPath,
+    });
+
+    newFile('$workspaceRootPath/aaa/lib/a.dart', content: r'''
+@deprecated
+class A {}
+''');
+
+    await assertErrorsInCode(r'''
+import 'package:aaa/a.dart';
+
+void f(A a) {}
+''', [
+      error(HintCode.DEPRECATED_MEMBER_USE, 37, 1),
+    ]);
+  }
+
+  test_samePackage() async {
+    newFile('$workspaceRootPath/my/pubspec.yaml');
+    newFile('$workspaceRootPath/my/BUILD.gn');
+
+    _writeWorkspacePackagesFile({
+      'my': myPackageLibPath,
+    });
+
+    newFile('$myPackageLibPath/a.dart', content: r'''
+@deprecated
+class A {}
+''');
+
+    await assertErrorsInCode(r'''
+import 'package:my/a.dart';
+
+void f(A a) {}
+''', [
+      error(HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE, 36, 1),
+    ]);
+  }
+
+  @override
+  void verifyCreatedCollection() {
+    super.verifyCreatedCollection();
+    assertGnWorkspaceFor(testFilePath);
+  }
+
+  void _writeWorkspacePackagesFile(Map<String, String> nameToLibPath) {
+    var builder = StringBuffer();
+    for (var entry in nameToLibPath.entries) {
+      builder.writeln('${entry.key}:${toUriStr(entry.value)}');
+    }
+
+    var buildDir = 'out/debug-x87_128';
+    var genPath = '$workspaceRootPath/$buildDir/dartlang/gen';
+    newFile('$genPath/foo.packages', content: builder.toString());
+  }
+}
+
+@reflectiveTest
+class DeprecatedMemberUse_PackageBuildWorkspaceTest
+    extends _PackageBuildWorkspaceBase {
+  test_generated() async {
+    writeTestPackageConfig({
+      'aaa': '$workspaceRootPath/aaa',
+    });
+
+    newFile('$testPackageRootPath/pubspec.yaml', content: 'name: test');
+    _newTestPackageGeneratedFile(
+      packageName: 'aaa',
+      pathInLib: 'a.dart',
+      content: r'''
+@deprecated
+class A {}
+''',
+    );
+
+    await assertErrorsInCode(r'''
+import 'package:aaa/a.dart';
+
+void f(A a) {}
+''', [
+      error(HintCode.DEPRECATED_MEMBER_USE, 37, 1),
+    ]);
+  }
+
+  test_lib() async {
+    writeTestPackageConfig({
+      'aaa': '$workspaceRootPath/aaa',
+    });
+
+    newFile('$workspaceRootPath/aaa/lib/a.dart', content: r'''
+@deprecated
+class A {}
+''');
+
+    newFile('$testPackageRootPath/pubspec.yaml', content: 'name: test');
+    _createTestPackageBuildMarker();
+
+    await assertErrorsInCode(r'''
+import 'package:aaa/a.dart';
+
+void f(A a) {}
+''', [
+      error(HintCode.DEPRECATED_MEMBER_USE, 37, 1),
+    ]);
+  }
+}
+
+@reflectiveTest
+class DeprecatedMemberUseFromSamePackage_BasicWorkspaceTest
+    extends PubPackageResolutionTest {
   test_call() async {
     await assertErrorsInCode(r'''
 class A {
@@ -70,6 +366,21 @@
     ]);
   }
 
+  test_class() async {
+    newFile('$testPackageLibPath/a.dart', content: r'''
+@deprecated
+class A {}
+''');
+
+    await assertErrorsInCode(r'''
+import 'a.dart';
+
+void f(A a) {}
+''', [
+      error(HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE, 25, 1),
+    ]);
+  }
+
   test_compoundAssignment() async {
     await assertErrorsInCode(r'''
 class A {
@@ -86,7 +397,7 @@
   }
 
   test_export() async {
-    newFile("/test/lib/deprecated_library.dart", content: r'''
+    newFile('$testPackageLibPath/deprecated_library.dart', content: r'''
 @deprecated
 library deprecated_library;
 class A {}
@@ -126,35 +437,8 @@
     ]);
   }
 
-  test_gnWorkspace() async {
-    configureWorkspace(root: '/workspace');
-
-    newFolder('/workspace/.jiri_root');
-    newFile('/workspace/project/pubspec.yaml');
-    newFile('/workspace/project/BUILD.gn');
-    String buildDir = convertPath('out/debug-x87_128');
-    newFile('/workspace/.config', content: '''
-FOO=foo
-FUCHSIA_BUILD_DIR=$buildDir
-''');
-    newFile('/workspace/out/debug-x87_128/dartlang/gen/project/foo.packages');
-
-    newFile('/workspace/project/lib/deprecated_library.dart', content: r'''
-@deprecated
-library deprecated_library;
-class A {}
-''');
-
-    await assertErrorsInFile('/workspace/project/lib/lib1.dart', r'''
-import 'deprecated_library.dart';
-f(A a) {}
-''', [
-      error(HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE, 0, 33),
-    ]);
-  }
-
   test_import() async {
-    newFile("/test/lib/deprecated_library.dart", content: r'''
+    newFile('$testPackageLibPath/deprecated_library.dart', content: r'''
 @deprecated
 library deprecated_library;
 class A {}
@@ -358,27 +642,6 @@
     ]);
   }
 
-  test_packageBuildWorkspace() async {
-    configureWorkspace(root: '/workspace');
-
-    newFolder('/workspace/.dart_tool/build/generated/project/lib');
-    newFile('/workspace/pubspec.yaml', content: 'name: project');
-    newFile('/workspace/.packages', content: 'project:lib/');
-
-    newFile('/workspace/lib/deprecated_library.dart', content: r'''
-@deprecated
-library deprecated_library;
-class A {}
-''');
-
-    await assertErrorsInFile('/workspace/lib/lib1.dart', r'''
-import 'deprecated_library.dart';
-f(A a) {}
-''', [
-      error(HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE, 0, 33),
-    ]);
-  }
-
   test_parameter_named() async {
     await assertErrorsInCode(r'''
 class A {
@@ -487,249 +750,95 @@
 }
 
 @reflectiveTest
-class DeprecatedMemberUseTest extends DriverResolutionTest {
-  /// Write a pubspec file at [root], so that BestPracticesVerifier can see that
-  /// [root] is the root of a PubWorkspace, and a PubWorkspacePackage.
-  void newPubPackage(String root) {
-    newFile('$root/pubspec.yaml');
-  }
-
-  void resetWithFooLibrary(String content) {
-    newFile('/aaa/lib/a.dart', content: content);
-  }
-
-  test_basicWorkspace() async {
-    resetWithFooLibrary(r'''
+class DeprecatedMemberUseFromSamePackage_BazelWorkspaceTest
+    extends BazelWorkspaceResolutionTest {
+  test_it() async {
+    newFile('$myPackageLibPath/a.dart', content: r'''
 @deprecated
-library deprecated_library;
 class A {}
 ''');
 
     await assertErrorsInCode(r'''
-import 'package:aaa/a.dart';
-f(A a) {}
+import 'a.dart';
+
+void f(A a) {}
 ''', [
-      error(HintCode.DEPRECATED_MEMBER_USE, 0, 28),
+      error(HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE, 25, 1),
     ]);
   }
-
-  test_bazelWorkspace() async {
-    resetWithFooLibrary(r'''
-@deprecated
-library deprecated_library;
-class A {}
-''');
-
-    newFile('/workspace/WORKSPACE');
-    newFile('/workspace/project/BUILD');
-    newFolder('/workspace/bazel-genfiles');
-
-    await assertErrorsInFile('/workspace/project/lib/lib1.dart', r'''
-import 'package:aaa/a.dart';
-f(A a) {}
-''', [
-      error(HintCode.DEPRECATED_MEMBER_USE, 0, 28),
-    ]);
-  }
-
-  test_bazelWorkspace_sameWorkspace() async {
-    newFile('/workspace/WORKSPACE');
-    newFile('/workspace/project_a/BUILD');
-    newFile('/workspace/project_b/BUILD');
-    newFolder('/workspace/bazel-genfiles');
-
-    newFile('/workspace/project_a/lib/deprecated_library.dart', content: r'''
-@deprecated
-library deprecated_library;
-class A {}
-''');
-
-    await assertErrorsInFile('/workspace/project_b/lib/lib1.dart', r'''
-import '../../project_a/lib/deprecated_library.dart';
-f(A a) {}
-''', [
-      error(HintCode.DEPRECATED_MEMBER_USE, 0, 53),
-    ]);
-  }
-
-  test_export() async {
-    resetWithFooLibrary(r'''
-@deprecated
-library deprecated_library;
-class A {}
-''');
-
-    newPubPackage('/pkg1');
-    await assertErrorsInFile('/pkg1/lib/lib1.dart', '''
-export 'package:aaa/a.dart';
-''', [
-      error(HintCode.DEPRECATED_MEMBER_USE, 0, 28),
-    ]);
-  }
-
-  test_fieldGet_implicitGetter() async {
-    resetWithFooLibrary(r'''
-class A {
-  @Deprecated('0.9')
-  bool bob = true;
 }
-''');
 
-    newPubPackage('/pkg1');
-    await assertErrorsInFile('/pkg1/lib/lib1.dart', r'''
-import 'package:aaa/a.dart';
-void main() { A().bob; }
-''', [
-      error(HintCode.DEPRECATED_MEMBER_USE_WITH_MESSAGE, 47, 3),
-    ]);
-  }
+@reflectiveTest
+class DeprecatedMemberUseFromSamePackage_PackageBuildWorkspaceTest
+    extends _PackageBuildWorkspaceBase {
+  test_generated() async {
+    newFile('$testPackageRootPath/pubspec.yaml', content: 'name: test');
 
-  test_fieldSet_implicitSetter() async {
-    resetWithFooLibrary(r'''
-class A {
-  @Deprecated('0.9')
-  bool bob = true;
-}
-''');
-
-    newPubPackage('/pkg1');
-    await assertErrorsInFile('/pkg1/lib/lib1.dart', r'''
-import 'package:aaa/a.dart';
-void main() { A().bob = false; }
-''', [
-      error(HintCode.DEPRECATED_MEMBER_USE_WITH_MESSAGE, 47, 3),
-    ]);
-  }
-
-  test_gnWorkspace() async {
-    resetWithFooLibrary(r'''
+    _newTestPackageGeneratedFile(
+      packageName: 'test',
+      pathInLib: 'a.dart',
+      content: r'''
 @deprecated
-library deprecated_library;
 class A {}
-''');
+''',
+    );
 
-    newFolder('/workspace/.jiri_root');
-    newFile('/workspace/project/pubspec.yaml');
-    String buildDir = convertPath('out/debug-x87_128');
-    newFile('/workspace/.config', content: '''
-FOO=foo
-FUCHSIA_BUILD_DIR=$buildDir
-BAR=bar
-''');
-    newFile('/workspace/out/debug-x87_128/dartlang/gen/project/foo.packages');
+    await assertErrorsInCode(r'''
+import 'a.dart';
 
-    await assertErrorsInFile('/workspace/project/lib/lib1.dart', r'''
-import 'package:aaa/a.dart';
-f(A a) {}
+void f(A a) {}
 ''', [
-      error(HintCode.DEPRECATED_MEMBER_USE, 0, 28),
+      error(HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE, 25, 1),
     ]);
   }
 
-  test_gnWorkspace_sameWorkspace() async {
-    newFolder('/workspace/.jiri_root');
-    newFile('/workspace/project_a/pubspec.yaml');
-    newFile('/workspace/project_b/pubspec.yaml');
-    newFile('/workspace/project_a/BUILD.gn');
-    newFile('/workspace/project_b/BUILD.gn');
-    String buildDir = convertPath('out/debug-x87_128');
-    newFile('/workspace/.config', content: '''
-FOO=foo
-FUCHSIA_BUILD_DIR=$buildDir
-''');
-    newFile('/workspace/out/debug-x87_128/dartlang/gen/project_a/foo.packages');
+  test_lib() async {
+    newFile('$testPackageRootPath/pubspec.yaml', content: 'name: test');
+    _createTestPackageBuildMarker();
 
-    newFile('/workspace/project_a/lib/deprecated_library.dart', content: r'''
+    newFile('$testPackageLibPath/a.dart', content: r'''
 @deprecated
-library deprecated_library;
 class A {}
 ''');
 
-    await assertErrorsInFile('/workspace/project_b/lib/lib1.dart', r'''
-import '../../project_a/lib/deprecated_library.dart';
-f(A a) {}
-''', [
-      error(HintCode.DEPRECATED_MEMBER_USE, 0, 53),
-    ]);
-  }
-
-  test_import() async {
-    resetWithFooLibrary(r'''
-@deprecated
-library deprecated_library;
-class A {}
-''');
-
-    await resolveTestCode(r'''
-import 'package:aaa/a.dart';
-f(A a) {}
-''');
-    expect(result.errors[0].message, contains('package:aaa/a.dart'));
-  }
-
-  test_methodInvocation_constant() async {
-    resetWithFooLibrary(r'''
-class A {
-  @deprecated
-  m() {}
-}
-''');
-
     await assertErrorsInCode(r'''
-import 'package:aaa/a.dart';
-void main() => A().m();
+import 'a.dart';
+
+void f(A a) {}
 ''', [
-      error(HintCode.DEPRECATED_MEMBER_USE, 48, 1),
+      error(HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE, 25, 1),
     ]);
   }
-
-  test_methodInvocation_constructor() async {
-    resetWithFooLibrary(r'''
-class A {
-  @Deprecated('0.9')
-  m() {}
 }
-''');
 
-    await assertErrorsInCode(r'''
-import 'package:aaa/a.dart';
-void main() => A().m();
-''', [
-      error(HintCode.DEPRECATED_MEMBER_USE_WITH_MESSAGE, 48, 1),
-    ]);
+class _PackageBuildWorkspaceBase extends PubPackageResolutionTest {
+  String get testPackageGeneratedPath {
+    return '$testPackageRootPath/.dart_tool/build/generated';
   }
 
-  test_packageBuildWorkspace() async {
-    resetWithFooLibrary(r'''
-@deprecated
-library deprecated_library;
-class A {}
-''');
-
-    newFolder('/workspace/.dart_tool/build/generated/project/lib');
-    newFile('/workspace/pubspec.yaml', content: 'name: project');
-
-    await assertErrorsInFile('/workspace/package/lib/lib1.dart', r'''
-import 'package:aaa/a.dart';
-f(A a) {}
-''', [
-      error(HintCode.DEPRECATED_MEMBER_USE, 0, 28),
-    ]);
+  @override
+  void setUp() {
+    super.setUp();
   }
 
-  test_setterInvocation_constructor() async {
-    resetWithFooLibrary(r'''
-class A {
-  @Deprecated('0.9')
-  set bob(bool b) { }
-}
-''');
+  @override
+  void verifyCreatedCollection() {
+    super.verifyCreatedCollection();
+    assertPackageBuildWorkspaceFor(testFilePath);
+  }
 
-    await assertErrorsInCode(r'''
-import 'package:aaa/a.dart';
-void main() { A().bob = false; }
-''', [
-      error(HintCode.DEPRECATED_MEMBER_USE_WITH_MESSAGE, 47, 3),
-    ]);
+  void _createTestPackageBuildMarker() {
+    newFolder(testPackageGeneratedPath);
+  }
+
+  void _newTestPackageGeneratedFile({
+    @required String packageName,
+    @required String pathInLib,
+    @required String content,
+  }) {
+    newFile(
+      '$testPackageGeneratedPath/$packageName/lib/$pathInLib',
+      content: content,
+    );
   }
 }
diff --git a/pkg/analyzer/test/src/diagnostics/mixin_on_sealed_class_test.dart b/pkg/analyzer/test/src/diagnostics/mixin_on_sealed_class_test.dart
index 74a169e..f140857 100644
--- a/pkg/analyzer/test/src/diagnostics/mixin_on_sealed_class_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/mixin_on_sealed_class_test.dart
@@ -2,13 +2,10 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-import 'package:analyzer/file_system/file_system.dart';
 import 'package:analyzer/src/error/codes.dart';
-import 'package:analyzer/src/test_utilities/package_mixin.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
-import '../../generated/test_support.dart';
-import '../dart/resolution/driver_resolution.dart';
+import '../dart/resolution/context_collection_resolution.dart';
 
 main() {
   defineReflectiveSuite(() {
@@ -17,107 +14,91 @@
 }
 
 @reflectiveTest
-class MixinOnSealedClassTest extends DriverResolutionTest with PackageMixin {
+class MixinOnSealedClassTest extends PubPackageResolutionTest {
+  @override
+  void setUp() {
+    super.setUp();
+    writeTestPackageConfigWithMeta();
+  }
+
   test_mixinOnSealedClass() async {
-    addMetaPackage();
-    _addPackage('foo', r'''
+    writeTestPackageConfigWith({
+      'foo': '$workspaceRootPath/foo',
+    }, meta: true);
+
+    newFile('$workspaceRootPath/foo/lib/foo.dart', content: r'''
 import 'package:meta/meta.dart';
 @sealed class Foo {}
 ''');
 
-    _newPubPackageRoot('/pkg1');
-    newFile('/pkg1/lib/lib1.dart', content: r'''
+    await assertErrorsInCode(r'''
 import 'package:foo/foo.dart';
 mixin Bar on Foo {}
-''');
-    await _resolveFile('/pkg1/lib/lib1.dart', [
+''', [
       error(HintCode.MIXIN_ON_SEALED_CLASS, 31, 19),
     ]);
   }
 
   test_withinLibrary_OK() async {
-    addMetaPackage();
-
-    _newPubPackageRoot('/pkg1');
-    newFile('/pkg1/lib/lib1.dart', content: r'''
+    await assertNoErrorsInCode(r'''
 import 'package:meta/meta.dart';
 @sealed class Foo {}
-
 mixin Bar on Foo {}
 ''');
-    await _resolveFile('/pkg1/lib/lib1.dart');
   }
 
   test_withinPackageLibDirectory_OK() async {
-    addMetaPackage();
-
-    _newPubPackageRoot('/pkg1');
-    newFile('/pkg1/lib/lib1.dart', content: r'''
+    newFile('$testPackageLibPath/lib1.dart', content: r'''
 import 'package:meta/meta.dart';
 @sealed class Foo {}
 ''');
-    newFile('/pkg1/lib/src/lib2.dart', content: r'''
+
+    newFile('$testPackageLibPath/src/lib2.dart', content: r'''
 import '../lib1.dart';
 mixin Bar on Foo {}
 ''');
-    await _resolveFile('/pkg1/lib/lib1.dart');
-    await _resolveFile('/pkg1/lib/src/lib2.dart');
+
+    await resolveFile2('$testPackageLibPath/lib1.dart');
+    assertNoErrorsInResult();
+
+    await resolveFile2('$testPackageLibPath/src/lib2.dart');
+    assertNoErrorsInResult();
   }
 
   test_withinPackageTestDirectory_OK() async {
-    addMetaPackage();
-
-    _newPubPackageRoot('/pkg1');
-    newFile('/pkg1/lib/lib1.dart', content: r'''
+    newFile('$testPackageLibPath/lib1.dart', content: r'''
 import 'package:meta/meta.dart';
 @sealed class Foo {}
 ''');
-    newFile('/pkg1/test/test.dart', content: r'''
-import '../lib/lib1.dart';
+
+    newFile('$testPackageRootPath/test/lib2.dart', content: r'''
+import 'package:test/lib1.dart';
 mixin Bar on Foo {}
 ''');
-    await _resolveFile('/pkg1/lib/lib1.dart');
-    await _resolveFile('/pkg1/test/test.dart');
+
+    await resolveFile2('$testPackageLibPath/lib1.dart');
+    assertNoErrorsInResult();
+
+    await resolveFile2('$testPackageRootPath/test/lib2.dart');
+    assertNoErrorsInResult();
   }
 
   test_withinPart_OK() async {
-    addMetaPackage();
-
-    _newPubPackageRoot('/pkg1');
-    newFile('/pkg1/lib/lib1.dart', content: r'''
+    newFile('$testPackageLibPath/lib1.dart', content: r'''
 import 'package:meta/meta.dart';
 part 'part1.dart';
 @sealed class Foo {}
 ''');
-    newFile('/pkg1/lib/part1.dart', content: r'''
+
+    newFile('$testPackageLibPath/part1.dart', content: r'''
 part of 'lib1.dart';
 mixin Bar on Foo {}
 ''');
-    await _resolveFile('/pkg1/lib/lib1.dart');
-  }
 
-  /// Add a package named [name], and one library file, with content
-  /// [libraryContent].
-  void _addPackage(String name, String libraryContent) {
-    Folder lib = addPubPackage(name);
-    newFile(join(lib.path, '$name.dart'), content: libraryContent);
-  }
+    await resolveFile2('$testPackageLibPath/lib1.dart');
+    assertNoErrorsInResult();
 
-  /// Write a pubspec file at [root], so that BestPracticesVerifier can see
-  /// that [root] is the root of a PubWorkspace, and a PubWorkspacePackage.
-  void _newPubPackageRoot(String root) {
-    newFile('$root/pubspec.yaml');
-    configureWorkspace(root: root);
-  }
-
-  /// Resolve the file with the given [path].
-  ///
-  /// Similar to ResolutionTest.resolveTestFile, but a custom path is supported.
-  Future<void> _resolveFile(
-    String path, [
-    List<ExpectedError> expectedErrors = const [],
-  ]) async {
-    result = await resolveFile(convertPath(path));
-    assertErrorsInResolvedUnit(result, expectedErrors);
+    await resolveFile2('$testPackageLibPath/part1.dart');
+    assertNoErrorsInResult();
   }
 }