-
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.
Merge pull request #2 from GJJ2019/add_test_cases
Adding plugin test cases
- Loading branch information
Showing
7 changed files
with
188 additions
and
48 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
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,20 +1,45 @@ | ||
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 'fake_data.dart'; | ||
|
||
void main() { | ||
// MethodChannelEasyUpiPayment platform = MethodChannelEasyUpiPayment(); | ||
// const MethodChannel channel = MethodChannel('easy_upi_payment'); | ||
// | ||
// TestWidgetsFlutterBinding.ensureInitialized(); | ||
// | ||
// setUp(() { | ||
// channel.setMockMethodCallHandler((MethodCall methodCall) async { | ||
// return '42'; | ||
// }); | ||
// }); | ||
// | ||
// tearDown(() { | ||
// channel.setMockMethodCallHandler(null); | ||
// }); | ||
// | ||
// test('getPlatformVersion', () async { | ||
// expect(await platform.getPlatformVersion(), '42'); | ||
// }); | ||
final MethodChannelEasyUpiPayment platform = MethodChannelEasyUpiPayment(); | ||
const MethodChannel channel = MethodChannel('easy_upi_payment'); | ||
|
||
TestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
tearDown(() { | ||
channel.setMockMethodCallHandler(null); | ||
}); | ||
|
||
group('startPayment with appropriate result', () { | ||
setUp(() { | ||
channel.setMockMethodCallHandler((MethodCall methodCall) async { | ||
return fakeTransactionDetailsModel.toMap(); | ||
}); | ||
}); | ||
|
||
test('startPayment', () async { | ||
expect(await platform.startPayment(fakeEasyUpiPaymentModel), fakeTransactionDetailsModel); | ||
}); | ||
}); | ||
|
||
group('startPayment with exception', () { | ||
final platformException = PlatformException(code: EasyUpiPaymentExceptionType.failedException.toString()); | ||
setUp(() { | ||
channel.setMockMethodCallHandler((MethodCall methodCall) async { | ||
return platformException; | ||
}); | ||
}); | ||
|
||
test('startPayment', () async { | ||
expect( | ||
() => platform.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 |
---|---|---|
@@ -1,29 +1,76 @@ | ||
// import 'package:flutter_test/flutter_test.dart'; | ||
// import 'package:easy_upi_payment/easy_upi_payment.dart'; | ||
// import 'package:easy_upi_payment/easy_upi_payment_platform_interface.dart'; | ||
// import 'package:easy_upi_payment/easy_upi_payment_method_channel.dart'; | ||
// import 'package:plugin_platform_interface/plugin_platform_interface.dart'; | ||
// | ||
// class MockEasyUpiPaymentPlatform | ||
// with MockPlatformInterfaceMixin | ||
// implements EasyUpiPaymentPlatform { | ||
// | ||
// @override | ||
// Future<String?> getPlatformVersion() => Future.value('42'); | ||
// } | ||
// | ||
// void main() { | ||
// final EasyUpiPaymentPlatform initialPlatform = EasyUpiPaymentPlatform.instance; | ||
// | ||
// test('$MethodChannelEasyUpiPayment is the default instance', () { | ||
// expect(initialPlatform, isInstanceOf<MethodChannelEasyUpiPayment>()); | ||
// }); | ||
// | ||
// test('getPlatformVersion', () async { | ||
// EasyUpiPayment easyUpiPaymentPlugin = EasyUpiPayment(); | ||
// MockEasyUpiPaymentPlatform fakePlatform = MockEasyUpiPaymentPlatform(); | ||
// EasyUpiPaymentPlatform.instance = fakePlatform; | ||
// | ||
// expect(await easyUpiPaymentPlugin.getPlatformVersion(), '42'); | ||
// }); | ||
// } | ||
import 'package:easy_upi_payment/easy_upi_payment.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mockito/annotations.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
|
||
import 'easy_upi_payment_test.mocks.dart'; | ||
import 'fake_data.dart'; | ||
|
||
@GenerateMocks([EasyUpiPaymentPlatform]) | ||
void main() { | ||
final mockPlatform = MockEasyUpiPaymentPlatform(); | ||
|
||
test('startPayment', () async { | ||
when(mockPlatform.startPayment(fakeEasyUpiPaymentModel)).thenAnswer( | ||
(_) => Future.value(fakeTransactionDetailsModel), | ||
); | ||
expect(await mockPlatform.startPayment(fakeEasyUpiPaymentModel), fakeTransactionDetailsModel); | ||
}); | ||
|
||
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>()), | ||
); | ||
}); | ||
|
||
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?>); | ||
} |
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,16 @@ | ||
import 'package:easy_upi_payment/easy_upi_payment.dart'; | ||
|
||
const fakeTransactionDetailsModel = TransactionDetailModel( | ||
transactionId: 'transactionId', | ||
responseCode: 'responseCode', | ||
approvalRefNo: 'approvalRefNo', | ||
transactionRefId: 'transactionRefId', | ||
amount: 'amount', | ||
); | ||
|
||
const fakeEasyUpiPaymentModel = EasyUpiPaymentModel( | ||
payeeVpa: 'payeeVpa', | ||
payeeName: 'payeeName', | ||
amount: 10.0, | ||
description: 'description', | ||
); |