Skip to content

Commit

Permalink
Remove unnecessary List mock causing mockito builder issues
Browse files Browse the repository at this point in the history
Errors look like:

  Invalid @GenerateMocks annotation: Mockito cannot generate a valid mock class which implements 'List' for the following reasons:
    The method 'Iterable.reduce' features a non-nullable unknown return type, and cannot be stubbed. Try generating this mock with a MockSpec with 'unsupportedMembers' or a dummy generator (see https://pub.dev/documentation/mockito/latest/annotations/MockSpec-class.html).
  • Loading branch information
greglittlefield-wf committed Feb 13, 2023
1 parent c6009fc commit 578132d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 19 deletions.
9 changes: 0 additions & 9 deletions test/mockito.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,13 @@ import 'package:mockito/annotations.dart';

@GenerateMocks([], customMocks: [
MockSpec<Logger>(returnNullOnMissingStub: true),
MockSpec<List>(fallbackGenerators: {
#[]: listIndexOperatorShim,
#removeAt: listRemoveAtShim,
#removeLast: listRemoveLastShim,
}, returnNullOnMissingStub: true),
MockSpec<Map>(fallbackGenerators: {
#update: mapUpdateShim,
#putIfAbsent: mapPutIfAbsentShim,
}, returnNullOnMissingStub: true)
])
void main() {}

dynamic listIndexOperatorShim(int index) => 1;
dynamic listRemoveAtShim(int index) => 1;
dynamic listRemoveLastShim() => 1;

String mapUpdateShim<K, V>(K key, V Function(V value) update,
{V Function() ifAbsent}) =>
'value';
Expand Down
11 changes: 5 additions & 6 deletions test/mockito.mocks.dart
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
// Mocks generated by Mockito 5.0.15 from annotations
// Mocks generated by Mockito 5.2.0 from annotations
// in over_react/test/mockito.dart.
// Do not manually edit this file.

// @dart=2.9

// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'package:logging/src/logger.dart' as _i2;
import 'package:mockito/mockito.dart' as _i1;

// ignore_for_file: type=lint
// ignore_for_file: avoid_redundant_argument_values
// ignore_for_file: avoid_setters_without_getters
// ignore_for_file: comment_references
// ignore_for_file: implementation_imports
// ignore_for_file: invalid_use_of_visible_for_testing_member
// ignore_for_file: prefer_const_constructors
// ignore_for_file: unnecessary_parenthesis
// ignore_for_file: camel_case_types

/// A class which mocks [Logger].
///
/// See the documentation for Mockito's code generation for more information.
class MockLogger extends _i1.Mock implements _i2.Logger {}

/// A class which mocks [List].
///
/// See the documentation for Mockito's code generation for more information.
class MockList<E> extends _i1.Mock implements List<E> {}

/// A class which mocks [Map].
///
/// See the documentation for Mockito's code generation for more information.
Expand Down
4 changes: 0 additions & 4 deletions test/over_react_redux/value_mutation_checker_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import 'package:over_react/src/over_react_redux/value_mutation_checker.dart';
import 'package:react/react.dart' as react;
import 'package:test/test.dart';

import '../mockito.mocks.dart';

// ignore_for_file: invalid_use_of_protected_member
main() {
group('Value Mutation Checker:', () {
Expand Down Expand Up @@ -106,13 +104,11 @@ void sharedHashTests(InstanceHasher Function() getHasher) {

test('true if the object is a map or iterable', () {
final props = DomProps(react.a as ReactComponentFactoryProxy);
final list = MockList();

expect(hasher.canHash({'e', 'a', 'b'}), isTrue);
expect(hasher.canHash([]), isTrue);
expect(hasher.canHash({'a': 1}), isTrue);
expect(hasher.canHash(props), isTrue);
expect(hasher.canHash(list), isTrue);
});
});

Expand Down

0 comments on commit 578132d

Please sign in to comment.