Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AbedElazizShe/e22804720b2f861f24a6ef482e0450f5 to your computer and use it in GitHub Desktop.
Save AbedElazizShe/e22804720b2f861f24a6ef482e0450f5 to your computer and use it in GitHub Desktop.
import 'package:data/data.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:remote/remote.dart';
import 'package:remote/src/models/article/articles_response_model.dart';
import '../mock/mock_articles_model.dart';
import 'articles_remote_repository_impl_test.mocks.dart';
@GenerateMocks([ArticlesService, ArticlesEntityMapper])
void main() {
late ArticlesService articlesService;
late ArticlesEntityMapper articlesEntityMapper;
late ArticlesRemoteRepositoryImpl articlesRemoteRepositoryImpl;
setUp(() {
articlesService = MockArticlesService();
articlesEntityMapper = MockArticlesEntityMapper();
articlesRemoteRepositoryImpl = ArticlesRemoteRepositoryImpl(
articlesService: articlesService,
articlesEntityMapper: articlesEntityMapper);
});
test('should get list of ArticlesEntity when fetching most emailed articles',
() async {
final ArticlesResponseModel articlesResponseModel =
mockArticlesResponseModel;
when(articlesService.getMostEmailedArticles())
.thenAnswer((_) async => articlesResponseModel);
when(articlesEntityMapper.mapFromModel(articlesResponseModel.results[0]))
.thenReturn(mockArticlesEntity);
final List<ArticlesEntity> articlesEntity =
await articlesRemoteRepositoryImpl.getMostEmailedArticles();
expect(articlesEntity, isNotNull);
expect(articlesEntity.length, same(1));
verify(articlesService.getMostEmailedArticles()).called(1);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment