From d2dfa0255a1fe04b3eaf4e42e7aaa045bc52a73d Mon Sep 17 00:00:00 2001 From: Michael Shafrir Date: Mon, 3 Aug 2020 11:05:47 -0400 Subject: [PATCH] Deprecate Card.create() Use `CardParams` instead of `Card` in tests where relevant --- .../java/com/stripe/android/model/Card.kt | 7 + .../java/com/stripe/android/ApiRequestTest.kt | 11 +- .../android/FingerprintParamsUtilsTest.kt | 15 +- .../stripe/android/StripeApiRepositoryTest.kt | 22 +-- .../com/stripe/android/StripeEndToEndTest.kt | 6 +- .../java/com/stripe/android/StripeTest.java | 62 ++++---- .../com/stripe/android/model/CardFixtures.kt | 14 -- .../stripe/android/model/CardParamsFixture.kt | 16 -- .../android/model/CardParamsFixtures.kt | 33 ++++ .../stripe/android/model/CardParamsTest.kt | 2 +- .../java/com/stripe/android/model/CardTest.kt | 146 ++++++++++-------- .../model/ConfirmPaymentIntentParamsTest.kt | 2 +- .../stripe/android/model/SourceParamsTest.kt | 2 +- .../stripe/android/model/StripeModelTest.kt | 40 ++--- 14 files changed, 197 insertions(+), 181 deletions(-) delete mode 100644 stripe/src/test/java/com/stripe/android/model/CardParamsFixture.kt create mode 100644 stripe/src/test/java/com/stripe/android/model/CardParamsFixtures.kt diff --git a/stripe/src/main/java/com/stripe/android/model/Card.kt b/stripe/src/main/java/com/stripe/android/model/Card.kt index 6a790df447c..2f95f4c0217 100644 --- a/stripe/src/main/java/com/stripe/android/model/Card.kt +++ b/stripe/src/main/java/com/stripe/android/model/Card.kt @@ -556,6 +556,13 @@ data class Card internal constructor( * @param expYear the expiry year * @param cvc the CVC code */ + @Deprecated( + "Use CardParams", + ReplaceWith( + "Builder(number, expMonth, expYear, cvc).build()", + "com.stripe.android.model.Card.Builder" + ) + ) @JvmStatic fun create( number: String? = null, diff --git a/stripe/src/test/java/com/stripe/android/ApiRequestTest.kt b/stripe/src/test/java/com/stripe/android/ApiRequestTest.kt index 1781e89be96..347c56b0503 100644 --- a/stripe/src/test/java/com/stripe/android/ApiRequestTest.kt +++ b/stripe/src/test/java/com/stripe/android/ApiRequestTest.kt @@ -2,7 +2,7 @@ package com.stripe.android import android.net.Uri import com.google.common.truth.Truth.assertThat -import com.stripe.android.model.CardFixtures +import com.stripe.android.model.CardParamsFixtures import java.io.ByteArrayOutputStream import kotlin.test.Test import kotlin.test.assertEquals @@ -16,12 +16,11 @@ internal class ApiRequestTest { @Test fun url_withCardData_createsProperQueryString() { - val cardMap = CardFixtures.MINIMUM_CARD.toParamMap() - .plus(FINGERPRINT_DATA.params) val url = FACTORY.createGet( - StripeApiRepository.sourcesUrl, - OPTIONS, - cardMap + url = StripeApiRepository.sourcesUrl, + options = OPTIONS, + params = CardParamsFixtures.MINIMUM.toParamMap() + .plus(FINGERPRINT_DATA.params) ).url assertThat(Uri.parse(url)) diff --git a/stripe/src/test/java/com/stripe/android/FingerprintParamsUtilsTest.kt b/stripe/src/test/java/com/stripe/android/FingerprintParamsUtilsTest.kt index 0542c6c47e3..d1b48e278b0 100644 --- a/stripe/src/test/java/com/stripe/android/FingerprintParamsUtilsTest.kt +++ b/stripe/src/test/java/com/stripe/android/FingerprintParamsUtilsTest.kt @@ -1,7 +1,7 @@ package com.stripe.android import com.google.common.truth.Truth.assertThat -import com.stripe.android.model.CardFixtures +import com.stripe.android.model.CardParamsFixtures import com.stripe.android.model.ConfirmPaymentIntentParams import com.stripe.android.model.ConfirmStripeIntentParams.Companion.PARAM_PAYMENT_METHOD_DATA import com.stripe.android.model.PaymentMethodCreateParamsFixtures @@ -20,7 +20,7 @@ class FingerprintParamsUtilsTest { val updatedParams = fingerprintParamsUtils.addFingerprintData( params = mapOf( ConfirmPaymentIntentParams.PARAM_SOURCE_DATA to - SourceParams.createCardParams(CardFixtures.CARD).toParamMap() + SourceParams.createCardParams(CardParamsFixtures.DEFAULT).toParamMap() ), fingerprintData = FINGERPRINT_DATA ) @@ -33,19 +33,20 @@ class FingerprintParamsUtilsTest { "address" to mapOf( "city" to "San Francisco", "country" to "US", - "line1" to "1234 Main Street", - "line2" to "906", - "postal_code" to "94111", + "line1" to "123 Market St", + "line2" to "#345", + "postal_code" to "94107", "state" to "CA" ), "name" to "Jenny Rosen" ), "card" to mapOf( "number" to CardNumberFixtures.VISA_NO_SPACES, - "exp_month" to 8, - "exp_year" to 2019, + "exp_month" to 12, + "exp_year" to 2025, "cvc" to "123" ), + "metadata" to mapOf("fruit" to "orange"), "muid" to FINGERPRINT_DATA.muid, "guid" to FINGERPRINT_DATA.guid, "sid" to FINGERPRINT_DATA.sid diff --git a/stripe/src/test/java/com/stripe/android/StripeApiRepositoryTest.kt b/stripe/src/test/java/com/stripe/android/StripeApiRepositoryTest.kt index f701c539e0e..ebda848e42f 100644 --- a/stripe/src/test/java/com/stripe/android/StripeApiRepositoryTest.kt +++ b/stripe/src/test/java/com/stripe/android/StripeApiRepositoryTest.kt @@ -16,8 +16,8 @@ import com.nhaarman.mockitokotlin2.whenever import com.stripe.android.exception.APIConnectionException import com.stripe.android.exception.InvalidRequestException import com.stripe.android.model.BankAccountTokenParamsFixtures -import com.stripe.android.model.Card -import com.stripe.android.model.CardFixtures +import com.stripe.android.model.CardParams +import com.stripe.android.model.CardParamsFixtures import com.stripe.android.model.ConfirmPaymentIntentParams import com.stripe.android.model.ListPaymentMethodsParams import com.stripe.android.model.PaymentIntentFixtures @@ -187,7 +187,7 @@ class StripeApiRepositoryTest { @Test fun createSource_shouldLogSourceCreation_andReturnSource() { val source = stripeApiRepository.createSource( - SourceParams.createCardParams(CARD), + SourceParams.createCardParams(CARD_PARAMS), DEFAULT_OPTIONS ) @@ -205,7 +205,7 @@ class StripeApiRepositoryTest { whenever(stripeApiRequestExecutor.execute(any())) .thenReturn(stripeResponse) create().createSource( - SourceParams.createCardParams(CardFixtures.CARD_WITH_ATTRIBUTION), + SourceParams.createCardParams(CardParamsFixtures.WITH_ATTRIBUTION), DEFAULT_OPTIONS ) @@ -242,7 +242,7 @@ class StripeApiRepositoryTest { @Test fun createSource_withConnectAccount_keepsHeaderInAccount() { val connectAccountId = "acct_1Acj2PBUgO3KuWzz" - val source = stripeApiRepository.createSource(SourceParams.createCardParams(CARD), + val source = stripeApiRepository.createSource(SourceParams.createCardParams(CARD_PARAMS), ApiRequest.Options(ApiKeyFixtures.CONNECTED_ACCOUNT_PUBLISHABLE_KEY, connectAccountId)) // Check that we get a source back; we don't care about its fields for this test. @@ -345,7 +345,7 @@ class StripeApiRepositoryTest { ApiKeyFixtures.CONNECTED_ACCOUNT_PUBLISHABLE_KEY, connectAccountId ), - SourceParams.createCardParams(CARD).toParamMap() + SourceParams.createCardParams(CARD_PARAMS).toParamMap() ) ) assertNotNull(response) @@ -434,7 +434,7 @@ class StripeApiRepositoryTest { fingerprintDataRepository = fingerprintDataRepository ) val source = stripeApiRepository.createSource( - SourceParams.createCardParams(CARD), + SourceParams.createCardParams(CARD_PARAMS), DEFAULT_OPTIONS ) assertNotNull(source) @@ -734,7 +734,7 @@ class StripeApiRepositoryTest { assertFailsWith { create().createSource( - SourceParams.createCardParams(CARD), + SourceParams.createCardParams(CARD_PARAMS), DEFAULT_OPTIONS ) } @@ -812,7 +812,7 @@ class StripeApiRepositoryTest { ) whenever(stripeApiRequestExecutor.execute(any())).thenReturn(stripeResponse) create().createToken( - CardFixtures.CARD_WITH_ATTRIBUTION, + CardParamsFixtures.WITH_ATTRIBUTION, DEFAULT_OPTIONS ) @@ -935,8 +935,8 @@ class StripeApiRepositoryTest { private companion object { private const val STRIPE_ACCOUNT_RESPONSE_HEADER = "Stripe-Account" - private val CARD = - Card.create("4242424242424242", 1, 2050, "123") + private val CARD_PARAMS = + CardParams("4242424242424242", 1, 2050, "123") private val DEFAULT_OPTIONS = ApiRequest.Options(ApiKeyFixtures.DEFAULT_PUBLISHABLE_KEY) diff --git a/stripe/src/test/java/com/stripe/android/StripeEndToEndTest.kt b/stripe/src/test/java/com/stripe/android/StripeEndToEndTest.kt index 7ace8cadfd6..809eca933df 100644 --- a/stripe/src/test/java/com/stripe/android/StripeEndToEndTest.kt +++ b/stripe/src/test/java/com/stripe/android/StripeEndToEndTest.kt @@ -12,7 +12,7 @@ import com.stripe.android.model.AddressFixtures import com.stripe.android.model.Card import com.stripe.android.model.CardBrand import com.stripe.android.model.CardFunding -import com.stripe.android.model.CardParamsFixture +import com.stripe.android.model.CardParamsFixtures import com.stripe.android.model.PaymentIntent import com.stripe.android.model.PaymentMethod import com.stripe.android.model.PaymentMethodCreateParams @@ -133,7 +133,7 @@ class StripeEndToEndTest { @Test fun `create Source using CardParams should return object with expected data`() { val source = defaultStripe.createSourceSynchronous( - SourceParams.createCardParams(CardParamsFixture.DEFAULT) + SourceParams.createCardParams(CardParamsFixtures.DEFAULT) ) assertThat(source?.sourceTypeModel) .isEqualTo( @@ -155,7 +155,7 @@ class StripeEndToEndTest { @Test fun `create card token using CardParams should return object with expected data`() { val token = defaultStripe.createCardTokenSynchronous( - CardParamsFixture.DEFAULT + CardParamsFixtures.DEFAULT ) val card = token?.card diff --git a/stripe/src/test/java/com/stripe/android/StripeTest.java b/stripe/src/test/java/com/stripe/android/StripeTest.java index 7368fc11c10..5152c5e3922 100644 --- a/stripe/src/test/java/com/stripe/android/StripeTest.java +++ b/stripe/src/test/java/com/stripe/android/StripeTest.java @@ -15,8 +15,9 @@ import com.stripe.android.model.BankAccountTokenParamsFixtures; import com.stripe.android.model.Card; import com.stripe.android.model.CardBrand; -import com.stripe.android.model.CardFixtures; import com.stripe.android.model.CardFunding; +import com.stripe.android.model.CardParams; +import com.stripe.android.model.CardParamsFixtures; import com.stripe.android.model.PaymentMethod; import com.stripe.android.model.PaymentMethodCreateParams; import com.stripe.android.model.PaymentMethodCreateParamsFixtures; @@ -49,6 +50,7 @@ import kotlinx.coroutines.CoroutineScope; +import static com.google.common.truth.Truth.assertThat; import static kotlinx.coroutines.CoroutineScopeKt.MainScope; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -64,7 +66,7 @@ */ @RunWith(RobolectricTestRunner.class) public class StripeTest { - private static final Card CARD = CardFixtures.MINIMUM_CARD; + private static final CardParams CARD_PARAMS = CardParamsFixtures.MINIMUM; @NonNull private final Context context = ApplicationProvider.getApplicationContext(); @@ -134,7 +136,7 @@ public void constructorShouldFailWithSecretKey() { @Test public void createCardTokenShouldCreateRealToken() { final Stripe stripe = createStripe(MainScope()); - stripe.createCardToken(CARD, tokenCallback); + stripe.createCardToken(CARD_PARAMS, tokenCallback); verify(tokenCallback).onSuccess(tokenArgumentCaptor.capture()); final Token token = tokenArgumentCaptor.getValue(); final String tokenId = token.getId(); @@ -144,17 +146,20 @@ public void createCardTokenShouldCreateRealToken() { @Test public void createCardTokenSynchronous_withValidData_returnsToken() throws StripeException { - final Token token = defaultStripe.createCardTokenSynchronous(CARD); + final Token token = defaultStripe.createCardTokenSynchronous(CARD_PARAMS); assertNotNull(token); Card returnedCard = token.getCard(); assertNotNull(returnedCard); assertNull(token.getBankAccount()); assertEquals(Token.Type.Card, token.getType()); - assertEquals(CARD.getLast4(), returnedCard.getLast4()); assertEquals(CardBrand.Visa, returnedCard.getBrand()); - assertEquals(CARD.getExpYear(), returnedCard.getExpYear()); - assertEquals(CARD.getExpMonth(), returnedCard.getExpMonth()); + assertThat(returnedCard.getLast4()) + .isEqualTo("4242"); + assertThat(returnedCard.getExpYear()) + .isEqualTo(2050); + assertThat(returnedCard.getExpMonth()) + .isEqualTo(1); assertEquals(CardFunding.Credit, returnedCard.getFunding()); } @@ -167,17 +172,20 @@ public void createCardTokenSynchronous_withValidDataAndConnectAccount_returnsTok "acct_1Acj2PBUgO3KuWzz" ); - final Token token = stripe.createCardTokenSynchronous(CARD); + final Token token = stripe.createCardTokenSynchronous(CARD_PARAMS); assertNotNull(token); Card returnedCard = token.getCard(); assertNotNull(returnedCard); assertNull(token.getBankAccount()); assertEquals(Token.Type.Card, token.getType()); - assertEquals(CARD.getLast4(), returnedCard.getLast4()); assertEquals(CardBrand.Visa, returnedCard.getBrand()); - assertEquals(CARD.getExpYear(), returnedCard.getExpYear()); - assertEquals(CARD.getExpMonth(), returnedCard.getExpMonth()); + assertThat(returnedCard.getLast4()) + .isEqualTo("4242"); + assertThat(returnedCard.getExpYear()) + .isEqualTo(2050); + assertThat(returnedCard.getExpMonth()) + .isEqualTo(1); assertEquals(CardFunding.Credit, returnedCard.getFunding()); } @@ -185,7 +193,7 @@ public void createCardTokenSynchronous_withValidDataAndConnectAccount_returnsTok public void createToken_createSource_returnsSource() throws StripeException { final Stripe stripe = defaultStripe; - final Token token = stripe.createCardTokenSynchronous(CARD); + final Token token = stripe.createCardTokenSynchronous(CARD_PARAMS); assertNotNull(token); final SourceParams sourceParams = SourceParams.createSourceFromTokenParams(token.getId()); @@ -197,7 +205,7 @@ public void createToken_createSource_returnsSource() public void createToken_createSourceWithTokenToSourceParams_returnsSource() throws StripeException { final Stripe stripe = defaultStripe; - final Token token = stripe.createCardTokenSynchronous(CARD); + final Token token = stripe.createCardTokenSynchronous(CARD_PARAMS); assertNotNull(token); final SourceParams sourceParams = SourceParams.createSourceFromTokenParams(token.getId()); @@ -241,7 +249,7 @@ public void onError(@NonNull Exception e) { @Test public void testCreateSource() { createStripe().createSource( - SourceParams.createCardParams(CARD), + SourceParams.createCardParams(CARD_PARAMS), new ApiResultCallback() { @Override public void onSuccess(@NonNull Source result) { @@ -468,7 +476,7 @@ public void createSourceSynchronous_withCardParams_passesIntegrationTest() public void createSourceSynchronous_with3DSParams_passesIntegrationTest() throws StripeException { final Stripe stripe = defaultStripe; - final SourceParams params = SourceParams.createCardParams(CARD); + final SourceParams params = SourceParams.createCardParams(CARD_PARAMS); final Source cardSource = stripe.createSourceSynchronous(params); assertNotNull(cardSource); @@ -858,7 +866,7 @@ public void retrieveSourceSynchronous_withValidData_passesIntegrationTest() public void createSourceFromTokenParams_withExtraParams_succeeds() throws StripeException { final Stripe stripe = defaultStripe; - final Token token = stripe.createCardTokenSynchronous(CARD); + final Token token = stripe.createCardTokenSynchronous(CARD_PARAMS); assertNotNull(token); final Map map = new HashMap<>(); @@ -1032,7 +1040,7 @@ public void createTokenSynchronous_withValidDataAndBadKey_throwsAuthenticationEx final Stripe stripe = createStripe(ApiKeyFixtures.FAKE_PUBLISHABLE_KEY); final AuthenticationException authenticationException = assertThrows( AuthenticationException.class, - () -> stripe.createCardTokenSynchronous(CARD) + () -> stripe.createCardTokenSynchronous(CARD_PARAMS) ); assertEquals("Invalid API Key provided: " + ApiKeyFixtures.FAKE_PUBLISHABLE_KEY, authenticationException.getMessage()); @@ -1041,10 +1049,10 @@ public void createTokenSynchronous_withValidDataAndBadKey_throwsAuthenticationEx @Test public void createTokenSynchronous_withInvalidCardNumber_throwsCardException() { // This card is missing quite a few numbers. - final Card card = Card.create("42424242", 12, 2050, "123"); + final CardParams cardParams = new CardParams("42424242", 12, 2050, "123"); final CardException cardException = assertThrows( CardException.class, - () -> defaultStripe.createCardTokenSynchronous(card) + () -> defaultStripe.createCardTokenSynchronous(cardParams) ); assertEquals("Your card number is incorrect.", cardException.getMessage()); } @@ -1062,10 +1070,10 @@ public void retrievePaymentIntent_withInvalidClientSecret_shouldThrowException() @Test public void createTokenSynchronous_withExpiredCard_throwsCardException() { // This card is missing quite a few numbers. - final Card card = Card.create("4242424242424242", 11, 2015, "123"); + final CardParams cardParams = new CardParams("4242424242424242", 11, 2015, "123"); final CardException cardException = assertThrows( CardException.class, - () -> defaultStripe.createCardTokenSynchronous(card) + () -> defaultStripe.createCardTokenSynchronous(cardParams) ); assertEquals("Your card's expiration year is invalid.", cardException.getMessage()); @@ -1082,8 +1090,8 @@ public void createTokenSynchronousTwice_withIdempotencyKey_returnsSameToken() final String idempotencyKey = UUID.randomUUID().toString(); assertEquals( - stripe.createCardTokenSynchronous(CardFixtures.MINIMUM_CARD, idempotencyKey), - stripe.createCardTokenSynchronous(CardFixtures.MINIMUM_CARD, idempotencyKey) + stripe.createCardTokenSynchronous(CardParamsFixtures.MINIMUM, idempotencyKey), + stripe.createCardTokenSynchronous(CardParamsFixtures.MINIMUM, idempotencyKey) ); } @@ -1092,8 +1100,8 @@ public void createTokenSynchronousTwice_withoutIdempotencyKey_returnsDifferentTo throws StripeException { final Stripe stripe = defaultStripe; assertNotEquals( - stripe.createCardTokenSynchronous(CardFixtures.MINIMUM_CARD), - stripe.createCardTokenSynchronous(CardFixtures.MINIMUM_CARD) + stripe.createCardTokenSynchronous(CardParamsFixtures.MINIMUM), + stripe.createCardTokenSynchronous(CardParamsFixtures.MINIMUM) ); } @@ -1115,7 +1123,7 @@ public void createPaymentMethodSynchronous_withCard() public void createPaymentMethod_withCardToken() throws StripeException { final Stripe stripe = defaultStripe; - final Token token = Objects.requireNonNull(stripe.createCardTokenSynchronous(CARD)); + final Token token = Objects.requireNonNull(stripe.createCardTokenSynchronous(CARD_PARAMS)); final PaymentMethodCreateParams paymentMethodCreateParams = PaymentMethodCreateParams.create( @@ -1283,7 +1291,7 @@ public void createFileSynchronous_shouldCreateFile() { @NonNull private Source createSource() throws StripeException { final Stripe stripe = defaultStripe; - final SourceParams params = SourceParams.createCardParams(CARD); + final SourceParams params = SourceParams.createCardParams(CARD_PARAMS); final Source cardSource = stripe.createSourceSynchronous(params); diff --git a/stripe/src/test/java/com/stripe/android/model/CardFixtures.kt b/stripe/src/test/java/com/stripe/android/model/CardFixtures.kt index d39a3748053..e6bf04eefd1 100644 --- a/stripe/src/test/java/com/stripe/android/model/CardFixtures.kt +++ b/stripe/src/test/java/com/stripe/android/model/CardFixtures.kt @@ -1,19 +1,9 @@ package com.stripe.android.model -import com.stripe.android.CardNumberFixtures import com.stripe.android.model.parsers.CardJsonParser import org.json.JSONObject object CardFixtures { - - @JvmField - val MINIMUM_CARD: Card = Card.create( - CardNumberFixtures.VISA_NO_SPACES, - 1, - 2050, - "123" - ) - private const val CARD_ADDRESS_L1 = "1234 Main Street" private const val CARD_ADDRESS_L2 = "906" private const val CARD_CITY = "San Francisco" @@ -132,8 +122,4 @@ object CardFixtures { } """.trimIndent() ))) - - internal val CARD_WITH_ATTRIBUTION = Card.Builder() - .loggingTokens(setOf("CardInputView")) - .build() } diff --git a/stripe/src/test/java/com/stripe/android/model/CardParamsFixture.kt b/stripe/src/test/java/com/stripe/android/model/CardParamsFixture.kt deleted file mode 100644 index f87a70102a0..00000000000 --- a/stripe/src/test/java/com/stripe/android/model/CardParamsFixture.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.stripe.android.model - -import com.stripe.android.CardNumberFixtures - -internal object CardParamsFixture { - val DEFAULT = CardParams( - number = CardNumberFixtures.VISA_NO_SPACES, - expMonth = 12, - expYear = 2025, - cvc = "123", - name = "Jenny Rosen", - address = AddressFixtures.ADDRESS, - currency = "usd", - metadata = mapOf("fruit" to "orange") - ) -} diff --git a/stripe/src/test/java/com/stripe/android/model/CardParamsFixtures.kt b/stripe/src/test/java/com/stripe/android/model/CardParamsFixtures.kt new file mode 100644 index 00000000000..d7d481329a0 --- /dev/null +++ b/stripe/src/test/java/com/stripe/android/model/CardParamsFixtures.kt @@ -0,0 +1,33 @@ +package com.stripe.android.model + +import com.stripe.android.CardNumberFixtures +import com.stripe.android.view.CardInputWidget + +internal object CardParamsFixtures { + @JvmField + val MINIMUM = CardParams( + CardNumberFixtures.VISA_NO_SPACES, + 1, + 2050, + "123" + ) + + val DEFAULT = CardParams( + number = CardNumberFixtures.VISA_NO_SPACES, + expMonth = 12, + expYear = 2025, + cvc = "123", + name = "Jenny Rosen", + address = AddressFixtures.ADDRESS, + currency = "usd", + metadata = mapOf("fruit" to "orange") + ) + + val WITH_ATTRIBUTION = CardParams( + loggingTokens = setOf(CardInputWidget.LOGGING_TOKEN), + number = CardNumberFixtures.VISA_NO_SPACES, + expMonth = 12, + expYear = 2025, + cvc = "123" + ) +} diff --git a/stripe/src/test/java/com/stripe/android/model/CardParamsTest.kt b/stripe/src/test/java/com/stripe/android/model/CardParamsTest.kt index bf3cd4e4b00..67c54f3484e 100644 --- a/stripe/src/test/java/com/stripe/android/model/CardParamsTest.kt +++ b/stripe/src/test/java/com/stripe/android/model/CardParamsTest.kt @@ -7,7 +7,7 @@ class CardParamsTest { @Test fun `toParamMap() should create expected map`() { - assertThat(CardParamsFixture.DEFAULT.toParamMap()) + assertThat(CardParamsFixtures.DEFAULT.toParamMap()) .isEqualTo( mapOf("card" to mapOf( diff --git a/stripe/src/test/java/com/stripe/android/model/CardTest.kt b/stripe/src/test/java/com/stripe/android/model/CardTest.kt index 20ad9d7ccdd..5d5d6ecbef4 100644 --- a/stripe/src/test/java/com/stripe/android/model/CardTest.kt +++ b/stripe/src/test/java/com/stripe/android/model/CardTest.kt @@ -29,141 +29,141 @@ class CardTest { @Test fun canInitializeWithMinimalArguments() { - val card = Card.create(number = "4242-4242-4242-4242", expMonth = 12, expYear = 2050, cvc = "123") + val card = createCard(number = "4242-4242-4242-4242", expMonth = 12, expYear = 2050, cvc = "123") assertTrue(card.validateNumber()) } @Test fun testTypeReturnsCorrectlyForAmexCard() { - val card = Card.create(number = "3412123412341234") + val card = createCard(number = "3412123412341234") assertEquals(CardBrand.AmericanExpress, card.brand) } @Test fun testTypeReturnsCorrectlyForDiscoverCard() { - val card = Card.create(number = "6452123412341234") + val card = createCard(number = "6452123412341234") assertEquals(CardBrand.Discover, card.brand) } @Test fun testTypeReturnsCorrectlyForJCBCard() { - val card = Card.create(number = CardNumberFixtures.JCB_NO_SPACES) + val card = createCard(number = CardNumberFixtures.JCB_NO_SPACES) assertEquals(CardBrand.JCB, card.brand) } @Test fun testTypeReturnsCorrectlyForDinersClubCard() { - val card = Card.create(number = "3612123412341234") + val card = createCard(number = "3612123412341234") assertEquals(CardBrand.DinersClub, card.brand) } @Test fun testTypeReturnsCorrectlyForVisaCard() { - val card = Card.create(number = "4112123412341234") + val card = createCard(number = "4112123412341234") assertEquals(CardBrand.Visa, card.brand) } @Test fun testTypeReturnsCorrectlyForMasterCard() { - val card = Card.create(number = "5112123412341234") + val card = createCard(number = "5112123412341234") assertEquals(CardBrand.MasterCard, card.brand) } @Test fun testTypeReturnsCorrectlyForUnionPay() { - val card = Card.create(number = CardNumberFixtures.UNIONPAY_NO_SPACES) + val card = createCard(number = CardNumberFixtures.UNIONPAY_NO_SPACES) assertEquals(CardBrand.UnionPay, card.brand) } @Test fun shouldPassValidateNumberIfLuhnNumber() { - val card = Card.create(number = "4242-4242-4242-4242") + val card = createCard(number = "4242-4242-4242-4242") assertTrue(card.validateNumber()) } @Test fun shouldFailValidateNumberIfNotLuhnNumber() { - val card = Card.create(number = "4242-4242-4242-4241") + val card = createCard(number = "4242-4242-4242-4241") assertFalse(card.validateNumber()) } @Test fun shouldPassValidateNumberIfLuhnNumberAmex() { - val card = Card.create(number = CardNumberFixtures.AMEX_NO_SPACES) + val card = createCard(number = CardNumberFixtures.AMEX_NO_SPACES) assertEquals(CardBrand.AmericanExpress, card.brand) assertTrue(card.validateNumber()) } @Test fun shouldFailValidateNumberIfNull() { - val card = Card.create(cvc = null) + val card = createCard(cvc = null) assertFalse(card.validateNumber()) } @Test fun shouldFailValidateNumberIfBlank() { - val card = Card.create(number = "") + val card = createCard(number = "") assertFalse(card.validateNumber()) } @Test fun shouldFailValidateNumberIfJustSpaces() { - val card = Card.create(number = " ") + val card = createCard(number = " ") assertFalse(card.validateNumber()) } @Test fun shouldFailValidateNumberIfTooShort() { - val card = Card.create(number = "0") + val card = createCard(number = "0") assertFalse(card.validateNumber()) } @Test fun shouldFailValidateNumberIfContainsLetters() { - val card = Card.create(number = "424242424242a4242") + val card = createCard(number = "424242424242a4242") assertFalse(card.validateNumber()) } @Test fun shouldFailValidateNumberIfTooLong() { - val card = Card.create(number = "4242 4242 4242 4242 6") + val card = createCard(number = "4242 4242 4242 4242 6") assertEquals(CardBrand.Visa, card.brand) assertFalse(card.validateNumber()) } @Test fun shouldPassValidateNumber() { - val card = Card.create(CardNumberFixtures.VISA_NO_SPACES) + val card = createCard(CardNumberFixtures.VISA_NO_SPACES) assertTrue(card.validateNumber()) } @Test fun shouldPassValidateNumberSpaces() { - val card = Card.create(CardNumberFixtures.VISA_WITH_SPACES) + val card = createCard(CardNumberFixtures.VISA_WITH_SPACES) assertTrue(card.validateNumber()) } @Test fun shouldPassValidateNumberDashes() { - val card = Card.create(number = "4242-4242-4242-4242") + val card = createCard(number = "4242-4242-4242-4242") assertTrue(card.validateNumber()) } @Test fun shouldPassValidateNumberWithMixedSeparators() { - val card = Card.create(number = "4242-4 242 424-24 242") + val card = createCard(number = "4242-4 242 424-24 242") assertTrue(card.validateNumber()) } @Test fun shouldFailValidateNumberIfWithDot() { - val card = Card.create(number = "4242.4242.4242.4242") + val card = createCard(number = "4242.4242.4242.4242") assertFalse(card.validateNumber()) } @Test fun shouldFailValidateExpiryDateIfNull() { - val card = Card.create(cvc = null) + val card = createCard(cvc = null) assertFalse(card.validateExpMonth()) assertFalse(card.validateExpYear(calendar)) assertFalse(card.validateExpiryDate(calendar)) @@ -171,7 +171,7 @@ class CardTest { @Test fun shouldFailValidateExpiryDateIfNullMonth() { - val card = Card.create(expYear = YEAR_IN_FUTURE) + val card = createCard(expYear = YEAR_IN_FUTURE) assertFalse(card.validateExpMonth()) assertTrue(card.validateExpYear(calendar)) assertFalse(card.validateExpiryDate(calendar)) @@ -179,7 +179,7 @@ class CardTest { @Test fun shouldFailValidateExpiryDateIfZeroMonth() { - val card = Card.create(expMonth = 0, expYear = YEAR_IN_FUTURE) + val card = createCard(expMonth = 0, expYear = YEAR_IN_FUTURE) assertFalse(card.validateExpMonth()) assertTrue(card.validateExpYear(calendar)) assertFalse(card.validateExpiryDate(calendar)) @@ -187,7 +187,7 @@ class CardTest { @Test fun shouldFailValidateExpiryDateIfNegativeMonth() { - val card = Card.create(expMonth = -1, expYear = YEAR_IN_FUTURE) + val card = createCard(expMonth = -1, expYear = YEAR_IN_FUTURE) assertFalse(card.validateExpMonth()) assertTrue(card.validateExpYear(calendar)) assertFalse(card.validateExpiryDate(calendar)) @@ -195,7 +195,7 @@ class CardTest { @Test fun shouldFailValidateExpiryDateIfMonthToLarge() { - val card = Card.create(expMonth = 13, expYear = YEAR_IN_FUTURE) + val card = createCard(expMonth = 13, expYear = YEAR_IN_FUTURE) assertFalse(card.validateExpMonth()) assertTrue(card.validateExpYear(calendar)) assertFalse(card.validateExpiryDate(calendar)) @@ -203,13 +203,13 @@ class CardTest { @Test fun shouldFailValidateExpiryDateIfNullYear() { - val card = Card.create(expMonth = 1) + val card = createCard(expMonth = 1) assertFalse(card.validateExpiryDate(calendar)) } @Test fun shouldFailValidateExpiryDateIfZeroYear() { - val card = Card.create(expMonth = 12, expYear = 0) + val card = createCard(expMonth = 12, expYear = 0) assertTrue(card.validateExpMonth()) assertFalse(card.validateExpYear(calendar)) assertFalse(card.validateExpiryDate(calendar)) @@ -217,7 +217,7 @@ class CardTest { @Test fun shouldFailValidateExpiryDateIfNegativeYear() { - val card = Card.create(expMonth = 12, expYear = -1) + val card = createCard(expMonth = 12, expYear = -1) assertTrue(card.validateExpMonth()) assertFalse(card.validateExpYear(calendar)) assertFalse(card.validateExpiryDate(calendar)) @@ -225,7 +225,7 @@ class CardTest { @Test fun shouldPassValidateExpiryDateForDecemberOfThisYear() { - val card = Card.create(expMonth = 12, expYear = 1997) + val card = createCard(expMonth = 12, expYear = 1997) assertTrue(card.validateExpMonth()) assertTrue(card.validateExpYear(calendar)) assertTrue(card.validateExpiryDate(calendar)) @@ -233,7 +233,7 @@ class CardTest { @Test fun shouldPassValidateExpiryDateIfCurrentMonth() { - val card = Card.create(expMonth = 8, expYear = 1997) + val card = createCard(expMonth = 8, expYear = 1997) assertTrue(card.validateExpMonth()) assertTrue(card.validateExpYear(calendar)) assertTrue(card.validateExpiryDate(calendar)) @@ -241,7 +241,7 @@ class CardTest { @Test fun shouldPassValidateExpiryDateIfCurrentMonthTwoDigitYear() { - val card = Card.create(expMonth = 8, expYear = 97) + val card = createCard(expMonth = 8, expYear = 97) assertTrue(card.validateExpMonth()) assertTrue(card.validateExpYear(calendar)) assertTrue(card.validateExpiryDate(calendar)) @@ -249,7 +249,7 @@ class CardTest { @Test fun shouldFailValidateExpiryDateIfLastMonth() { - val card = Card.create(expMonth = 7, expYear = 1997) + val card = createCard(expMonth = 7, expYear = 1997) assertTrue(card.validateExpMonth()) assertTrue(card.validateExpYear(calendar)) assertFalse(card.validateExpiryDate(calendar)) @@ -257,7 +257,7 @@ class CardTest { @Test fun shouldPassValidateExpiryDateIfNextMonth() { - val card = Card.create(expMonth = 9, expYear = 1997) + val card = createCard(expMonth = 9, expYear = 1997) assertTrue(card.validateExpMonth()) assertTrue(card.validateExpYear(calendar)) assertTrue(card.validateExpiryDate(calendar)) @@ -265,7 +265,7 @@ class CardTest { @Test fun shouldPassValidateExpiryDateForJanuary00() { - val card = Card.create(expMonth = 1, expYear = 0) + val card = createCard(expMonth = 1, expYear = 0) assertTrue(card.validateExpMonth()) assertFalse(card.validateExpYear(calendar)) assertFalse(card.validateExpiryDate(calendar)) @@ -273,7 +273,7 @@ class CardTest { @Test fun shouldPassValidateExpiryDateForDecember99() { - val card = Card.create(expMonth = 12, expYear = 99) + val card = createCard(expMonth = 12, expYear = 99) assertTrue(card.validateExpMonth()) assertTrue(card.validateExpYear(calendar)) assertTrue(card.validateExpiryDate(calendar)) @@ -281,103 +281,103 @@ class CardTest { @Test fun shouldFailValidateCVCIfNull() { - val card = Card.create(cvc = null) + val card = createCard(cvc = null) assertFalse(card.validateCVC()) } @Test fun shouldFailValidateCVCIfBlank() { - val card = Card.create(cvc = "") + val card = createCard(cvc = "") assertFalse(card.validateCVC()) } @Test fun shouldFailValidateCVCIfUnknownTypeAndLength2() { - val card = Card.create(cvc = "12") + val card = createCard(cvc = "12") assertFalse(card.validateCVC()) } @Test fun shouldPassValidateCVCIfUnknownTypeAndLength3() { - val card = Card.create(cvc = "123") + val card = createCard(cvc = "123") assertTrue(card.validateCVC()) } @Test fun shouldPassValidateCVCIfUnknownTypeAndLength4() { - val card = Card.create(cvc = "1234") + val card = createCard(cvc = "1234") assertTrue(card.validateCVC()) } @Test fun shouldFailValidateCVCIfUnknownTypeAndLength5() { - val card = Card.create(cvc = "12345") + val card = createCard(cvc = "12345") assertFalse(card.validateCVC()) } @Test fun shouldFailValidateCVCIfVisaAndLength2() { - val card = Card.create(number = "4242 4242 4242 4242", cvc = "12") + val card = createCard(number = "4242 4242 4242 4242", cvc = "12") assertFalse(card.validateCVC()) } @Test fun shouldPassValidateCVCIfVisaAndLength3() { - val card = Card.create(number = "4242 4242 4242 4242", cvc = "123") + val card = createCard(number = "4242 4242 4242 4242", cvc = "123") assertTrue(card.validateCVC()) } @Test fun shouldFailValidateCVCIfVisaAndLength4() { - val card = Card.create(number = "4242 4242 4242 4242", cvc = "1234") + val card = createCard(number = "4242 4242 4242 4242", cvc = "1234") assertFalse(card.validateCVC()) } @Test fun shouldFailValidateCVCIfVisaAndLength5() { - val card = Card.create(number = "4242 4242 4242 4242", cvc = "12345") + val card = createCard(number = "4242 4242 4242 4242", cvc = "12345") assertFalse(card.validateCVC()) } @Test fun shouldFailValidateCVCIfVisaAndNotNumeric() { - val card = Card.create(number = "4242 4242 4242 4242", cvc = "12a") + val card = createCard(number = "4242 4242 4242 4242", cvc = "12a") assertFalse(card.validateCVC()) } @Test fun shouldPassValidateCVCIfAmexAndLength2() { - val card = Card.create(number = CardNumberFixtures.AMEX_NO_SPACES, cvc = "12") + val card = createCard(number = CardNumberFixtures.AMEX_NO_SPACES, cvc = "12") assertFalse(card.validateCVC()) } @Test fun shouldPassValidateCVCIfAmexAndLength3() { - val card = Card.create(number = CardNumberFixtures.AMEX_NO_SPACES, cvc = "123") + val card = createCard(number = CardNumberFixtures.AMEX_NO_SPACES, cvc = "123") assertTrue(card.validateCVC()) } @Test fun shouldPassValidateCVCIfAmexAndLength4() { - val card = Card.create(number = CardNumberFixtures.AMEX_NO_SPACES, cvc = "1234") + val card = createCard(number = CardNumberFixtures.AMEX_NO_SPACES, cvc = "1234") assertTrue(card.validateCVC()) } @Test fun shouldFailValidateCVCIfAmexAndLength5() { - val card = Card.create(number = CardNumberFixtures.AMEX_NO_SPACES, cvc = "12345") + val card = createCard(number = CardNumberFixtures.AMEX_NO_SPACES, cvc = "12345") assertFalse(card.validateCVC()) } @Test fun shouldFailValidateCVCIfAmexAndNotNumeric() { - val card = Card.create(number = CardNumberFixtures.AMEX_NO_SPACES, cvc = "123d") + val card = createCard(number = CardNumberFixtures.AMEX_NO_SPACES, cvc = "123d") assertFalse(card.validateCVC()) } @Test fun shouldFailValidateCardIfNotLuhnNumber() { - val card = Card.create(number = "4242-4242-4242-4241", expMonth = 12, expYear = 2050, cvc = "123") + val card = createCard(number = "4242-4242-4242-4241", expMonth = 12, expYear = 2050, cvc = "123") assertFalse(card.validateCard()) assertFalse(card.validateNumber()) assertTrue(card.validateExpiryDate(calendar)) @@ -386,7 +386,7 @@ class CardTest { @Test fun shouldFailValidateCardInvalidMonth() { - val card = Card.create(number = "4242-4242-4242-4242", expMonth = 13, expYear = 2050, cvc = "123") + val card = createCard(number = "4242-4242-4242-4242", expMonth = 13, expYear = 2050, cvc = "123") assertFalse(card.validateCard()) assertTrue(card.validateNumber()) assertFalse(card.validateExpiryDate(calendar)) @@ -395,7 +395,7 @@ class CardTest { @Test fun shouldFailValidateCardInvalidYear() { - val card = Card.create(number = "4242-4242-4242-4242", expMonth = 1, expYear = 1990, cvc = "123") + val card = createCard(number = "4242-4242-4242-4242", expMonth = 1, expYear = 1990, cvc = "123") assertFalse(card.validateCard(calendar)) assertTrue(card.validateNumber()) assertFalse(card.validateExpiryDate(calendar)) @@ -404,7 +404,7 @@ class CardTest { @Test fun shouldPassValidateCardWithNullCVC() { - val card = Card.create(number = "4242-4242-4242-4242", expMonth = 12, expYear = 2050) + val card = createCard(number = "4242-4242-4242-4242", expMonth = 12, expYear = 2050) assertTrue(card.validateCard(calendar)) assertTrue(card.validateNumber()) assertTrue(card.validateExpiryDate(calendar)) @@ -413,7 +413,7 @@ class CardTest { @Test fun shouldPassValidateCardVisa() { - val card = Card.create(number = "4242-4242-4242-4242", expMonth = 12, expYear = 2050, cvc = "123") + val card = createCard(number = "4242-4242-4242-4242", expMonth = 12, expYear = 2050, cvc = "123") assertTrue(card.validateCard(calendar)) assertTrue(card.validateNumber()) assertTrue(card.validateExpiryDate(calendar)) @@ -422,7 +422,7 @@ class CardTest { @Test fun shouldFailValidateCardVisaWithShortCVC() { - val card = Card.create(number = "4242-4242-4242-4242", expMonth = 12, expYear = 2050, cvc = "12") + val card = createCard(number = "4242-4242-4242-4242", expMonth = 12, expYear = 2050, cvc = "12") assertFalse(card.validateCard(calendar)) assertTrue(card.validateNumber()) assertTrue(card.validateExpiryDate(calendar)) @@ -431,7 +431,7 @@ class CardTest { @Test fun shouldFailValidateCardVisaWithLongCVC() { - val card = Card.create(number = "4242-4242-4242-4242", expMonth = 12, expYear = 2050, cvc = "1234") + val card = createCard(number = "4242-4242-4242-4242", expMonth = 12, expYear = 2050, cvc = "1234") assertFalse(card.validateCard(calendar)) assertTrue(card.validateNumber()) assertTrue(card.validateExpiryDate(calendar)) @@ -440,7 +440,7 @@ class CardTest { @Test fun shouldFailValidateCardVisaWithBadCVC() { - val card = Card.create(number = "4242-4242-4242-4242", expMonth = 12, expYear = 2050, cvc = "bad") + val card = createCard(number = "4242-4242-4242-4242", expMonth = 12, expYear = 2050, cvc = "bad") assertFalse(card.validateCard(calendar)) assertTrue(card.validateNumber()) assertTrue(card.validateExpiryDate(calendar)) @@ -449,7 +449,7 @@ class CardTest { @Test fun shouldPassValidateCardAmex() { - val card = Card.create(number = CardNumberFixtures.AMEX_NO_SPACES, expMonth = 12, expYear = 2050, cvc = "1234") + val card = createCard(number = CardNumberFixtures.AMEX_NO_SPACES, expMonth = 12, expYear = 2050, cvc = "1234") assertTrue(card.validateCard(calendar)) assertTrue(card.validateNumber()) assertTrue(card.validateExpiryDate(calendar)) @@ -458,7 +458,7 @@ class CardTest { @Test fun shouldPassValidateCardAmexWithNullCVC() { - val card = Card.create(number = CardNumberFixtures.AMEX_NO_SPACES, expMonth = 12, expYear = 2050) + val card = createCard(number = CardNumberFixtures.AMEX_NO_SPACES, expMonth = 12, expYear = 2050) assertTrue(card.validateCard(calendar)) assertTrue(card.validateNumber()) assertTrue(card.validateExpiryDate(calendar)) @@ -467,7 +467,7 @@ class CardTest { @Test fun shouldFailValidateCardAmexWithShortCVC() { - val card = Card.create(number = CardNumberFixtures.AMEX_NO_SPACES, expMonth = 12, expYear = 2050, cvc = "12") + val card = createCard(number = CardNumberFixtures.AMEX_NO_SPACES, expMonth = 12, expYear = 2050, cvc = "12") assertFalse(card.validateCard(calendar)) assertTrue(card.validateNumber()) assertTrue(card.validateExpiryDate(calendar)) @@ -476,7 +476,7 @@ class CardTest { @Test fun shouldFailValidateCardAmexWithLongCVC() { - val card = Card.create(number = CardNumberFixtures.AMEX_NO_SPACES, expMonth = 12, expYear = 2050, cvc = "12345") + val card = createCard(number = CardNumberFixtures.AMEX_NO_SPACES, expMonth = 12, expYear = 2050, cvc = "12345") assertFalse(card.validateCard(calendar)) assertTrue(card.validateNumber()) assertTrue(card.validateExpiryDate(calendar)) @@ -485,7 +485,7 @@ class CardTest { @Test fun shouldFailValidateCardAmexWithBadCVC() { - val card = Card.create(number = CardNumberFixtures.AMEX_NO_SPACES, expMonth = 12, expYear = 2050, cvc = "bad") + val card = createCard(number = CardNumberFixtures.AMEX_NO_SPACES, expMonth = 12, expYear = 2050, cvc = "bad") assertFalse(card.validateCard(calendar)) assertTrue(card.validateNumber()) assertTrue(card.validateExpiryDate(calendar)) @@ -494,13 +494,13 @@ class CardTest { @Test fun testLast4() { - val card = Card.create(number = "42 42 42 42 42 42 42 42") + val card = createCard(number = "42 42 42 42 42 42 42 42") assertEquals("4242", card.last4) } @Test fun last4ShouldBeNullWhenNumberIsNull() { - val card = Card.create(cvc = null) + val card = createCard(cvc = null) assertNull(card.last4) } @@ -662,5 +662,15 @@ class CardTest { "animal" to "dog" )) .build() + + private fun createCard( + number: String? = null, + expMonth: Int? = null, + expYear: Int? = null, + cvc: String? = null + ): Card { + return Card.Builder(number, expMonth, expYear, cvc) + .build() + } } } diff --git a/stripe/src/test/java/com/stripe/android/model/ConfirmPaymentIntentParamsTest.kt b/stripe/src/test/java/com/stripe/android/model/ConfirmPaymentIntentParamsTest.kt index 44ad0ff41fd..f1ec1fbdf1c 100644 --- a/stripe/src/test/java/com/stripe/android/model/ConfirmPaymentIntentParamsTest.kt +++ b/stripe/src/test/java/com/stripe/android/model/ConfirmPaymentIntentParamsTest.kt @@ -7,7 +7,7 @@ class ConfirmPaymentIntentParamsTest { @Test fun toParamMap_withSourceParams_shouldCreateExpectedMap() { - val sourceParams = SourceParams.createCardParams(CardFixtures.CARD) + val sourceParams = SourceParams.createCardParams(CardParamsFixtures.MINIMUM) val params = ConfirmPaymentIntentParams .createWithSourceParams(sourceParams, CLIENT_SECRET, RETURN_URL) .toParamMap() diff --git a/stripe/src/test/java/com/stripe/android/model/SourceParamsTest.kt b/stripe/src/test/java/com/stripe/android/model/SourceParamsTest.kt index 866ac5fe8d2..ee498832cc4 100644 --- a/stripe/src/test/java/com/stripe/android/model/SourceParamsTest.kt +++ b/stripe/src/test/java/com/stripe/android/model/SourceParamsTest.kt @@ -172,7 +172,7 @@ class SourceParamsTest { @Test fun `create with CardParams object should return expected map`() { - assertThat(SourceParams.createCardParams(CardParamsFixture.DEFAULT).toParamMap()) + assertThat(SourceParams.createCardParams(CardParamsFixtures.DEFAULT).toParamMap()) .isEqualTo( mapOf( "type" to "card", diff --git a/stripe/src/test/java/com/stripe/android/model/StripeModelTest.kt b/stripe/src/test/java/com/stripe/android/model/StripeModelTest.kt index 3710c51e7f1..12c109786f1 100644 --- a/stripe/src/test/java/com/stripe/android/model/StripeModelTest.kt +++ b/stripe/src/test/java/com/stripe/android/model/StripeModelTest.kt @@ -1,10 +1,10 @@ package com.stripe.android.model +import com.google.common.truth.Truth.assertThat import com.stripe.android.model.parsers.CardJsonParser +import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertEquals -import kotlin.test.assertNotEquals -import kotlin.test.assertNotNull import kotlin.test.assertNotSame import kotlin.test.assertTrue import org.json.JSONObject @@ -14,10 +14,13 @@ import org.json.JSONObject */ class StripeModelTest { - @Test - fun equals_whenEquals_returnsTrue() { + @BeforeTest + fun setup() { assertTrue(StripeModel::class.java.isAssignableFrom(Card::class.java)) + } + @Test + fun equals_whenEquals_returnsTrue() { val firstCard = parse(CardTest.JSON_CARD_USD) val secondCard = parse(CardTest.JSON_CARD_USD) @@ -28,38 +31,23 @@ class StripeModelTest { @Test fun equals_whenNotEquals_returnsFalse() { - assertTrue(StripeModel::class.java.isAssignableFrom(Card::class.java)) - val firstCard = Card.create("4242", null, null, null) - val secondCard = Card.create("4343", null, null, null) - assertNotEquals(firstCard, secondCard) + assertThat(CardParams("4242", 1, 2021)) + .isNotEqualTo(CardParams("4343", 1, 20201)) } @Test fun hashCode_whenEquals_returnsSameValue() { - assertTrue(StripeModel::class.java.isAssignableFrom(Card::class.java)) - - val firstCard = parse(CardTest.JSON_CARD_USD) - val secondCard = parse(CardTest.JSON_CARD_USD) - assertNotNull(firstCard) - assertNotNull(secondCard) - - assertEquals(firstCard.hashCode(), secondCard.hashCode()) + assertThat(parse(CardTest.JSON_CARD_USD).hashCode()) + .isEqualTo(parse(CardTest.JSON_CARD_USD).hashCode()) } @Test fun hashCode_whenNotEquals_returnsDifferentValues() { - assertTrue(StripeModel::class.java.isAssignableFrom(Card::class.java)) - - val usdCard = CardFixtures.CARD_USD - val eurCard = CardFixtures.CARD_EUR - - assertNotNull(usdCard) - assertNotNull(eurCard) - - assertNotEquals(usdCard.hashCode(), eurCard.hashCode()) + assertThat(CardFixtures.CARD_USD.hashCode()) + .isNotEqualTo(CardFixtures.CARD_EUR.hashCode()) } - private fun parse(json: JSONObject): Card? { + private fun parse(json: JSONObject): Card { return requireNotNull(CardJsonParser().parse(json)) } }