-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
106 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,76 @@ | ||
import 'package:easy_upi_payment/easy_upi_payment.dart'; | ||
import 'package:easy_upi_payment/src/easy_upi_payment_method_channel.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:plugin_platform_interface/plugin_platform_interface.dart'; | ||
import 'package:mockito/annotations.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
|
||
import 'easy_upi_payment_test.mocks.dart'; | ||
import 'fake_data.dart'; | ||
|
||
class MockEasyUpiPaymentPlatform with MockPlatformInterfaceMixin implements EasyUpiPaymentPlatform { | ||
@override | ||
Future<TransactionDetailModel?> startPayment(EasyUpiPaymentModel easyUpiPaymentModel) { | ||
return Future.value(fakeTransactionDetailsModel); | ||
} | ||
} | ||
|
||
@GenerateMocks([EasyUpiPaymentPlatform]) | ||
void main() { | ||
final EasyUpiPaymentPlatform initialPlatform = EasyUpiPaymentPlatform.instance; | ||
final mockPlatform = MockEasyUpiPaymentPlatform(); | ||
|
||
test('$MethodChannelEasyUpiPayment is the default instance', () { | ||
expect(initialPlatform, isInstanceOf<MethodChannelEasyUpiPayment>()); | ||
test('startPayment', () async { | ||
when(mockPlatform.startPayment(fakeEasyUpiPaymentModel)).thenAnswer( | ||
(_) => Future.value(fakeTransactionDetailsModel), | ||
); | ||
expect(await mockPlatform.startPayment(fakeEasyUpiPaymentModel), fakeTransactionDetailsModel); | ||
}); | ||
|
||
test('startPayment', () async { | ||
final MockEasyUpiPaymentPlatform fakePlatform = MockEasyUpiPaymentPlatform(); | ||
EasyUpiPaymentPlatform.instance = fakePlatform; | ||
test('startPayment with cancelled Exception', () async { | ||
when(mockPlatform.startPayment(fakeEasyUpiPaymentModel)).thenThrow( | ||
EasyUpiPaymentException.fromException( | ||
PlatformException( | ||
code: EasyUpiPaymentExceptionType.cancelledException.toString(), | ||
), | ||
), | ||
); | ||
expect( | ||
() => mockPlatform.startPayment(fakeEasyUpiPaymentModel), | ||
throwsA(isA<EasyUpiPaymentException>()), | ||
); | ||
}); | ||
|
||
test('startPayment with failed Exception', () async { | ||
when(mockPlatform.startPayment(fakeEasyUpiPaymentModel)).thenThrow( | ||
EasyUpiPaymentException.fromException( | ||
PlatformException( | ||
code: EasyUpiPaymentExceptionType.failedException.toString(), | ||
), | ||
), | ||
); | ||
expect( | ||
() => mockPlatform.startPayment(fakeEasyUpiPaymentModel), | ||
throwsA(isA<EasyUpiPaymentException>()), | ||
); | ||
}); | ||
|
||
test('startPayment with submitted Exception', () async { | ||
when(mockPlatform.startPayment(fakeEasyUpiPaymentModel)).thenThrow( | ||
EasyUpiPaymentException.fromException( | ||
PlatformException( | ||
code: EasyUpiPaymentExceptionType.submittedException.toString(), | ||
), | ||
), | ||
); | ||
expect( | ||
() => mockPlatform.startPayment(fakeEasyUpiPaymentModel), | ||
throwsA(isA<EasyUpiPaymentException>()), | ||
); | ||
}); | ||
|
||
expect(await fakePlatform.startPayment(fakeEasyUpiPaymentModel), fakeTransactionDetailsModel); | ||
test('startPayment with unknown Exception', () async { | ||
when(mockPlatform.startPayment(fakeEasyUpiPaymentModel)).thenThrow( | ||
EasyUpiPaymentException.fromException( | ||
PlatformException( | ||
code: EasyUpiPaymentExceptionType.unknownException.toString(), | ||
), | ||
), | ||
); | ||
expect( | ||
() => mockPlatform.startPayment(fakeEasyUpiPaymentModel), | ||
throwsA(isA<EasyUpiPaymentException>()), | ||
); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Mocks generated by Mockito 5.2.0 from annotations | ||
// in easy_upi_payment/test/easy_upi_payment_test.dart. | ||
// Do not manually edit this file. | ||
|
||
import 'dart:async' as _i3; | ||
|
||
import 'package:easy_upi_payment/src/easy_upi_payment_platform_interface.dart' | ||
as _i2; | ||
import 'package:easy_upi_payment/src/model/easy_upi_payment_model.dart' as _i5; | ||
import 'package:easy_upi_payment/src/model/transaction_detail_model.dart' | ||
as _i4; | ||
import 'package:mockito/mockito.dart' as _i1; | ||
|
||
// ignore_for_file: type=lint | ||
// ignore_for_file: avoid_redundant_argument_values | ||
// ignore_for_file: avoid_setters_without_getters | ||
// ignore_for_file: comment_references | ||
// ignore_for_file: implementation_imports | ||
// ignore_for_file: invalid_use_of_visible_for_testing_member | ||
// ignore_for_file: prefer_const_constructors | ||
// ignore_for_file: unnecessary_parenthesis | ||
// ignore_for_file: camel_case_types | ||
|
||
/// A class which mocks [EasyUpiPaymentPlatform]. | ||
/// | ||
/// See the documentation for Mockito's code generation for more information. | ||
class MockEasyUpiPaymentPlatform extends _i1.Mock | ||
implements _i2.EasyUpiPaymentPlatform { | ||
MockEasyUpiPaymentPlatform() { | ||
_i1.throwOnMissingStub(this); | ||
} | ||
|
||
@override | ||
_i3.Future<_i4.TransactionDetailModel?> startPayment( | ||
_i5.EasyUpiPaymentModel? easyUpiPaymentModel) => | ||
(super.noSuchMethod( | ||
Invocation.method(#startPayment, [easyUpiPaymentModel]), | ||
returnValue: Future<_i4.TransactionDetailModel?>.value()) | ||
as _i3.Future<_i4.TransactionDetailModel?>); | ||
} |