68 lines
1.9 KiB
Dart
68 lines
1.9 KiB
Dart
/// Tests unitaires pour ClearCache use case
|
|
library clear_cache_test;
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:mockito/annotations.dart';
|
|
import 'package:mockito/mockito.dart';
|
|
import 'package:unionflow_mobile_apps/features/settings/domain/repositories/system_config_repository.dart';
|
|
import 'package:unionflow_mobile_apps/features/settings/domain/usecases/clear_cache.dart';
|
|
|
|
@GenerateMocks([ISystemConfigRepository])
|
|
import 'clear_cache_test.mocks.dart';
|
|
|
|
void main() {
|
|
late ClearCache useCase;
|
|
late MockISystemConfigRepository mockRepository;
|
|
|
|
setUp(() {
|
|
mockRepository = MockISystemConfigRepository();
|
|
useCase = ClearCache(mockRepository);
|
|
});
|
|
|
|
group('ClearCache Use Case', () {
|
|
test('should clear cache successfully', () async {
|
|
// Arrange
|
|
when(mockRepository.clearCache())
|
|
.thenAnswer((_) async => Future.value());
|
|
|
|
// Act
|
|
await useCase();
|
|
|
|
// Assert
|
|
verify(mockRepository.clearCache());
|
|
verifyNoMoreInteractions(mockRepository);
|
|
});
|
|
|
|
test('should complete without error when cache is empty', () async {
|
|
// Arrange
|
|
when(mockRepository.clearCache())
|
|
.thenAnswer((_) async => Future.value());
|
|
|
|
// Act
|
|
await useCase();
|
|
|
|
// Assert
|
|
verify(mockRepository.clearCache()).called(1);
|
|
});
|
|
|
|
test('should throw exception when clear operation fails', () async {
|
|
// Arrange
|
|
when(mockRepository.clearCache())
|
|
.thenThrow(Exception('Clear operation failed'));
|
|
|
|
// Act & Assert
|
|
expect(() => useCase(), throwsA(isA<Exception>()));
|
|
verify(mockRepository.clearCache());
|
|
});
|
|
|
|
test('should throw exception when permission denied', () async {
|
|
// Arrange
|
|
when(mockRepository.clearCache())
|
|
.thenThrow(Exception('Permission denied'));
|
|
|
|
// Act & Assert
|
|
expect(() => useCase(), throwsException);
|
|
});
|
|
});
|
|
}
|