This repository has been archived by the owner on Nov 11, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Version 3.0.0 #41 from PatilShreyas/version-3.0.0-dev
Version 3.0.0 dev
- Loading branch information
Showing
124 changed files
with
1,836 additions
and
16,844 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
-keepclasseswithmembernames public class com.shreyaspatil.easyupipayment.model.** {*;} |
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,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.shreyaspatil.EasyUpiPayment"> | ||
|
||
<application> | ||
<activity | ||
android:name="com.shreyaspatil.easyupipayment.FakeUpiActivity" | ||
android:launchMode="singleInstance" | ||
android:theme="@style/Theme.AppCompat"> | ||
<intent-filter android:autoVerify="true"> | ||
<action android:name="android.intent.action.VIEW" /> | ||
|
||
<category android:name="android.intent.category.DEFAULT" /> | ||
<category android:name="android.intent.category.BROWSABLE" /> | ||
|
||
<data android:scheme="upi" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
27 changes: 0 additions & 27 deletions
27
...Payment/src/androidTest/java/com/shreyaspatil/EasyUpiPayment/ExampleInstrumentedTest.java
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
EasyUpiPayment/src/androidTest/java/com/shreyaspatil/EasyUpiPayment/FakeUpiActivity.kt
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,12 @@ | ||
package com.shreyaspatil.easyupipayment | ||
|
||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
|
||
class FakeUpiActivity : AppCompatActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
finish() | ||
} | ||
} |
124 changes: 124 additions & 0 deletions
124
...iPayment/src/androidTest/java/com/shreyaspatil/EasyUpiPayment/ui/PaymentUiActivityTest.kt
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,124 @@ | ||
package com.shreyaspatil.easyupipayment.ui | ||
|
||
import android.app.Activity | ||
import android.content.Intent | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.test.core.app.ApplicationProvider | ||
import androidx.test.core.app.launchActivity | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn | ||
import com.shreyaspatil.easyupipayment.model.PaymentApp | ||
import com.shreyaspatil.easyupipayment.testutils.paymentWith | ||
import junit.framework.TestCase.assertTrue | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.Mockito.verify | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class PaymentUiActivityTest { | ||
|
||
@Test | ||
fun shouldNotThrowIllegalStateException_whenPaymentDetailsProvided() { | ||
val intent = getPaymentIntent() | ||
launchActivity<PaymentUiActivity>(intent).onActivity { | ||
assertTrue(it.lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) | ||
} | ||
} | ||
|
||
@Test | ||
fun shouldFinishActivity_whenTransactionIsOver() { | ||
launchActivity<PaymentUiActivity>(getPaymentIntent()).onActivity { | ||
val responseIntent = Intent().apply { putExtra("response", "") } | ||
|
||
// Give transaction result | ||
it.onActivityResult(PaymentUiActivity.PAYMENT_REQUEST, Activity.RESULT_OK, responseIntent) | ||
|
||
// Verify Activity is destroyed or not | ||
assertTrue(it.lifecycle.currentState.isAtLeast(Lifecycle.State.DESTROYED)) | ||
} | ||
} | ||
|
||
@Test | ||
fun shouldGiveCancelledCallback_whenTransactionIsCancelled() { | ||
launchActivity<PaymentUiActivity>(getPaymentIntent()).onActivity { | ||
spyOn(it) | ||
|
||
it.onActivityResult( | ||
PaymentUiActivity.PAYMENT_REQUEST, | ||
Activity.RESULT_CANCELED, | ||
null | ||
) | ||
|
||
verify(it).callbackTransactionCancelled() | ||
} | ||
} | ||
|
||
@Test | ||
fun shouldGiveCompletedCallback_whenTransactionIsFailed() { | ||
launchActivity<PaymentUiActivity>(getPaymentIntent()).onActivity { | ||
spyOn(it) | ||
|
||
val transactionDetails = it.getTransactionDetails(RESPONSE_TRANSACTION_FAILURE) | ||
|
||
it.onActivityResult( | ||
PaymentUiActivity.PAYMENT_REQUEST, | ||
Activity.RESULT_OK, | ||
getResponseIntent(RESPONSE_TRANSACTION_FAILURE) | ||
) | ||
|
||
verify(it).callbackTransactionCompleted(transactionDetails) | ||
} | ||
} | ||
|
||
@Test | ||
fun shouldGiveCompletedCallback_whenTransactionIsSuccessful() { | ||
launchActivity<PaymentUiActivity>(getPaymentIntent()).onActivity { | ||
spyOn(it) | ||
|
||
val transactionDetails = it.getTransactionDetails(RESPONSE_TRANSACTION_SUCCESS) | ||
|
||
it.onActivityResult( | ||
PaymentUiActivity.PAYMENT_REQUEST, | ||
Activity.RESULT_OK, | ||
getResponseIntent(RESPONSE_TRANSACTION_SUCCESS) | ||
) | ||
|
||
verify(it).callbackTransactionCompleted(transactionDetails) | ||
} | ||
} | ||
|
||
@Test | ||
fun shouldGiveCompletedCallback_whenTransactionIsSubmitted() { | ||
launchActivity<PaymentUiActivity>(getPaymentIntent()).onActivity { | ||
spyOn(it) | ||
|
||
val transactionDetails = it.getTransactionDetails(RESPONSE_TRANSACTION_SUBMITTED) | ||
|
||
it.onActivityResult( | ||
PaymentUiActivity.PAYMENT_REQUEST, | ||
Activity.RESULT_OK, | ||
getResponseIntent(RESPONSE_TRANSACTION_SUBMITTED) | ||
) | ||
|
||
verify(it).callbackTransactionCompleted(transactionDetails) | ||
} | ||
} | ||
|
||
private fun getPaymentIntent(paymentApp: PaymentApp? = null) = Intent( | ||
ApplicationProvider.getApplicationContext(), | ||
PaymentUiActivity::class.java | ||
).apply { | ||
putExtra(PaymentUiActivity.EXTRA_KEY_PAYMENT, paymentWith(paymentApp)) | ||
} | ||
|
||
private fun getResponseIntent(response: String) = Intent().apply { | ||
putExtra("response", response) | ||
} | ||
|
||
companion object { | ||
const val RESPONSE_TRANSACTION_SUCCESS = "txnId=abcdefghijklmnopqrstuvwxyz123456789&responseCode=00&ApprovalRefNo=122321&Status=SUCCESS&txnRef=6655443322" | ||
const val RESPONSE_TRANSACTION_SUBMITTED = "txnId=abcdefghijklmnopqrstuvwxyz123456789&responseCode=ZM&ApprovalRefNo=122321&Status=SUBMITTED&txnRef=6655443322" | ||
const val RESPONSE_TRANSACTION_FAILURE = "txnId=abcdefghijklmnopqrstuvwxyz123456789&responseCode=Y1&ApprovalRefNo=122321&Status=FAILURE&txnRef=6655443322" | ||
} | ||
} | ||
|
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
Oops, something went wrong.