Skip to content

Commit

Permalink
adding test cases without mockito
Browse files Browse the repository at this point in the history
  • Loading branch information
GJJ2019 committed Jul 11, 2022
1 parent fb053ef commit 823f3c0
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 48 deletions.
2 changes: 1 addition & 1 deletion lib/src/model/easy_upi_payment_model.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class EasyUpiPaymentModel {
EasyUpiPaymentModel({
const EasyUpiPaymentModel({
required this.payeeVpa,
required this.payeeName,
required this.amount,
Expand Down
10 changes: 10 additions & 0 deletions lib/src/model/transaction_detail_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,14 @@ class TransactionDetailModel {
String toString() {
return 'TransactionDetailModel(transactionId: $transactionId, responseCode: $responseCode, approvalRefNo: $approvalRefNo, transactionRefId: $transactionRefId, amount: $amount)';
}

Map<String, dynamic> toMap() {
return <String, dynamic>{
'transactionId': transactionId,
'responseCode': responseCode,
'approvalRefNo': approvalRefNo,
'transactionRefId': transactionRefId,
'amount': amount,
};
}
}
61 changes: 43 additions & 18 deletions test/easy_upi_payment_method_channel_test.dart
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>()),
);
});
});
}
57 changes: 28 additions & 29 deletions test/easy_upi_payment_test.dart
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
// 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:easy_upi_payment/src/easy_upi_payment_method_channel.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';

import 'fake_data.dart';

class MockEasyUpiPaymentPlatform with MockPlatformInterfaceMixin implements EasyUpiPaymentPlatform {
@override
Future<TransactionDetailModel?> startPayment(EasyUpiPaymentModel easyUpiPaymentModel) {
return Future.value(fakeTransactionDetailsModel);
}
}

void main() {
final EasyUpiPaymentPlatform initialPlatform = EasyUpiPaymentPlatform.instance;

test('$MethodChannelEasyUpiPayment is the default instance', () {
expect(initialPlatform, isInstanceOf<MethodChannelEasyUpiPayment>());
});

test('startPayment', () async {
final MockEasyUpiPaymentPlatform fakePlatform = MockEasyUpiPaymentPlatform();
EasyUpiPaymentPlatform.instance = fakePlatform;

expect(await fakePlatform.startPayment(fakeEasyUpiPaymentModel), fakeTransactionDetailsModel);
});
}
16 changes: 16 additions & 0 deletions test/fake_data.dart
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',
);

0 comments on commit 823f3c0

Please sign in to comment.