This worked for the latest dependencies (01/16/2022). Complete answer for 2-3 errors:
added: build_runner: ^2.1.7
to pubspec.yaml
//...
import 'package:mockito/annotations.dart';
class MockNumberTriviaRepository extends Mock implements NumberTriviaRepo {}
@GenerateMocks([NumberTriviaRepo])
void main() {
late GetConcreteNumberTrivia usecases;
late MockNumberTriviaRepository mockNumberTriviaRepository;
late int tNumber;
late NumberTrivia tNumberTrivia;
setUp(() {
mockNumberTriviaRepository = MockNumberTriviaRepository();
usecases = GetConcreteNumberTrivia(repo: mockNumberTriviaRepository);
tNumber = 1;
tNumberTrivia = NumberTrivia(text: 'test', number: 1);
});
test('should get a trivia for the number from the repo', () async {
// arrange
when(mockNumberTriviaRepository.getConcreteNumberTrivia(tNumber))
.thenAnswer((_) async => Right(tNumberTrivia));
// act
final result = await usecases.execute(number: tNumber);
//assert
expect(result, Right(tNumberTrivia));
verify(mockNumberTriviaRepository.getConcreteNumberTrivia(tNumber));
verifyNoMoreInteractions(mockNumberTriviaRepository);
});
}
class NumberTriviaRepository:
abstract class NumberTriviaRepository {
Future<Either<Failure, NumberTrivia>>? getConcreteNumberTrivia(int number);
Future<Either<Failure, NumberTrivia>>? getRandomNumberTrivia();
}
class GetConcreteNumberTrivia:
class GetConcreteNumberTrivia {
final NumberTriviaRepository repo;
GetConcreteNumberTrivia({
required this.repo,
});
Future<Either<Failure, NumberTrivia>?> execute({required int number}) async {
return await repo.getConcreteNumberTrivia(number);
}
}