From cf39c318f33ae3a2e47e0c662f358b58b810445d Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Sun, 15 Oct 2023 23:43:27 +0200 Subject: [PATCH 01/32] refactor: update helper layer in tests --- test/helpers/extensions/extensions.dart | 1 + .../{pump_app.dart => extensions/widget_tester_ext.dart} | 2 +- test/helpers/helpers.dart | 3 ++- test/helpers/mocks/mock_numbers_service.dart | 4 ++++ test/helpers/mocks/mocks.dart | 1 + 5 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 test/helpers/extensions/extensions.dart rename test/helpers/{pump_app.dart => extensions/widget_tester_ext.dart} (90%) create mode 100644 test/helpers/mocks/mock_numbers_service.dart create mode 100644 test/helpers/mocks/mocks.dart diff --git a/test/helpers/extensions/extensions.dart b/test/helpers/extensions/extensions.dart new file mode 100644 index 0000000..7ea732b --- /dev/null +++ b/test/helpers/extensions/extensions.dart @@ -0,0 +1 @@ +export 'widget_tester_ext.dart'; diff --git a/test/helpers/pump_app.dart b/test/helpers/extensions/widget_tester_ext.dart similarity index 90% rename from test/helpers/pump_app.dart rename to test/helpers/extensions/widget_tester_ext.dart index d120468..f05253c 100644 --- a/test/helpers/pump_app.dart +++ b/test/helpers/extensions/widget_tester_ext.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:numbers/src/core/l10n/l10n.dart'; -extension PumpApp on WidgetTester { +extension WidgetTesterExt on WidgetTester { Future pumpApp(Widget widget) { return pumpWidget( MaterialApp( diff --git a/test/helpers/helpers.dart b/test/helpers/helpers.dart index b15fe65..d31d42e 100644 --- a/test/helpers/helpers.dart +++ b/test/helpers/helpers.dart @@ -1 +1,2 @@ -export 'pump_app.dart'; +export 'extensions/extensions.dart'; +export 'mocks/mocks.dart'; diff --git a/test/helpers/mocks/mock_numbers_service.dart b/test/helpers/mocks/mock_numbers_service.dart new file mode 100644 index 0000000..b622765 --- /dev/null +++ b/test/helpers/mocks/mock_numbers_service.dart @@ -0,0 +1,4 @@ +import 'package:mocktail/mocktail.dart'; +import 'package:numbers/src/features/number/number.dart'; + +final class MockNumbersService extends Mock implements NumbersService {} diff --git a/test/helpers/mocks/mocks.dart b/test/helpers/mocks/mocks.dart new file mode 100644 index 0000000..62cbd62 --- /dev/null +++ b/test/helpers/mocks/mocks.dart @@ -0,0 +1 @@ +export 'mock_numbers_service.dart'; From b8b5bf34d01b9b4a953c3b8d700a11a4e96355d7 Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Sun, 15 Oct 2023 23:44:25 +0200 Subject: [PATCH 02/32] refactor: extend DataState class from Equatable --- lib/src/core/resources/data_state.dart | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/src/core/resources/data_state.dart b/lib/src/core/resources/data_state.dart index ab1d689..ce501dc 100644 --- a/lib/src/core/resources/data_state.dart +++ b/lib/src/core/resources/data_state.dart @@ -1,12 +1,14 @@ -import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:equatable/equatable.dart'; import 'package:numbers/src/core/core.dart'; -@immutable -sealed class DataState { +sealed class DataState extends Equatable { const DataState({this.data, this.details}); final T? data; final ErrorDetails? details; + + @override + List get props => [data, details]; } final class DataSuccess extends DataState { From c0a8ab968e6f16afb76c049aff0362b3450c3599 Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Sun, 15 Oct 2023 23:53:43 +0200 Subject: [PATCH 03/32] test: add missing tests of NumberRepositoryImpl --- .../number_repository_impl_test.dart | 99 ------------------- .../number_repository_impl_test.dart | 99 +++++++++++++++++++ 2 files changed, 99 insertions(+), 99 deletions(-) delete mode 100644 test/src/data/repositories/number_repository_impl_test.dart create mode 100644 test/src/features/number/data/repositories/number_repository_impl_test.dart diff --git a/test/src/data/repositories/number_repository_impl_test.dart b/test/src/data/repositories/number_repository_impl_test.dart deleted file mode 100644 index 59ac156..0000000 --- a/test/src/data/repositories/number_repository_impl_test.dart +++ /dev/null @@ -1,99 +0,0 @@ -import 'package:flutter_test/flutter_test.dart'; -import 'package:mocktail/mocktail.dart'; -import 'package:numbers/src/core/core.dart'; -import 'package:numbers/src/data/data.dart'; -import 'package:numbers/src/domain/domain.dart'; - -class MockNumbersApiService extends Mock implements NumbersApiService {} - -void main() { - late MockNumbersApiService mockNumbersApiService; - late GetNumberParams numberRequestParams; - late NumberRepositoryImpl sut; - - setUp( - () { - mockNumbersApiService = MockNumbersApiService(); - numberRequestParams = const GetNumberParams(number: 0); - sut = NumberRepositoryImpl(service: mockNumbersApiService); - }, - ); - - void arrangeNumbersApiServiceGetNumberResponse() { - when(() => mockNumbersApiService.getNumber(params: numberRequestParams)) - .thenAnswer((_) async => const NumberModel(info: '')); - } - - void arrangeNumbersApiServiceGetRandomNumberResponse() { - when(() => mockNumbersApiService.getRandomNumber()) - .thenAnswer((_) async => const NumberModel(info: '')); - } - - group( - 'NumberRepositoryImpl', - () { - test( - 'calls "getNumber" function only one time', - () async { - arrangeNumbersApiServiceGetNumberResponse(); - - await sut.getNumber(numberRequestParams); - - verify( - () => mockNumbersApiService.getNumber(params: numberRequestParams), - ).called(1); - }, - ); - - test( - 'calls "getRandomNumber" function two times', - () async { - arrangeNumbersApiServiceGetRandomNumberResponse(); - - await sut.getRandomNumber(); - await sut.getRandomNumber(); - - verify( - () => mockNumbersApiService.getRandomNumber(), - ).called(2); - }, - ); - - test( - 'gets number from the service', - () async { - arrangeNumbersApiServiceGetNumberResponse(); - - final result = await sut.getNumber(numberRequestParams); - - expect( - result, - equals(DataSuccess(const NumberModel(info: '').toEntity())), - ); - verify( - () => mockNumbersApiService.getNumber(params: numberRequestParams), - ); - verifyNoMoreInteractions(mockNumbersApiService); - }, - ); - - test( - 'gets random number from the service', - () async { - arrangeNumbersApiServiceGetRandomNumberResponse(); - - final result = await sut.getRandomNumber(); - - expect( - result, - equals(const DataSuccess(Number(info: ''))), - ); - verify( - () => mockNumbersApiService.getRandomNumber(), - ); - verifyNoMoreInteractions(mockNumbersApiService); - }, - ); - }, - ); -} diff --git a/test/src/features/number/data/repositories/number_repository_impl_test.dart b/test/src/features/number/data/repositories/number_repository_impl_test.dart new file mode 100644 index 0000000..e269f14 --- /dev/null +++ b/test/src/features/number/data/repositories/number_repository_impl_test.dart @@ -0,0 +1,99 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:mocktail/mocktail.dart'; +import 'package:numbers/src/core/core.dart'; +import 'package:numbers/src/features/number/number.dart'; + +import '../../../../../helpers/helpers.dart'; + +void main() { + late MockNumbersService mockNumbersService; + late GetNumberParams getNumberParams; + late NumberRepositoryImpl sut; + + setUpAll( + () { + mockNumbersService = MockNumbersService(); + getNumberParams = const GetNumberParams(number: 0); + sut = NumberRepositoryImpl(service: mockNumbersService); + }, + ); + + void fakeGetNumberResponse(String? info) { + if (info == null) { + when(() => mockNumbersService.getNumber(params: getNumberParams)) + .thenThrow(const GetNumberException('message', 'stackTrace')); + } else { + when(() => mockNumbersService.getNumber(params: getNumberParams)) + .thenAnswer((_) async => NumberDto(info: info)); + } + } + + void fakeGetRandomNumberResponse(String? info) { + if (info == null) { + when(() => mockNumbersService.getRandomNumber()) + .thenThrow(const GetRandomNumberException('message', 'stackTrace')); + } else { + when(() => mockNumbersService.getRandomNumber()) + .thenAnswer((_) async => NumberDto(info: info)); + } + } + + group( + 'NumberRepositoryImpl', + () { + test( + 'getNumber returns DataSuccess that contains an info of a number', + () { + const info = 'test_info'; + + fakeGetNumberResponse(info); + + expect( + sut.getNumber(getNumberParams), + completion(const DataSuccess(Number(info: info))), + ); + }, + ); + + test( + 'getRandomNumber returns DataSuccess that contains an info of a random ' + 'number', + () { + const info = 'test_info'; + + fakeGetRandomNumberResponse(info); + + expect( + sut.getRandomNumber(), + completion(const DataSuccess(Number(info: info))), + ); + }, + ); + + test( + 'getNumber returns DataFailure when GetNumberException is thrown', + () { + fakeGetNumberResponse(null); + + expect( + sut.getNumber(getNumberParams), + completion(isA>()), + ); + }, + ); + + test( + 'getRandomNumber returns DataFailure when GetRandomNumberException is ' + 'thrown', + () { + fakeGetRandomNumberResponse(null); + + expect( + sut.getRandomNumber(), + completion(isA>()), + ); + }, + ); + }, + ); +} From 145a44439071225f0d5899d4275cebf1c5d40682 Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Mon, 16 Oct 2023 21:02:32 +0200 Subject: [PATCH 04/32] test: add missing tests of GetNumberUsecase --- .../helpers/mocks/mock_number_repository.dart | 4 ++ test/helpers/mocks/mocks.dart | 1 + .../usecases/get_number_usecase_test.dart | 60 ----------------- .../get_random_number_usecase_test.dart | 56 ---------------- .../usecases/get_number_usecase_test.dart | 67 +++++++++++++++++++ .../get_random_number_usecase_test.dart | 56 ++++++++++++++++ 6 files changed, 128 insertions(+), 116 deletions(-) create mode 100644 test/helpers/mocks/mock_number_repository.dart delete mode 100644 test/src/domain/usecases/get_number_usecase_test.dart delete mode 100644 test/src/domain/usecases/get_random_number_usecase_test.dart create mode 100644 test/src/features/number/domain/usecases/get_number_usecase_test.dart create mode 100644 test/src/features/number/domain/usecases/get_random_number_usecase_test.dart diff --git a/test/helpers/mocks/mock_number_repository.dart b/test/helpers/mocks/mock_number_repository.dart new file mode 100644 index 0000000..4e78da3 --- /dev/null +++ b/test/helpers/mocks/mock_number_repository.dart @@ -0,0 +1,4 @@ +import 'package:mocktail/mocktail.dart'; +import 'package:numbers/src/features/number/number.dart'; + +class MockNumberRepository extends Mock implements NumberRepository {} diff --git a/test/helpers/mocks/mocks.dart b/test/helpers/mocks/mocks.dart index 62cbd62..db89a58 100644 --- a/test/helpers/mocks/mocks.dart +++ b/test/helpers/mocks/mocks.dart @@ -1 +1,2 @@ +export 'mock_number_repository.dart'; export 'mock_numbers_service.dart'; diff --git a/test/src/domain/usecases/get_number_usecase_test.dart b/test/src/domain/usecases/get_number_usecase_test.dart deleted file mode 100644 index a51ee75..0000000 --- a/test/src/domain/usecases/get_number_usecase_test.dart +++ /dev/null @@ -1,60 +0,0 @@ -import 'package:flutter_test/flutter_test.dart'; -import 'package:mocktail/mocktail.dart'; -import 'package:numbers/src/core/core.dart'; -import 'package:numbers/src/domain/domain.dart'; - -const String _kResponseInfo = - '0 is the atomic number of the theoretical element tetraneutron.'; - -class MockNumberRepository extends Mock implements NumberRepository {} - -void main() { - late MockNumberRepository mockNumberRepository; - late GetNumberParams numberRequestParams; - late GetNumberUseCase sut; - - setUp(() { - mockNumberRepository = MockNumberRepository(); - numberRequestParams = const GetNumberParams(number: 0); - sut = GetNumberUseCase(repository: mockNumberRepository); - }); - - void arrangeNumberRepositoryResponse(GetNumberParams params) { - when( - () => mockNumberRepository.getNumber(params), - ).thenAnswer((_) async => const DataSuccess(Number(info: _kResponseInfo))); - } - - group( - 'GetNumberUsecase', - () { - test( - 'calls "getNumber" function only one time', - () async { - arrangeNumberRepositoryResponse(numberRequestParams); - - await sut(params: numberRequestParams); - - verify(() => mockNumberRepository.getNumber(numberRequestParams)) - .called(1); - }, - ); - - test( - 'gets data from the repository', - () async { - arrangeNumberRepositoryResponse(numberRequestParams); - - final result = await sut(params: numberRequestParams); - - expect( - result, - equals(const DataSuccess(Number(info: _kResponseInfo))), - ); - verify(() => mockNumberRepository.getNumber(numberRequestParams)); - verifyNoMoreInteractions(mockNumberRepository); - }, - ); - }, - ); -} diff --git a/test/src/domain/usecases/get_random_number_usecase_test.dart b/test/src/domain/usecases/get_random_number_usecase_test.dart deleted file mode 100644 index 6ba2368..0000000 --- a/test/src/domain/usecases/get_random_number_usecase_test.dart +++ /dev/null @@ -1,56 +0,0 @@ -import 'package:flutter_test/flutter_test.dart'; -import 'package:mocktail/mocktail.dart'; -import 'package:numbers/src/core/core.dart'; -import 'package:numbers/src/domain/domain.dart'; - -class MockNumberRepository extends Mock implements NumberRepository {} - -void main() { - late MockNumberRepository mockNumberRepository; - late NoParams noParams; - late GetRandomNumberUseCase sut; - - setUp(() { - mockNumberRepository = MockNumberRepository(); - noParams = const NoParams(); - sut = GetRandomNumberUseCase(repository: mockNumberRepository); - }); - - void arrangeNumberRepositoryResponse() { - when(mockNumberRepository.getRandomNumber).thenAnswer( - (_) async => const DataFailure(Failure(title: '', message: '')), - ); - } - - group( - 'GetRandomNumberUseCase', - () { - test( - 'calls "getRandomNumber" function only one time', - () async { - arrangeNumberRepositoryResponse(); - - await sut(params: noParams); - - verify(mockNumberRepository.getRandomNumber).called(1); - }, - ); - - test( - 'gets failure from the repository', - () async { - arrangeNumberRepositoryResponse(); - - final result = await sut(params: noParams); - - expect( - result, - equals(const DataFailure(Failure(title: '', message: ''))), - ); - verify(mockNumberRepository.getRandomNumber); - verifyNoMoreInteractions(mockNumberRepository); - }, - ); - }, - ); -} diff --git a/test/src/features/number/domain/usecases/get_number_usecase_test.dart b/test/src/features/number/domain/usecases/get_number_usecase_test.dart new file mode 100644 index 0000000..05161b0 --- /dev/null +++ b/test/src/features/number/domain/usecases/get_number_usecase_test.dart @@ -0,0 +1,67 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:mocktail/mocktail.dart'; +import 'package:numbers/src/core/core.dart'; +import 'package:numbers/src/features/number/number.dart'; + +import '../../../../../helpers/helpers.dart'; + +void main() { + late MockNumberRepository mockNumberRepository; + late GetNumberParams getNumberParams; + late GetNumberUseCase sut; + + setUpAll(() { + mockNumberRepository = MockNumberRepository(); + getNumberParams = const GetNumberParams(number: 0); + sut = GetNumberUseCase(repository: mockNumberRepository); + }); + + void fakeNumberRepositoryResponse(String? info) { + if (info == null) { + when(() => mockNumberRepository.getNumber(getNumberParams)).thenAnswer( + (_) async => const DataFailure( + ErrorDetails( + error: 'error', + message: 'message', + stackTrace: 'stackTrace', + ), + ), + ); + } else { + when( + () => mockNumberRepository.getNumber(getNumberParams), + ).thenAnswer((_) async => DataSuccess(Number(info: info))); + } + } + + group( + 'GetNumberUsecase', + () { + test( + 'returns DataSuccess that contains an info of a number', + () async { + const info = 'test'; + + fakeNumberRepositoryResponse(info); + + expect( + sut(params: getNumberParams), + completion(const DataSuccess(Number(info: info))), + ); + }, + ); + + test( + 'returns DataFailure when error occurs', + () async { + fakeNumberRepositoryResponse(null); + + expect( + sut(params: getNumberParams), + completion(isA>()), + ); + }, + ); + }, + ); +} diff --git a/test/src/features/number/domain/usecases/get_random_number_usecase_test.dart b/test/src/features/number/domain/usecases/get_random_number_usecase_test.dart new file mode 100644 index 0000000..9dd8ce5 --- /dev/null +++ b/test/src/features/number/domain/usecases/get_random_number_usecase_test.dart @@ -0,0 +1,56 @@ +// import 'package:flutter_test/flutter_test.dart'; +// import 'package:mocktail/mocktail.dart'; +// import 'package:numbers/src/core/core.dart'; +// import 'package:numbers/src/domain/domain.dart'; + +// class MockNumberRepository extends Mock implements NumberRepository {} + +// void main() { +// late MockNumberRepository mockNumberRepository; +// late NoParams noParams; +// late GetRandomNumberUseCase sut; + +// setUp(() { +// mockNumberRepository = MockNumberRepository(); +// noParams = const NoParams(); +// sut = GetRandomNumberUseCase(repository: mockNumberRepository); +// }); + +// void arrangeNumberRepositoryResponse() { +// when(mockNumberRepository.getRandomNumber).thenAnswer( +// (_) async => const DataFailure(Failure(title: '', message: '')), +// ); +// } + +// group( +// 'GetRandomNumberUseCase', +// () { +// test( +// 'calls "getRandomNumber" function only one time', +// () async { +// arrangeNumberRepositoryResponse(); + +// await sut(params: noParams); + +// verify(mockNumberRepository.getRandomNumber).called(1); +// }, +// ); + +// test( +// 'gets failure from the repository', +// () async { +// arrangeNumberRepositoryResponse(); + +// final result = await sut(params: noParams); + +// expect( +// result, +// equals(const DataFailure(Failure(title: '', message: ''))), +// ); +// verify(mockNumberRepository.getRandomNumber); +// verifyNoMoreInteractions(mockNumberRepository); +// }, +// ); +// }, +// ); +// } From bf70a3ef5b7d3a38e1196fbe6c812b27e4c61dfa Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Mon, 16 Oct 2023 21:06:47 +0200 Subject: [PATCH 05/32] test: add missing tests of GetRandomNumberUseCase --- .../usecases/get_number_usecase_test.dart | 4 +- .../get_random_number_usecase_test.dart | 121 ++++++++++-------- 2 files changed, 67 insertions(+), 58 deletions(-) diff --git a/test/src/features/number/domain/usecases/get_number_usecase_test.dart b/test/src/features/number/domain/usecases/get_number_usecase_test.dart index 05161b0..1f3146f 100644 --- a/test/src/features/number/domain/usecases/get_number_usecase_test.dart +++ b/test/src/features/number/domain/usecases/get_number_usecase_test.dart @@ -39,7 +39,7 @@ void main() { () { test( 'returns DataSuccess that contains an info of a number', - () async { + () { const info = 'test'; fakeNumberRepositoryResponse(info); @@ -53,7 +53,7 @@ void main() { test( 'returns DataFailure when error occurs', - () async { + () { fakeNumberRepositoryResponse(null); expect( diff --git a/test/src/features/number/domain/usecases/get_random_number_usecase_test.dart b/test/src/features/number/domain/usecases/get_random_number_usecase_test.dart index 9dd8ce5..8cf7901 100644 --- a/test/src/features/number/domain/usecases/get_random_number_usecase_test.dart +++ b/test/src/features/number/domain/usecases/get_random_number_usecase_test.dart @@ -1,56 +1,65 @@ -// import 'package:flutter_test/flutter_test.dart'; -// import 'package:mocktail/mocktail.dart'; -// import 'package:numbers/src/core/core.dart'; -// import 'package:numbers/src/domain/domain.dart'; - -// class MockNumberRepository extends Mock implements NumberRepository {} - -// void main() { -// late MockNumberRepository mockNumberRepository; -// late NoParams noParams; -// late GetRandomNumberUseCase sut; - -// setUp(() { -// mockNumberRepository = MockNumberRepository(); -// noParams = const NoParams(); -// sut = GetRandomNumberUseCase(repository: mockNumberRepository); -// }); - -// void arrangeNumberRepositoryResponse() { -// when(mockNumberRepository.getRandomNumber).thenAnswer( -// (_) async => const DataFailure(Failure(title: '', message: '')), -// ); -// } - -// group( -// 'GetRandomNumberUseCase', -// () { -// test( -// 'calls "getRandomNumber" function only one time', -// () async { -// arrangeNumberRepositoryResponse(); - -// await sut(params: noParams); - -// verify(mockNumberRepository.getRandomNumber).called(1); -// }, -// ); - -// test( -// 'gets failure from the repository', -// () async { -// arrangeNumberRepositoryResponse(); - -// final result = await sut(params: noParams); - -// expect( -// result, -// equals(const DataFailure(Failure(title: '', message: ''))), -// ); -// verify(mockNumberRepository.getRandomNumber); -// verifyNoMoreInteractions(mockNumberRepository); -// }, -// ); -// }, -// ); -// } +import 'package:flutter_test/flutter_test.dart'; +import 'package:mocktail/mocktail.dart'; +import 'package:numbers/src/core/core.dart'; +import 'package:numbers/src/features/number/number.dart'; + +import '../../../../../helpers/helpers.dart'; + +void main() { + late MockNumberRepository mockNumberRepository; + late GetRandomNumberUseCase sut; + + setUp(() { + mockNumberRepository = MockNumberRepository(); + sut = GetRandomNumberUseCase(repository: mockNumberRepository); + }); + + void fakeNumberRepositoryResponse(String? info) { + if (info == null) { + when(() => mockNumberRepository.getRandomNumber()).thenAnswer( + (_) async => const DataFailure( + ErrorDetails( + error: 'error', + message: 'message', + stackTrace: 'stackTrace', + ), + ), + ); + } else { + when( + () => mockNumberRepository.getRandomNumber(), + ).thenAnswer((_) async => DataSuccess(Number(info: info))); + } + } + + group( + 'GetRandomNumberUsecase', + () { + test( + 'returns DataSuccess that contains an info of a number', + () { + const info = 'test'; + + fakeNumberRepositoryResponse(info); + + expect( + sut(), + completion(const DataSuccess(Number(info: info))), + ); + }, + ); + + test( + 'returns DataFailure when error occurs', + () { + fakeNumberRepositoryResponse(null); + + expect( + sut(), + completion(isA>()), + ); + }, + ); + }, + ); +} From e3eeec8c218ea9345f297b882853538e386a7b9a Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Mon, 16 Oct 2023 21:19:51 +0200 Subject: [PATCH 06/32] refactor: make MockNumberRepository class final --- test/helpers/mocks/mock_number_repository.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/helpers/mocks/mock_number_repository.dart b/test/helpers/mocks/mock_number_repository.dart index 4e78da3..8df7183 100644 --- a/test/helpers/mocks/mock_number_repository.dart +++ b/test/helpers/mocks/mock_number_repository.dart @@ -1,4 +1,4 @@ import 'package:mocktail/mocktail.dart'; import 'package:numbers/src/features/number/number.dart'; -class MockNumberRepository extends Mock implements NumberRepository {} +final class MockNumberRepository extends Mock implements NumberRepository {} From 634b82e38651a61b1a248d775f57fce2a9a447a2 Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Mon, 16 Oct 2023 21:25:37 +0200 Subject: [PATCH 07/32] refactor: rename NumberRepository as NumbersRepository --- lib/bootstrap.dart | 4 ++-- ...pository_impl.dart => numbers_repository_impl.dart} | 4 ++-- .../number/data/repositories/repositories.dart | 2 +- ...{number_repository.dart => numbers_repository.dart} | 2 +- .../number/domain/repositories/repositories.dart | 2 +- .../number/domain/usecases/get_number_usecase.dart | 8 ++++---- .../domain/usecases/get_random_number_usecase.dart | 8 ++++---- ...er_repository.dart => mock_numbers_repository.dart} | 2 +- test/helpers/mocks/mocks.dart | 2 +- ...mpl_test.dart => numbers_repository_impl_test.dart} | 6 +++--- .../domain/usecases/get_number_usecase_test.dart | 10 +++++----- .../usecases/get_random_number_usecase_test.dart | 10 +++++----- 12 files changed, 30 insertions(+), 30 deletions(-) rename lib/src/features/number/data/repositories/{number_repository_impl.dart => numbers_repository_impl.dart} (91%) rename lib/src/features/number/domain/repositories/{number_repository.dart => numbers_repository.dart} (82%) rename test/helpers/mocks/{mock_number_repository.dart => mock_numbers_repository.dart} (55%) rename test/src/features/number/data/repositories/{number_repository_impl_test.dart => numbers_repository_impl_test.dart} (95%) diff --git a/lib/bootstrap.dart b/lib/bootstrap.dart index 227689c..539a668 100644 --- a/lib/bootstrap.dart +++ b/lib/bootstrap.dart @@ -73,8 +73,8 @@ Future setup() async { ..registerLazySingleton( () => ThemeRepositoryImpl(service: getIt()), ) - ..registerLazySingleton( - () => NumberRepositoryImpl(service: getIt()), + ..registerLazySingleton( + () => NumbersRepositoryImpl(service: getIt()), ) ..registerLazySingleton( () => GetThemeUseCase(repository: getIt()), diff --git a/lib/src/features/number/data/repositories/number_repository_impl.dart b/lib/src/features/number/data/repositories/numbers_repository_impl.dart similarity index 91% rename from lib/src/features/number/data/repositories/number_repository_impl.dart rename to lib/src/features/number/data/repositories/numbers_repository_impl.dart index dbd8f58..747facf 100644 --- a/lib/src/features/number/data/repositories/number_repository_impl.dart +++ b/lib/src/features/number/data/repositories/numbers_repository_impl.dart @@ -1,8 +1,8 @@ import 'package:numbers/src/core/core.dart'; import 'package:numbers/src/features/number/number.dart'; -final class NumberRepositoryImpl implements NumberRepository { - const NumberRepositoryImpl({ +final class NumbersRepositoryImpl implements NumbersRepository { + const NumbersRepositoryImpl({ required NumbersService service, }) : _numbersService = service; diff --git a/lib/src/features/number/data/repositories/repositories.dart b/lib/src/features/number/data/repositories/repositories.dart index 4860252..c3ad8d5 100644 --- a/lib/src/features/number/data/repositories/repositories.dart +++ b/lib/src/features/number/data/repositories/repositories.dart @@ -1 +1 @@ -export 'number_repository_impl.dart'; +export 'numbers_repository_impl.dart'; diff --git a/lib/src/features/number/domain/repositories/number_repository.dart b/lib/src/features/number/domain/repositories/numbers_repository.dart similarity index 82% rename from lib/src/features/number/domain/repositories/number_repository.dart rename to lib/src/features/number/domain/repositories/numbers_repository.dart index 1de268b..77edac1 100644 --- a/lib/src/features/number/domain/repositories/number_repository.dart +++ b/lib/src/features/number/domain/repositories/numbers_repository.dart @@ -1,7 +1,7 @@ import 'package:numbers/src/core/core.dart'; import 'package:numbers/src/features/number/number.dart'; -abstract interface class NumberRepository { +abstract interface class NumbersRepository { Future> getNumber(GetNumberParams params); Future> getRandomNumber(); } diff --git a/lib/src/features/number/domain/repositories/repositories.dart b/lib/src/features/number/domain/repositories/repositories.dart index 8df4e0f..97b6503 100644 --- a/lib/src/features/number/domain/repositories/repositories.dart +++ b/lib/src/features/number/domain/repositories/repositories.dart @@ -1 +1 @@ -export 'number_repository.dart'; +export 'numbers_repository.dart'; diff --git a/lib/src/features/number/domain/usecases/get_number_usecase.dart b/lib/src/features/number/domain/usecases/get_number_usecase.dart index 2877d82..532e01e 100644 --- a/lib/src/features/number/domain/usecases/get_number_usecase.dart +++ b/lib/src/features/number/domain/usecases/get_number_usecase.dart @@ -4,12 +4,12 @@ import 'package:numbers/src/features/number/number.dart'; final class GetNumberUseCase implements UseCase, GetNumberParams> { const GetNumberUseCase({ - required NumberRepository repository, - }) : _numberRepository = repository; + required NumbersRepository repository, + }) : _numbersRepository = repository; - final NumberRepository _numberRepository; + final NumbersRepository _numbersRepository; @override Future> call({required GetNumberParams params}) => - _numberRepository.getNumber(params); + _numbersRepository.getNumber(params); } diff --git a/lib/src/features/number/domain/usecases/get_random_number_usecase.dart b/lib/src/features/number/domain/usecases/get_random_number_usecase.dart index 816621a..d672cb6 100644 --- a/lib/src/features/number/domain/usecases/get_random_number_usecase.dart +++ b/lib/src/features/number/domain/usecases/get_random_number_usecase.dart @@ -4,12 +4,12 @@ import 'package:numbers/src/features/number/number.dart'; final class GetRandomNumberUseCase implements UseCase, Params> { const GetRandomNumberUseCase({ - required NumberRepository repository, - }) : _numberRepository = repository; + required NumbersRepository repository, + }) : _numbersRepository = repository; - final NumberRepository _numberRepository; + final NumbersRepository _numbersRepository; @override Future> call({Params params = const Params()}) => - _numberRepository.getRandomNumber(); + _numbersRepository.getRandomNumber(); } diff --git a/test/helpers/mocks/mock_number_repository.dart b/test/helpers/mocks/mock_numbers_repository.dart similarity index 55% rename from test/helpers/mocks/mock_number_repository.dart rename to test/helpers/mocks/mock_numbers_repository.dart index 8df7183..635d689 100644 --- a/test/helpers/mocks/mock_number_repository.dart +++ b/test/helpers/mocks/mock_numbers_repository.dart @@ -1,4 +1,4 @@ import 'package:mocktail/mocktail.dart'; import 'package:numbers/src/features/number/number.dart'; -final class MockNumberRepository extends Mock implements NumberRepository {} +final class MockNumbersRepository extends Mock implements NumbersRepository {} diff --git a/test/helpers/mocks/mocks.dart b/test/helpers/mocks/mocks.dart index db89a58..36fa9f4 100644 --- a/test/helpers/mocks/mocks.dart +++ b/test/helpers/mocks/mocks.dart @@ -1,2 +1,2 @@ -export 'mock_number_repository.dart'; +export 'mock_numbers_repository.dart'; export 'mock_numbers_service.dart'; diff --git a/test/src/features/number/data/repositories/number_repository_impl_test.dart b/test/src/features/number/data/repositories/numbers_repository_impl_test.dart similarity index 95% rename from test/src/features/number/data/repositories/number_repository_impl_test.dart rename to test/src/features/number/data/repositories/numbers_repository_impl_test.dart index e269f14..d02cfe6 100644 --- a/test/src/features/number/data/repositories/number_repository_impl_test.dart +++ b/test/src/features/number/data/repositories/numbers_repository_impl_test.dart @@ -8,13 +8,13 @@ import '../../../../../helpers/helpers.dart'; void main() { late MockNumbersService mockNumbersService; late GetNumberParams getNumberParams; - late NumberRepositoryImpl sut; + late NumbersRepositoryImpl sut; setUpAll( () { mockNumbersService = MockNumbersService(); getNumberParams = const GetNumberParams(number: 0); - sut = NumberRepositoryImpl(service: mockNumbersService); + sut = NumbersRepositoryImpl(service: mockNumbersService); }, ); @@ -39,7 +39,7 @@ void main() { } group( - 'NumberRepositoryImpl', + 'NumbersRepositoryImpl', () { test( 'getNumber returns DataSuccess that contains an info of a number', diff --git a/test/src/features/number/domain/usecases/get_number_usecase_test.dart b/test/src/features/number/domain/usecases/get_number_usecase_test.dart index 1f3146f..4e7d99f 100644 --- a/test/src/features/number/domain/usecases/get_number_usecase_test.dart +++ b/test/src/features/number/domain/usecases/get_number_usecase_test.dart @@ -6,19 +6,19 @@ import 'package:numbers/src/features/number/number.dart'; import '../../../../../helpers/helpers.dart'; void main() { - late MockNumberRepository mockNumberRepository; + late MockNumbersRepository mockNumbersRepository; late GetNumberParams getNumberParams; late GetNumberUseCase sut; setUpAll(() { - mockNumberRepository = MockNumberRepository(); + mockNumbersRepository = MockNumbersRepository(); getNumberParams = const GetNumberParams(number: 0); - sut = GetNumberUseCase(repository: mockNumberRepository); + sut = GetNumberUseCase(repository: mockNumbersRepository); }); void fakeNumberRepositoryResponse(String? info) { if (info == null) { - when(() => mockNumberRepository.getNumber(getNumberParams)).thenAnswer( + when(() => mockNumbersRepository.getNumber(getNumberParams)).thenAnswer( (_) async => const DataFailure( ErrorDetails( error: 'error', @@ -29,7 +29,7 @@ void main() { ); } else { when( - () => mockNumberRepository.getNumber(getNumberParams), + () => mockNumbersRepository.getNumber(getNumberParams), ).thenAnswer((_) async => DataSuccess(Number(info: info))); } } diff --git a/test/src/features/number/domain/usecases/get_random_number_usecase_test.dart b/test/src/features/number/domain/usecases/get_random_number_usecase_test.dart index 8cf7901..53af4d2 100644 --- a/test/src/features/number/domain/usecases/get_random_number_usecase_test.dart +++ b/test/src/features/number/domain/usecases/get_random_number_usecase_test.dart @@ -6,17 +6,17 @@ import 'package:numbers/src/features/number/number.dart'; import '../../../../../helpers/helpers.dart'; void main() { - late MockNumberRepository mockNumberRepository; + late MockNumbersRepository mockNumbersRepository; late GetRandomNumberUseCase sut; setUp(() { - mockNumberRepository = MockNumberRepository(); - sut = GetRandomNumberUseCase(repository: mockNumberRepository); + mockNumbersRepository = MockNumbersRepository(); + sut = GetRandomNumberUseCase(repository: mockNumbersRepository); }); void fakeNumberRepositoryResponse(String? info) { if (info == null) { - when(() => mockNumberRepository.getRandomNumber()).thenAnswer( + when(() => mockNumbersRepository.getRandomNumber()).thenAnswer( (_) async => const DataFailure( ErrorDetails( error: 'error', @@ -27,7 +27,7 @@ void main() { ); } else { when( - () => mockNumberRepository.getRandomNumber(), + () => mockNumbersRepository.getRandomNumber(), ).thenAnswer((_) async => DataSuccess(Number(info: info))); } } From bfac96012cb8151e217aefbac5b35c6f86c6a114 Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Mon, 16 Oct 2023 21:37:37 +0200 Subject: [PATCH 08/32] test: add tests for NumberDto --- .../number/data/models/number_dto_test.dart | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 test/src/features/number/data/models/number_dto_test.dart diff --git a/test/src/features/number/data/models/number_dto_test.dart b/test/src/features/number/data/models/number_dto_test.dart new file mode 100644 index 0000000..21af486 --- /dev/null +++ b/test/src/features/number/data/models/number_dto_test.dart @@ -0,0 +1,17 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:numbers/src/features/number/number.dart'; + +void main() { + group('NumberDto', () { + test('supports value comparisons', () { + expect( + const NumberDto( + info: 'test', + ), + const NumberDto( + info: 'test', + ), + ); + }); + }); +} From 420ba17f10f08812ba79932cbef1aa64c2eb6bef Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Mon, 16 Oct 2023 21:48:00 +0200 Subject: [PATCH 09/32] refactor: extend ErrorDetails class from Equatable --- lib/src/core/resources/error_details.dart | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/src/core/resources/error_details.dart b/lib/src/core/resources/error_details.dart index eb6a226..15557e1 100644 --- a/lib/src/core/resources/error_details.dart +++ b/lib/src/core/resources/error_details.dart @@ -1,4 +1,6 @@ -final class ErrorDetails { +import 'package:equatable/equatable.dart'; + +final class ErrorDetails extends Equatable { const ErrorDetails({ required this.error, required this.message, @@ -8,4 +10,7 @@ final class ErrorDetails { final String error; final String message; final String stackTrace; + + @override + List get props => [error, message, stackTrace]; } From 60f9952c61b04e11183ab58ec7c515557d062ed4 Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Mon, 16 Oct 2023 22:01:11 +0200 Subject: [PATCH 10/32] test: add tests for DataState --- test/src/core/resources/data_state_test.dart | 56 ++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 test/src/core/resources/data_state_test.dart diff --git a/test/src/core/resources/data_state_test.dart b/test/src/core/resources/data_state_test.dart new file mode 100644 index 0000000..f36c93d --- /dev/null +++ b/test/src/core/resources/data_state_test.dart @@ -0,0 +1,56 @@ +// ignore_for_file: prefer_const_constructors + +import 'package:flutter_test/flutter_test.dart'; +import 'package:numbers/src/core/core.dart'; + +void main() { + group('DataSuccess', () { + test('is extends from DataState', () { + expect( + DataSuccess('test'), + isA>(), + ); + }); + + test('supports value comparisons', () { + expect( + DataSuccess('test'), + DataSuccess('test'), + ); + }); + }); + + group('DataFailure', () { + test('is extends from DataState', () { + expect( + DataFailure( + ErrorDetails( + error: 'error', + message: 'message', + stackTrace: 'stackTrace', + ), + ), + isA>(), + ); + }); + + test('supports value comparisons', () { + expect( + DataFailure( + ErrorDetails( + error: 'error', + message: 'message', + stackTrace: 'stackTrace', + ), + ), + DataFailure( + ErrorDetails( + error: 'error', + message: 'message', + stackTrace: 'stackTrace', + ), + ), + ); + }); + }); +} From 0b896685f04678365edce933a3aed3672f39aa8f Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Mon, 16 Oct 2023 22:01:30 +0200 Subject: [PATCH 11/32] test: add tests for ErrorDetails --- .../core/resources/error_details_test.dart | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 test/src/core/resources/error_details_test.dart diff --git a/test/src/core/resources/error_details_test.dart b/test/src/core/resources/error_details_test.dart new file mode 100644 index 0000000..c60dbea --- /dev/null +++ b/test/src/core/resources/error_details_test.dart @@ -0,0 +1,25 @@ +// ignore_for_file: prefer_const_constructors + +import 'package:flutter_test/flutter_test.dart'; +import 'package:numbers/src/core/core.dart'; + +void main() { + group('ErrorDetails', () { + test('supports value comparisons', () { + expect( + ErrorDetails( + error: 'error', + message: 'message', + stackTrace: 'stackTrace', + ), + equals( + ErrorDetails( + error: 'error', + message: 'message', + stackTrace: 'stackTrace', + ), + ), + ); + }); + }); +} From 6a88334b2b9e02cb3f979db8f0ca9871199f39e1 Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Mon, 16 Oct 2023 22:03:48 +0200 Subject: [PATCH 12/32] test: update tests of DataState --- test/src/core/resources/data_state_test.dart | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/src/core/resources/data_state_test.dart b/test/src/core/resources/data_state_test.dart index f36c93d..c81a5b7 100644 --- a/test/src/core/resources/data_state_test.dart +++ b/test/src/core/resources/data_state_test.dart @@ -15,7 +15,7 @@ void main() { test('supports value comparisons', () { expect( DataSuccess('test'), - DataSuccess('test'), + equals(DataSuccess('test')), ); }); }); @@ -43,11 +43,13 @@ void main() { stackTrace: 'stackTrace', ), ), - DataFailure( - ErrorDetails( - error: 'error', - message: 'message', - stackTrace: 'stackTrace', + equals( + DataFailure( + ErrorDetails( + error: 'error', + message: 'message', + stackTrace: 'stackTrace', + ), ), ), ); From 4f1b0de1c8631c61e62b89db4cd56cdb35688fa9 Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Mon, 16 Oct 2023 22:04:22 +0200 Subject: [PATCH 13/32] test: update tests of NumberDto --- .../features/number/data/models/number_dto_test.dart | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/src/features/number/data/models/number_dto_test.dart b/test/src/features/number/data/models/number_dto_test.dart index 21af486..e8eff14 100644 --- a/test/src/features/number/data/models/number_dto_test.dart +++ b/test/src/features/number/data/models/number_dto_test.dart @@ -1,3 +1,5 @@ +// ignore_for_file: prefer_const_constructors + import 'package:flutter_test/flutter_test.dart'; import 'package:numbers/src/features/number/number.dart'; @@ -5,11 +7,13 @@ void main() { group('NumberDto', () { test('supports value comparisons', () { expect( - const NumberDto( + NumberDto( info: 'test', ), - const NumberDto( - info: 'test', + equals( + NumberDto( + info: 'test', + ), ), ); }); From d96162a7cddfe3a3cf07f853d9df3d3a82cfbac5 Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Mon, 16 Oct 2023 22:08:48 +0200 Subject: [PATCH 14/32] test: add tests for GetThemeParams --- test/src/core/params/get_theme_params_test.dart | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 test/src/core/params/get_theme_params_test.dart diff --git a/test/src/core/params/get_theme_params_test.dart b/test/src/core/params/get_theme_params_test.dart new file mode 100644 index 0000000..15c8468 --- /dev/null +++ b/test/src/core/params/get_theme_params_test.dart @@ -0,0 +1,13 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:numbers/src/core/core.dart'; + +void main() { + group('GetThemeParams', () { + test('is extends from Params', () { + expect( + const GetThemeParams(key: 'test'), + isA(), + ); + }); + }); +} From d2d2ed38f11f3e455fb91dc6357190954e065e05 Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Mon, 16 Oct 2023 22:09:49 +0200 Subject: [PATCH 15/32] refactor: update file name of GetNumberParams class --- .../params/{number_request_params.dart => get_number_params.dart} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename lib/src/core/params/{number_request_params.dart => get_number_params.dart} (100%) diff --git a/lib/src/core/params/number_request_params.dart b/lib/src/core/params/get_number_params.dart similarity index 100% rename from lib/src/core/params/number_request_params.dart rename to lib/src/core/params/get_number_params.dart From 1895885617ba32677140c92b9ccbbe0a5e7dfb9d Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Mon, 16 Oct 2023 22:10:47 +0200 Subject: [PATCH 16/32] refactor: update params --- lib/src/core/params/params.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/core/params/params.dart b/lib/src/core/params/params.dart index 184bb49..01044df 100644 --- a/lib/src/core/params/params.dart +++ b/lib/src/core/params/params.dart @@ -1,7 +1,7 @@ import 'package:flutter/foundation.dart'; +export 'get_number_params.dart'; export 'get_theme_params.dart'; -export 'number_request_params.dart'; export 'save_theme_params.dart'; @immutable From c50b23438f8264611d212732740b001425e47da4 Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Mon, 16 Oct 2023 22:12:13 +0200 Subject: [PATCH 17/32] test: add tests for GetNumberParams --- test/src/core/params/get_number_params_test.dart | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 test/src/core/params/get_number_params_test.dart diff --git a/test/src/core/params/get_number_params_test.dart b/test/src/core/params/get_number_params_test.dart new file mode 100644 index 0000000..f61f66b --- /dev/null +++ b/test/src/core/params/get_number_params_test.dart @@ -0,0 +1,13 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:numbers/src/core/core.dart'; + +void main() { + group('GetNumberParams', () { + test('is extends from Params', () { + expect( + const GetNumberParams(number: 0), + isA(), + ); + }); + }); +} From f2d2419f42b4d9f809d4ccfb35e4cd3b7f82d45a Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Mon, 16 Oct 2023 22:13:06 +0200 Subject: [PATCH 18/32] test: add tests for SaveThemeParams --- test/src/core/params/save_theme_params_test.dart | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 test/src/core/params/save_theme_params_test.dart diff --git a/test/src/core/params/save_theme_params_test.dart b/test/src/core/params/save_theme_params_test.dart new file mode 100644 index 0000000..9de697a --- /dev/null +++ b/test/src/core/params/save_theme_params_test.dart @@ -0,0 +1,13 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:numbers/src/core/core.dart'; + +void main() { + group('SaveThemeParams', () { + test('is extends from Params', () { + expect( + const SaveThemeParams(key: 'key', value: 'value'), + isA(), + ); + }); + }); +} From e65c785c1f98503dc4c6418c6bd6680e94064d2c Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Mon, 16 Oct 2023 23:40:30 +0200 Subject: [PATCH 19/32] test: add tests for Number --- .../number/domain/entities/number_test.dart | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 test/src/features/number/domain/entities/number_test.dart diff --git a/test/src/features/number/domain/entities/number_test.dart b/test/src/features/number/domain/entities/number_test.dart new file mode 100644 index 0000000..46d793d --- /dev/null +++ b/test/src/features/number/domain/entities/number_test.dart @@ -0,0 +1,21 @@ +// ignore_for_file: prefer_const_constructors + +import 'package:flutter_test/flutter_test.dart'; +import 'package:numbers/src/features/number/number.dart'; + +void main() { + group('Number', () { + test('supports value comparisons', () { + expect( + Number( + info: 'test', + ), + equals( + Number( + info: 'test', + ), + ), + ); + }); + }); +} From 86775360a94784577954b9ce234e8b63b4982d9a Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Mon, 16 Oct 2023 23:46:49 +0200 Subject: [PATCH 20/32] test: update tests of GetNumberParams --- test/src/core/params/get_number_params_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/src/core/params/get_number_params_test.dart b/test/src/core/params/get_number_params_test.dart index f61f66b..d7b6ed0 100644 --- a/test/src/core/params/get_number_params_test.dart +++ b/test/src/core/params/get_number_params_test.dart @@ -3,7 +3,7 @@ import 'package:numbers/src/core/core.dart'; void main() { group('GetNumberParams', () { - test('is extends from Params', () { + test('extends from Params', () { expect( const GetNumberParams(number: 0), isA(), From b1939cd8ff35c3485ed7d5868ca1c40755560edf Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Mon, 16 Oct 2023 23:50:22 +0200 Subject: [PATCH 21/32] test: update tests of GetThemeParams --- test/src/core/params/get_theme_params_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/src/core/params/get_theme_params_test.dart b/test/src/core/params/get_theme_params_test.dart index 15c8468..7fc7f9c 100644 --- a/test/src/core/params/get_theme_params_test.dart +++ b/test/src/core/params/get_theme_params_test.dart @@ -3,7 +3,7 @@ import 'package:numbers/src/core/core.dart'; void main() { group('GetThemeParams', () { - test('is extends from Params', () { + test('extends from Params', () { expect( const GetThemeParams(key: 'test'), isA(), From b49d808447b523b504b0c339bb18af12a0482a53 Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Mon, 16 Oct 2023 23:50:34 +0200 Subject: [PATCH 22/32] test: update tests of SaveThemeParams --- test/src/core/params/save_theme_params_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/src/core/params/save_theme_params_test.dart b/test/src/core/params/save_theme_params_test.dart index 9de697a..0d7c147 100644 --- a/test/src/core/params/save_theme_params_test.dart +++ b/test/src/core/params/save_theme_params_test.dart @@ -3,7 +3,7 @@ import 'package:numbers/src/core/core.dart'; void main() { group('SaveThemeParams', () { - test('is extends from Params', () { + test('extends from Params', () { expect( const SaveThemeParams(key: 'key', value: 'value'), isA(), From b89df24f970a5ce91f865b62d9140b3244a17a8b Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Mon, 16 Oct 2023 23:51:10 +0200 Subject: [PATCH 23/32] test: update tests of DataState --- test/src/core/resources/data_state_test.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/src/core/resources/data_state_test.dart b/test/src/core/resources/data_state_test.dart index c81a5b7..7c065a0 100644 --- a/test/src/core/resources/data_state_test.dart +++ b/test/src/core/resources/data_state_test.dart @@ -5,7 +5,7 @@ import 'package:numbers/src/core/core.dart'; void main() { group('DataSuccess', () { - test('is extends from DataState', () { + test('extends from DataState', () { expect( DataSuccess('test'), isA>(), @@ -21,7 +21,7 @@ void main() { }); group('DataFailure', () { - test('is extends from DataState', () { + test('extends from DataState', () { expect( DataFailure( ErrorDetails( From ebb150309fe2c3e3c8f2166c0c638bbc77d78d39 Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Mon, 16 Oct 2023 23:51:59 +0200 Subject: [PATCH 24/32] test: add tests for NumbersServiceException --- .../numbers_service_exception_test.dart | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 test/src/features/number/data/datasources/numbers_service/numbers_service_exception_test.dart diff --git a/test/src/features/number/data/datasources/numbers_service/numbers_service_exception_test.dart b/test/src/features/number/data/datasources/numbers_service/numbers_service_exception_test.dart new file mode 100644 index 0000000..23f7cb4 --- /dev/null +++ b/test/src/features/number/data/datasources/numbers_service/numbers_service_exception_test.dart @@ -0,0 +1,24 @@ +// ignore_for_file: prefer_const_constructors + +import 'package:flutter_test/flutter_test.dart'; +import 'package:numbers/src/features/number/number.dart'; + +void main() { + group('GetNumberException', () { + test('extends from NumbersServiceException', () { + expect( + GetNumberException('message', 'stackTrace'), + isA(), + ); + }); + }); + + group('GetRandomNumberException', () { + test('extends from NumbersServiceException', () { + expect( + GetRandomNumberException('message', 'stackTrace'), + isA(), + ); + }); + }); +} From 0579a70d00391d68217d300ba59287f19ca67b28 Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Mon, 16 Oct 2023 23:59:42 +0200 Subject: [PATCH 25/32] test: update tests of GetNumberException --- .../numbers_service/numbers_service_exception_test.dart | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/src/features/number/data/datasources/numbers_service/numbers_service_exception_test.dart b/test/src/features/number/data/datasources/numbers_service/numbers_service_exception_test.dart index 23f7cb4..6b92ade 100644 --- a/test/src/features/number/data/datasources/numbers_service/numbers_service_exception_test.dart +++ b/test/src/features/number/data/datasources/numbers_service/numbers_service_exception_test.dart @@ -1,5 +1,3 @@ -// ignore_for_file: prefer_const_constructors - import 'package:flutter_test/flutter_test.dart'; import 'package:numbers/src/features/number/number.dart'; @@ -7,7 +5,7 @@ void main() { group('GetNumberException', () { test('extends from NumbersServiceException', () { expect( - GetNumberException('message', 'stackTrace'), + const GetNumberException('message', 'stackTrace'), isA(), ); }); @@ -16,7 +14,7 @@ void main() { group('GetRandomNumberException', () { test('extends from NumbersServiceException', () { expect( - GetRandomNumberException('message', 'stackTrace'), + const GetRandomNumberException('message', 'stackTrace'), isA(), ); }); From 49027a9d0f505fa354d56d33ad18d00ed1b99e07 Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Tue, 17 Oct 2023 00:23:45 +0200 Subject: [PATCH 26/32] feat: create MockDio helper class for tests --- test/helpers/mocks/mock_dio.dart | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 test/helpers/mocks/mock_dio.dart diff --git a/test/helpers/mocks/mock_dio.dart b/test/helpers/mocks/mock_dio.dart new file mode 100644 index 0000000..c3fe066 --- /dev/null +++ b/test/helpers/mocks/mock_dio.dart @@ -0,0 +1,4 @@ +import 'package:dio/dio.dart'; +import 'package:mocktail/mocktail.dart'; + +final class MockDio extends Mock implements Dio {} From d2ae9d3de49786f46af3709b3e609096ba3f4310 Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Tue, 17 Oct 2023 00:27:57 +0200 Subject: [PATCH 27/32] test: add tests for DioNumbersService --- test/helpers/mocks/mocks.dart | 1 + .../dio_numbers_service_test.dart | 113 ++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 test/src/features/number/data/datasources/numbers_service/dio_numbers_service_test.dart diff --git a/test/helpers/mocks/mocks.dart b/test/helpers/mocks/mocks.dart index 36fa9f4..1535dbe 100644 --- a/test/helpers/mocks/mocks.dart +++ b/test/helpers/mocks/mocks.dart @@ -1,2 +1,3 @@ +export 'mock_dio.dart'; export 'mock_numbers_repository.dart'; export 'mock_numbers_service.dart'; diff --git a/test/src/features/number/data/datasources/numbers_service/dio_numbers_service_test.dart b/test/src/features/number/data/datasources/numbers_service/dio_numbers_service_test.dart new file mode 100644 index 0000000..17d7750 --- /dev/null +++ b/test/src/features/number/data/datasources/numbers_service/dio_numbers_service_test.dart @@ -0,0 +1,113 @@ +// ignore_for_file: prefer_const_constructors + +import 'package:dio/dio.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mocktail/mocktail.dart'; +import 'package:numbers/src/core/core.dart'; +import 'package:numbers/src/features/number/number.dart'; + +import '../../../../../../helpers/helpers.dart'; + +void main() { + late MockDio mockDio; + late String baseUrl; + late DioNumbersService sut; + + setUp(() { + mockDio = MockDio(); + baseUrl = 'testUrl'; + sut = DioNumbersService(dio: mockDio, baseUrl: baseUrl); + }); + + void fakeGetResponse(String? info) { + if (info == null) { + when(() => mockDio.get(any())).thenAnswer( + (_) async => Response( + statusCode: 500, + requestOptions: RequestOptions(), + ), + ); + } else { + when(() => mockDio.get(any())).thenAnswer( + (_) async => Response( + data: info, + statusCode: 200, + requestOptions: RequestOptions(), + ), + ); + } + } + + group('DioNumbersService', () { + test('is concrete implementation of NumbersService', () { + expect( + sut, + isA(), + ); + }); + + test('getNumber returns NumberDto', () async { + const info = 'test'; + const params = GetNumberParams(number: 0); + + fakeGetResponse(info); + + final result = await sut.getNumber(params: params); + + expect( + result, + equals( + NumberDto( + info: info, + ), + ), + ); + + verify(() => mockDio.get('$baseUrl/${params.number}')).called(1); + }); + + test('getNumber throws GetNumberException on non-200 response', () { + const params = GetNumberParams(number: 0); + + fakeGetResponse(null); + + expect( + sut.getNumber(params: params), + throwsA( + isA(), + ), + ); + }); + + test('getRandomNumber returns NumberDto', () async { + const info = 'test'; + + fakeGetResponse(info); + + final result = await sut.getRandomNumber(); + + expect( + result, + equals( + NumberDto( + info: info, + ), + ), + ); + + verify(() => mockDio.get('$baseUrl/random')).called(1); + }); + + test('getRandomNumber throws GetRandomNumberException on non-200 response', + () { + fakeGetResponse(null); + + expect( + sut.getRandomNumber(), + throwsA( + isA(), + ), + ); + }); + }); +} From 5e91b9678cde70e78941ebc02c6776f569b1d32c Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Tue, 17 Oct 2023 21:22:25 +0200 Subject: [PATCH 28/32] feat: create base mixins of usecases for testability --- .../features/number/domain/usecases/get_number_usecase.dart | 4 ++++ .../number/domain/usecases/get_random_number_usecase.dart | 4 ++++ lib/src/features/number/domain/usecases/usecases.dart | 4 ++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/src/features/number/domain/usecases/get_number_usecase.dart b/lib/src/features/number/domain/usecases/get_number_usecase.dart index 532e01e..05cd7aa 100644 --- a/lib/src/features/number/domain/usecases/get_number_usecase.dart +++ b/lib/src/features/number/domain/usecases/get_number_usecase.dart @@ -1,3 +1,4 @@ +import 'package:flutter/foundation.dart'; import 'package:numbers/src/core/core.dart'; import 'package:numbers/src/features/number/number.dart'; @@ -13,3 +14,6 @@ final class GetNumberUseCase Future> call({required GetNumberParams params}) => _numbersRepository.getNumber(params); } + +@visibleForTesting +base mixin MockGetNumberUseCaseMixin implements GetNumberUseCase {} diff --git a/lib/src/features/number/domain/usecases/get_random_number_usecase.dart b/lib/src/features/number/domain/usecases/get_random_number_usecase.dart index d672cb6..facc3d9 100644 --- a/lib/src/features/number/domain/usecases/get_random_number_usecase.dart +++ b/lib/src/features/number/domain/usecases/get_random_number_usecase.dart @@ -1,3 +1,4 @@ +import 'package:flutter/foundation.dart'; import 'package:numbers/src/core/core.dart'; import 'package:numbers/src/features/number/number.dart'; @@ -13,3 +14,6 @@ final class GetRandomNumberUseCase Future> call({Params params = const Params()}) => _numbersRepository.getRandomNumber(); } + +@visibleForTesting +base mixin MockGetRandomNumberUseCaseMixin implements GetRandomNumberUseCase {} diff --git a/lib/src/features/number/domain/usecases/usecases.dart b/lib/src/features/number/domain/usecases/usecases.dart index 0140fb2..981bd15 100644 --- a/lib/src/features/number/domain/usecases/usecases.dart +++ b/lib/src/features/number/domain/usecases/usecases.dart @@ -1,2 +1,2 @@ -export 'get_number_usecase.dart'; -export 'get_random_number_usecase.dart'; +export 'get_number_usecase.dart' show GetNumberUseCase; +export 'get_random_number_usecase.dart' show GetRandomNumberUseCase; From 7d46bfcb113402b08a4d1dc105af321922807da1 Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Wed, 18 Oct 2023 00:50:53 +0200 Subject: [PATCH 29/32] feat: create MockGetNumberUseCase helper class for tests --- test/helpers/mocks/mock_get_number_use_case.dart | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 test/helpers/mocks/mock_get_number_use_case.dart diff --git a/test/helpers/mocks/mock_get_number_use_case.dart b/test/helpers/mocks/mock_get_number_use_case.dart new file mode 100644 index 0000000..6730f60 --- /dev/null +++ b/test/helpers/mocks/mock_get_number_use_case.dart @@ -0,0 +1,4 @@ +import 'package:mocktail/mocktail.dart'; +import 'package:numbers/src/features/number/domain/usecases/get_number_usecase.dart'; + +final class MockGetNumberUseCase extends Mock with MockGetNumberUseCaseMixin {} From 4118f15dd1cb642fce17cea0cd343a3a46766316 Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Wed, 18 Oct 2023 00:51:05 +0200 Subject: [PATCH 30/32] feat: create MockGetRandomNumberUseCase helper class for tests --- test/helpers/mocks/mock_get_random_number_use_case.dart | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 test/helpers/mocks/mock_get_random_number_use_case.dart diff --git a/test/helpers/mocks/mock_get_random_number_use_case.dart b/test/helpers/mocks/mock_get_random_number_use_case.dart new file mode 100644 index 0000000..00c56d9 --- /dev/null +++ b/test/helpers/mocks/mock_get_random_number_use_case.dart @@ -0,0 +1,5 @@ +import 'package:mocktail/mocktail.dart'; +import 'package:numbers/src/features/number/domain/usecases/get_random_number_usecase.dart'; + +final class MockGetRandomNumberUseCase extends Mock + with MockGetRandomNumberUseCaseMixin {} From 444e351d10d600a51055d2bb37b3aec661947bd2 Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Wed, 18 Oct 2023 00:51:24 +0200 Subject: [PATCH 31/32] test: add tests for NumberCubit --- test/helpers/mocks/mocks.dart | 2 + .../presentation/cubit/number_cubit_test.dart | 125 ++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 test/src/features/number/presentation/cubit/number_cubit_test.dart diff --git a/test/helpers/mocks/mocks.dart b/test/helpers/mocks/mocks.dart index 1535dbe..5312268 100644 --- a/test/helpers/mocks/mocks.dart +++ b/test/helpers/mocks/mocks.dart @@ -1,3 +1,5 @@ export 'mock_dio.dart'; +export 'mock_get_number_use_case.dart'; +export 'mock_get_random_number_use_case.dart'; export 'mock_numbers_repository.dart'; export 'mock_numbers_service.dart'; diff --git a/test/src/features/number/presentation/cubit/number_cubit_test.dart b/test/src/features/number/presentation/cubit/number_cubit_test.dart new file mode 100644 index 0000000..8aca4e1 --- /dev/null +++ b/test/src/features/number/presentation/cubit/number_cubit_test.dart @@ -0,0 +1,125 @@ +import 'package:bloc_test/bloc_test.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mocktail/mocktail.dart'; +import 'package:numbers/src/core/core.dart'; +import 'package:numbers/src/features/number/number.dart'; + +import '../../../../../helpers/helpers.dart'; + +void main() { + late MockGetNumberUseCase mockGetNumberUseCase; + late MockGetRandomNumberUseCase mockGetRandomNumberUseCase; + late NumberCubit sut; + + setUp(() { + mockGetNumberUseCase = MockGetNumberUseCase(); + mockGetRandomNumberUseCase = MockGetRandomNumberUseCase(); + sut = NumberCubit( + getNumberUseCase: mockGetNumberUseCase, + getRandomNumberUseCase: mockGetRandomNumberUseCase, + ); + }); + + void fakeGetNumberUseCaseResponse(String? info) { + registerFallbackValue(const GetNumberParams(number: 0)); + + if (info == null) { + when(() => mockGetNumberUseCase(params: any(named: 'params'))).thenAnswer( + (_) async => const DataFailure( + ErrorDetails( + error: 'error', + message: 'message', + stackTrace: 'stackTrace', + ), + ), + ); + } else { + when(() => mockGetNumberUseCase(params: any(named: 'params'))).thenAnswer( + (_) async => DataSuccess(Number(info: info)), + ); + } + } + + void fakeGetRandomNumberUseCaseResponse(String? info) { + if (info == null) { + when(() => mockGetRandomNumberUseCase()).thenAnswer( + (_) async => const DataFailure( + ErrorDetails( + error: 'error', + message: 'message', + stackTrace: 'stackTrace', + ), + ), + ); + } else { + when(() => mockGetRandomNumberUseCase()).thenAnswer( + (_) async => DataSuccess(Number(info: info)), + ); + } + } + + group('NumberCubit', () { + test('initial state is correct', () { + expect( + sut.state, + equals(const NumberState.initial()), + ); + }); + + blocTest( + 'emits correct states when getNumberInfo completes with success', + setUp: () => fakeGetNumberUseCaseResponse('test'), + build: () => NumberCubit( + getNumberUseCase: mockGetNumberUseCase, + getRandomNumberUseCase: mockGetRandomNumberUseCase, + ), + act: (cubit) => cubit.getNumberInfo(number: 0), + expect: () => [ + const NumberState.loading(), + const NumberState.loaded(info: 'test'), + ], + ); + + blocTest( + 'emits correct states when getNumberInfo completes with failure', + setUp: () => fakeGetNumberUseCaseResponse(null), + build: () => NumberCubit( + getNumberUseCase: mockGetNumberUseCase, + getRandomNumberUseCase: mockGetRandomNumberUseCase, + ), + act: (cubit) => cubit.getNumberInfo(number: 0), + expect: () => [ + const NumberState.loading(), + const NumberState.error(), + ], + ); + + blocTest( + 'emits correct states when getRandomNumberInfo completes with success', + setUp: () => fakeGetRandomNumberUseCaseResponse('test'), + build: () => NumberCubit( + getNumberUseCase: mockGetNumberUseCase, + getRandomNumberUseCase: mockGetRandomNumberUseCase, + ), + act: (cubit) => cubit.getRandomNumberInfo(), + expect: () => [ + const NumberState.loading(), + const NumberState.loaded(info: 'test'), + ], + ); + + blocTest( + 'emits correct states when getRandomNumberInfo completes with failure', + setUp: () => fakeGetRandomNumberUseCaseResponse(null), + build: () => NumberCubit( + getNumberUseCase: mockGetNumberUseCase, + getRandomNumberUseCase: mockGetRandomNumberUseCase, + ), + act: (cubit) => cubit.getRandomNumberInfo(), + expect: () => [ + const NumberState.loading(), + const NumberState.error(), + ], + ); + }); +} From d4241124e3a057b6347316276fbc25c890a5dcf9 Mon Sep 17 00:00:00 2001 From: Bulent Baris Kilic Date: Wed, 18 Oct 2023 00:56:17 +0200 Subject: [PATCH 32/32] refactor: rename usecase file names as use_case --- lib/src/app/domain/domain.dart | 2 +- .../get_theme_use_case.dart} | 0 .../save_theme_use_case.dart} | 0 lib/src/app/domain/use_cases/use_cases.dart | 2 ++ lib/src/app/domain/usecases/usecases.dart | 2 -- lib/src/core/core.dart | 2 +- lib/src/core/{usecases/usecase.dart => use_case/use_case.dart} | 0 lib/src/features/number/domain/domain.dart | 2 +- .../get_number_use_case.dart} | 0 .../get_random_number_use_case.dart} | 0 lib/src/features/number/domain/use_cases/use_cases.dart | 2 ++ lib/src/features/number/domain/usecases/usecases.dart | 2 -- test/helpers/mocks/mock_get_number_use_case.dart | 2 +- test/helpers/mocks/mock_get_random_number_use_case.dart | 2 +- .../get_number_use_case_test.dart} | 0 .../get_random_number_use_case_test.dart} | 0 16 files changed, 9 insertions(+), 9 deletions(-) rename lib/src/app/domain/{usecases/get_theme_usecase.dart => use_cases/get_theme_use_case.dart} (100%) rename lib/src/app/domain/{usecases/save_theme_usecase.dart => use_cases/save_theme_use_case.dart} (100%) create mode 100644 lib/src/app/domain/use_cases/use_cases.dart delete mode 100644 lib/src/app/domain/usecases/usecases.dart rename lib/src/core/{usecases/usecase.dart => use_case/use_case.dart} (100%) rename lib/src/features/number/domain/{usecases/get_number_usecase.dart => use_cases/get_number_use_case.dart} (100%) rename lib/src/features/number/domain/{usecases/get_random_number_usecase.dart => use_cases/get_random_number_use_case.dart} (100%) create mode 100644 lib/src/features/number/domain/use_cases/use_cases.dart delete mode 100644 lib/src/features/number/domain/usecases/usecases.dart rename test/src/features/number/domain/{usecases/get_number_usecase_test.dart => use_cases/get_number_use_case_test.dart} (100%) rename test/src/features/number/domain/{usecases/get_random_number_usecase_test.dart => use_cases/get_random_number_use_case_test.dart} (100%) diff --git a/lib/src/app/domain/domain.dart b/lib/src/app/domain/domain.dart index 5e7bf10..3d91876 100644 --- a/lib/src/app/domain/domain.dart +++ b/lib/src/app/domain/domain.dart @@ -1,2 +1,2 @@ export 'repositories/repositories.dart'; -export 'usecases/usecases.dart'; +export 'use_cases/use_cases.dart'; diff --git a/lib/src/app/domain/usecases/get_theme_usecase.dart b/lib/src/app/domain/use_cases/get_theme_use_case.dart similarity index 100% rename from lib/src/app/domain/usecases/get_theme_usecase.dart rename to lib/src/app/domain/use_cases/get_theme_use_case.dart diff --git a/lib/src/app/domain/usecases/save_theme_usecase.dart b/lib/src/app/domain/use_cases/save_theme_use_case.dart similarity index 100% rename from lib/src/app/domain/usecases/save_theme_usecase.dart rename to lib/src/app/domain/use_cases/save_theme_use_case.dart diff --git a/lib/src/app/domain/use_cases/use_cases.dart b/lib/src/app/domain/use_cases/use_cases.dart new file mode 100644 index 0000000..bdd96a0 --- /dev/null +++ b/lib/src/app/domain/use_cases/use_cases.dart @@ -0,0 +1,2 @@ +export 'get_theme_use_case.dart'; +export 'save_theme_use_case.dart'; diff --git a/lib/src/app/domain/usecases/usecases.dart b/lib/src/app/domain/usecases/usecases.dart deleted file mode 100644 index a2fdf1d..0000000 --- a/lib/src/app/domain/usecases/usecases.dart +++ /dev/null @@ -1,2 +0,0 @@ -export 'get_theme_usecase.dart'; -export 'save_theme_usecase.dart'; diff --git a/lib/src/core/core.dart b/lib/src/core/core.dart index a81cde4..67a8588 100644 --- a/lib/src/core/core.dart +++ b/lib/src/core/core.dart @@ -3,4 +3,4 @@ export 'extensions/extensions.dart'; export 'l10n/l10n.dart'; export 'params/params.dart'; export 'resources/resources.dart'; -export 'usecases/usecase.dart'; +export 'use_case/use_case.dart'; diff --git a/lib/src/core/usecases/usecase.dart b/lib/src/core/use_case/use_case.dart similarity index 100% rename from lib/src/core/usecases/usecase.dart rename to lib/src/core/use_case/use_case.dart diff --git a/lib/src/features/number/domain/domain.dart b/lib/src/features/number/domain/domain.dart index ff77d1c..cc16ca3 100644 --- a/lib/src/features/number/domain/domain.dart +++ b/lib/src/features/number/domain/domain.dart @@ -1,3 +1,3 @@ export 'entities/entities.dart'; export 'repositories/repositories.dart'; -export 'usecases/usecases.dart'; +export 'use_cases/use_cases.dart'; diff --git a/lib/src/features/number/domain/usecases/get_number_usecase.dart b/lib/src/features/number/domain/use_cases/get_number_use_case.dart similarity index 100% rename from lib/src/features/number/domain/usecases/get_number_usecase.dart rename to lib/src/features/number/domain/use_cases/get_number_use_case.dart diff --git a/lib/src/features/number/domain/usecases/get_random_number_usecase.dart b/lib/src/features/number/domain/use_cases/get_random_number_use_case.dart similarity index 100% rename from lib/src/features/number/domain/usecases/get_random_number_usecase.dart rename to lib/src/features/number/domain/use_cases/get_random_number_use_case.dart diff --git a/lib/src/features/number/domain/use_cases/use_cases.dart b/lib/src/features/number/domain/use_cases/use_cases.dart new file mode 100644 index 0000000..fbe0c4f --- /dev/null +++ b/lib/src/features/number/domain/use_cases/use_cases.dart @@ -0,0 +1,2 @@ +export 'get_number_use_case.dart' show GetNumberUseCase; +export 'get_random_number_use_case.dart' show GetRandomNumberUseCase; diff --git a/lib/src/features/number/domain/usecases/usecases.dart b/lib/src/features/number/domain/usecases/usecases.dart deleted file mode 100644 index 981bd15..0000000 --- a/lib/src/features/number/domain/usecases/usecases.dart +++ /dev/null @@ -1,2 +0,0 @@ -export 'get_number_usecase.dart' show GetNumberUseCase; -export 'get_random_number_usecase.dart' show GetRandomNumberUseCase; diff --git a/test/helpers/mocks/mock_get_number_use_case.dart b/test/helpers/mocks/mock_get_number_use_case.dart index 6730f60..75fffe0 100644 --- a/test/helpers/mocks/mock_get_number_use_case.dart +++ b/test/helpers/mocks/mock_get_number_use_case.dart @@ -1,4 +1,4 @@ import 'package:mocktail/mocktail.dart'; -import 'package:numbers/src/features/number/domain/usecases/get_number_usecase.dart'; +import 'package:numbers/src/features/number/domain/use_cases/get_number_use_case.dart'; final class MockGetNumberUseCase extends Mock with MockGetNumberUseCaseMixin {} diff --git a/test/helpers/mocks/mock_get_random_number_use_case.dart b/test/helpers/mocks/mock_get_random_number_use_case.dart index 00c56d9..cb7b7ef 100644 --- a/test/helpers/mocks/mock_get_random_number_use_case.dart +++ b/test/helpers/mocks/mock_get_random_number_use_case.dart @@ -1,5 +1,5 @@ import 'package:mocktail/mocktail.dart'; -import 'package:numbers/src/features/number/domain/usecases/get_random_number_usecase.dart'; +import 'package:numbers/src/features/number/domain/use_cases/get_random_number_use_case.dart'; final class MockGetRandomNumberUseCase extends Mock with MockGetRandomNumberUseCaseMixin {} diff --git a/test/src/features/number/domain/usecases/get_number_usecase_test.dart b/test/src/features/number/domain/use_cases/get_number_use_case_test.dart similarity index 100% rename from test/src/features/number/domain/usecases/get_number_usecase_test.dart rename to test/src/features/number/domain/use_cases/get_number_use_case_test.dart diff --git a/test/src/features/number/domain/usecases/get_random_number_usecase_test.dart b/test/src/features/number/domain/use_cases/get_random_number_use_case_test.dart similarity index 100% rename from test/src/features/number/domain/usecases/get_random_number_usecase_test.dart rename to test/src/features/number/domain/use_cases/get_random_number_use_case_test.dart