Skip to content

Commit

Permalink
mockito: stop using deprecated analyzer APIs.
Browse files Browse the repository at this point in the history
Also remove some unused elements.

PiperOrigin-RevId: 673016124
  • Loading branch information
srawlins authored and copybara-github committed Sep 10, 2024
1 parent eb4d1da commit a3f92ef
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
15 changes: 5 additions & 10 deletions lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ class _TypeVisitor extends RecursiveElementVisitor<void> {
if (!alreadyVisitedElement) {
type.element.typeParameters.forEach(visitTypeParameterElement);

final toStringMethod =
type.element.lookUpMethod('toString', type.element.library);
final toStringMethod = type.element.augmented
.lookUpMethod(name: 'toString', library: type.element.library);
if (toStringMethod != null && toStringMethod.parameters.isNotEmpty) {
// In a Fake class which implements a class which overrides `toString`
// with additional (optional) parameters, we must also override
Expand Down Expand Up @@ -594,9 +594,7 @@ class _MockTargetGatherer {
var type = _determineDartType(typeToMock, entryLib.typeProvider);
final mockTypeArguments = mockType?.typeArguments;
if (mockTypeArguments != null) {
final typeName =
type.alias?.element.getDisplayString(withNullability: false) ??
'type $type';
final typeName = type.alias?.element.getDisplayString() ?? 'type $type';
final typeArguments = type.alias?.typeArguments ?? type.typeArguments;
// Check explicit type arguments for unknown types that were
// turned into `dynamic` by the analyzer.
Expand Down Expand Up @@ -1849,7 +1847,7 @@ class _MockClassInfo {
// TODO(srawlins): It seems like this might be revivable, but Angular
// does not revive Types; we should investigate this if users request it.
final type = object.toTypeValue()!;
final typeStr = type.getDisplayString(withNullability: false);
final typeStr = type.getDisplayString();
throw _ReviveException('default value is a Type: $typeStr.');
} else {
// If [constant] is not null, a literal, or a type, then it must be an
Expand Down Expand Up @@ -2176,10 +2174,7 @@ class _MockClassInfo {
{for (final f in type.namedFields) f.name: _typeReference(f.type)})
..isNullable = forceNullable || typeSystem.isNullable(type));
} else {
return referImported(
type.getDisplayString(withNullability: false),
_typeImport(type.element),
);
return referImported(type.getDisplayString(), _typeImport(type.element));
}
}

Expand Down
8 changes: 0 additions & 8 deletions test/builder/custom_mocks_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ void main() {}
'''
};

const _constructorWithThrowOnMissingStub = '''
MockFoo() {
_i1.throwOnMissingStub(this);
}''';

void main() {
late InMemoryAssetWriter writer;

Expand Down Expand Up @@ -1755,9 +1750,6 @@ void main() {
});
}

TypeMatcher<List<int>> _containsAllOf(a, [b]) => decodedMatches(
b == null ? allOf(contains(a)) : allOf(contains(a), contains(b)));

/// Expect that [testBuilder], given [assets], throws an
/// [InvalidMockitoAnnotationException] with a message containing [message].
void _expectBuilderThrows({
Expand Down

0 comments on commit a3f92ef

Please sign in to comment.