Skip to content

Commit

Permalink
Add forgotten mocks from pincode feature
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolay-vasilev-prime committed Oct 11, 2024
1 parent 4468642 commit e5ed207
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:rxdart/rxdart.dart';
import 'package:testapp/lib_pin_code/bloc/create_pin_bloc.dart';

import 'create_pin_bloc_mock.mocks.dart';

@GenerateMocks([CreatePinBlocType, CreatePinBlocEvents, CreatePinBlocStates])
CreatePinBlocType createPinMockFactory({
bool? isPinCreated,
bool? deleteStoredPinData,
}) {
final blocMock = MockCreatePinBlocType();
final eventsMock = MockCreatePinBlocEvents();
final statesMock = MockCreatePinBlocStates();

when(blocMock.events).thenReturn(eventsMock);
when(blocMock.states).thenReturn(statesMock);

final isPinCreatedState = (isPinCreated != null
? Stream.value(isPinCreated)
: const Stream<bool>.empty())
.publishReplay(maxSize: 1)
..connect();

final deleteStoredPinDataState = (deleteStoredPinData != null
? Stream.value(deleteStoredPinData)
: const Stream<bool>.empty())
.publishReplay(maxSize: 1)
..connect();

when(statesMock.deleteStoredPinData).thenAnswer(
(_) => deleteStoredPinDataState,
);

when(statesMock.isPinCreated).thenAnswer((_) => isPinCreatedState);

return blocMock;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:mockito/annotations.dart';
import 'package:testapp/lib_pin_code/repository/pin_code_repository.dart';
import 'package:testapp/lib_pin_code/services/create_pin_code_service.dart';

import 'create_pin_service_mock.mocks.dart';

@GenerateMocks([PinCodeRepository])
CreatePinCodeService createPinServiceMockFactory() {
final repositoryMock = MockPinCodeRepository();

return CreatePinCodeService(repositoryMock);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

import 'package:mockito/annotations.dart';
import 'package:testapp/lib_pin_code/data_source/pin_biometrics_local_data_source.dart';

import 'pin_biometrics_local_datasource_mock.mocks.dart';

@GenerateMocks([PinBiometricsLocalDataSource])
PinBiometricsLocalDataSource pinBiometricsLocalDataSourceMockFactory() => MockPinBiometricsLocalDataSource();
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:local_session_timeout/local_session_timeout.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:rxdart/rxdart.dart';
import 'package:testapp/lib_pin_code/bloc/update_and_verify_pin_bloc.dart';

import 'update_and_verify_pin_bloc_mock.mocks.dart';

@GenerateMocks([
UpdateAndVerifyPinBlocType,
UpdateAndVerifyPinBlocEvents,
UpdateAndVerifyPinBlocStates
])
UpdateAndVerifyPinBlocType updateAndVerifyPinMockFactory() {
final blocMock = MockUpdateAndVerifyPinBlocType();
final eventsMock = MockUpdateAndVerifyPinBlocEvents();
final statesMock = MockUpdateAndVerifyPinBlocStates();

when(blocMock.events).thenReturn(eventsMock);
when(blocMock.states).thenReturn(statesMock);

final emptyState = Stream.value(null).publishReplay(maxSize: 1)
..connect();

when(statesMock.deleteStoredPinData).thenAnswer((_) => emptyState);
when(statesMock.deletedData).thenAnswer((_) => emptyState);
when(statesMock.deleteStoredPinData).thenAnswer((_) => emptyState);
when(statesMock.isPinUpdated).thenAnswer((_) => emptyState);
when(statesMock.sessionValue).thenAnswer((_) => Stream.value(SessionState.stopListening).publishReplay(maxSize: 1)
..connect());

return blocMock;
}

0 comments on commit e5ed207

Please sign in to comment.