|
8 | 8 | import com.unzer.payment.models.CardTransactionData; |
9 | 9 | import com.unzer.payment.paymenttypes.Card; |
10 | 10 | import org.junit.jupiter.api.Disabled; |
| 11 | +import org.junit.jupiter.api.DynamicTest; |
11 | 12 | import org.junit.jupiter.api.Test; |
| 13 | +import org.junit.jupiter.api.TestFactory; |
12 | 14 |
|
13 | 15 | import java.math.BigDecimal; |
| 16 | +import java.util.Collection; |
14 | 17 | import java.util.Currency; |
| 18 | +import java.util.stream.Collectors; |
| 19 | +import java.util.stream.Stream; |
15 | 20 |
|
16 | 21 | import static com.unzer.payment.business.Keys.ALT_LEGACY_PRIVATE_KEY; |
17 | 22 | import static com.unzer.payment.util.Types.unsafeUrl; |
18 | 23 | import static org.junit.jupiter.api.Assertions.*; |
| 24 | +import static org.junit.jupiter.api.DynamicTest.dynamicTest; |
19 | 25 |
|
20 | 26 |
|
21 | 27 | public class CardTest extends AbstractPaymentTest { |
@@ -195,7 +201,7 @@ public void testCardMailInvalidValue() { |
195 | 201 | card.setCvc("123"); |
196 | 202 | card.setEmail(INVALID_MAIL_STRING); |
197 | 203 | try { |
198 | | - card = getUnzer().createPaymentType(card); |
| 204 | + getUnzer().createPaymentType(card); |
199 | 205 | } catch (PaymentException e) { |
200 | 206 | assertNotNull(e.getPaymentErrorList()); |
201 | 207 | assertTrue(e.getPaymentErrorList().size() > 0); |
@@ -447,64 +453,91 @@ public void testAdditionalTransactionData_Liability() { |
447 | 453 | assertEquals(liability, fetchAuthorization.getAdditionalTransactionData().getCard().getLiability()); |
448 | 454 | } |
449 | 455 |
|
450 | | - @Test |
451 | | - public void testCardLowValueExemptionsForAuth() { |
452 | | - Unzer unzer = getUnzer(); |
453 | | - |
454 | | - Card card = unzer.createPaymentType( |
455 | | - new Card(NO_3DS_VISA_CARD_NUMBER, "01/30") |
456 | | - .setCvc("123") |
457 | | - .set3ds(false) |
458 | | - ); |
| 456 | + @TestFactory |
| 457 | + public Collection<DynamicTest> testExemptionTypesForAuth() { |
| 458 | + class TestCase { |
| 459 | + final CardTransactionData.ExemptionType exemptionType; |
459 | 460 |
|
460 | | - Authorization authorization = (Authorization) new Authorization() |
461 | | - .setTypeId(card.getId()) |
462 | | - .setReturnUrl(unsafeUrl("https://unzer.com")) |
463 | | - .setAmount(BigDecimal.TEN) |
464 | | - .setCurrency(Currency.getInstance("EUR")) |
465 | | - .setOrderId("ord-Hi686u4Q4Y") |
466 | | - .setAdditionalTransactionData( |
467 | | - new AdditionalTransactionData() |
468 | | - .setCard( |
469 | | - new CardTransactionData() |
470 | | - .setRecurrenceType(RecurrenceType.UNSCHEDULED) |
471 | | - .setExemptionType(CardTransactionData.ExemptionType.LVP) |
472 | | - ) |
473 | | - ); |
474 | | - authorization = unzer.authorize(authorization); |
| 461 | + public TestCase(CardTransactionData.ExemptionType exemptionType) { |
| 462 | + this.exemptionType = exemptionType; |
| 463 | + } |
| 464 | + } |
475 | 465 |
|
476 | | - Authorization fetchAuthorization = unzer.fetchAuthorization(authorization.getPaymentId()); |
477 | | - assertEquals(CardTransactionData.ExemptionType.LVP, fetchAuthorization.getAdditionalTransactionData().getCard().getExemptionType()); |
| 466 | + return Stream.of( |
| 467 | + new TestCase(CardTransactionData.ExemptionType.LVP), |
| 468 | + new TestCase(CardTransactionData.ExemptionType.TRA) |
| 469 | + ).map(tc -> dynamicTest("exemptionType " + tc.exemptionType, () -> { |
| 470 | + Unzer unzer = getUnzer(); |
| 471 | + |
| 472 | + Card card = unzer.createPaymentType( |
| 473 | + new Card(NO_3DS_VISA_CARD_NUMBER, "01/30") |
| 474 | + .setCvc("123") |
| 475 | + .set3ds(false) |
| 476 | + ); |
| 477 | + |
| 478 | + Authorization authorization = (Authorization) new Authorization() |
| 479 | + .setTypeId(card.getId()) |
| 480 | + .setReturnUrl(unsafeUrl("https://unzer.com")) |
| 481 | + .setAmount(BigDecimal.TEN) |
| 482 | + .setCurrency(Currency.getInstance("EUR")) |
| 483 | + .setOrderId("ord-Hi686u4Q4Y") |
| 484 | + .setAdditionalTransactionData( |
| 485 | + new AdditionalTransactionData() |
| 486 | + .setCard( |
| 487 | + new CardTransactionData() |
| 488 | + .setRecurrenceType(RecurrenceType.UNSCHEDULED) |
| 489 | + .setExemptionType(tc.exemptionType) |
| 490 | + ) |
| 491 | + ); |
| 492 | + authorization = unzer.authorize(authorization); |
| 493 | + |
| 494 | + Authorization fetchAuthorization = unzer.fetchAuthorization(authorization.getPaymentId()); |
| 495 | + assertEquals(tc.exemptionType, fetchAuthorization.getAdditionalTransactionData().getCard().getExemptionType()); |
| 496 | + }) |
| 497 | + ).collect(Collectors.toList()); |
478 | 498 | } |
479 | 499 |
|
480 | | - @Test |
481 | | - public void testCardLowValueExemptionsForCharge() { |
482 | | - Unzer unzer = getUnzer(); |
483 | | - |
484 | | - Card card = unzer.createPaymentType( |
485 | | - new Card(NO_3DS_VISA_CARD_NUMBER, "01/30") |
486 | | - .setCvc("123") |
487 | | - .set3ds(false) |
488 | | - ); |
| 500 | + @TestFactory |
| 501 | + public Collection<DynamicTest> testCardExemptionTypesForCharge() { |
| 502 | + class TestCase { |
| 503 | + final CardTransactionData.ExemptionType exemptionType; |
489 | 504 |
|
490 | | - Charge charge = (Charge) new Charge() |
491 | | - .setTypeId(card.getId()) |
492 | | - .setReturnUrl(unsafeUrl("https://unzer.com")) |
493 | | - .setAmount(BigDecimal.TEN) |
494 | | - .setCurrency(Currency.getInstance("EUR")) |
495 | | - .setOrderId("ord-Hi686u4Q4Y") |
496 | | - .setAdditionalTransactionData( |
497 | | - new AdditionalTransactionData() |
498 | | - .setCard( |
499 | | - new CardTransactionData() |
500 | | - .setRecurrenceType(RecurrenceType.UNSCHEDULED) |
501 | | - .setExemptionType(CardTransactionData.ExemptionType.LVP) |
502 | | - ) |
503 | | - ); |
504 | | - unzer.charge(charge); |
| 505 | + public TestCase(CardTransactionData.ExemptionType exemptionType) { |
| 506 | + this.exemptionType = exemptionType; |
| 507 | + } |
| 508 | + } |
505 | 509 |
|
506 | | - Charge fetchCharge = unzer.fetchCharge(charge.getPaymentId(), "s-chg-1"); |
507 | | - assertEquals(CardTransactionData.ExemptionType.LVP, fetchCharge.getAdditionalTransactionData().getCard().getExemptionType()); |
| 510 | + return Stream.of( |
| 511 | + new TestCase(CardTransactionData.ExemptionType.LVP), |
| 512 | + new TestCase(CardTransactionData.ExemptionType.TRA) |
| 513 | + ).map(tc -> dynamicTest("exemptionType " + tc.exemptionType, () -> { |
| 514 | + Unzer unzer = getUnzer(); |
| 515 | + |
| 516 | + Card card = unzer.createPaymentType( |
| 517 | + new Card(NO_3DS_VISA_CARD_NUMBER, "01/30") |
| 518 | + .setCvc("123") |
| 519 | + .set3ds(false) |
| 520 | + ); |
| 521 | + |
| 522 | + Charge charge = (Charge) new Charge() |
| 523 | + .setTypeId(card.getId()) |
| 524 | + .setReturnUrl(unsafeUrl("https://unzer.com")) |
| 525 | + .setAmount(BigDecimal.TEN) |
| 526 | + .setCurrency(Currency.getInstance("EUR")) |
| 527 | + .setOrderId("ord-Hi686u4Q4Y") |
| 528 | + .setAdditionalTransactionData( |
| 529 | + new AdditionalTransactionData() |
| 530 | + .setCard( |
| 531 | + new CardTransactionData() |
| 532 | + .setRecurrenceType(RecurrenceType.UNSCHEDULED) |
| 533 | + .setExemptionType(tc.exemptionType) |
| 534 | + ) |
| 535 | + ); |
| 536 | + unzer.charge(charge); |
| 537 | + |
| 538 | + Charge fetchCharge = unzer.fetchCharge(charge.getPaymentId(), "s-chg-1"); |
| 539 | + assertEquals(tc.exemptionType, fetchCharge.getAdditionalTransactionData().getCard().getExemptionType()); |
| 540 | + }) |
| 541 | + ).collect(Collectors.toList()); |
508 | 542 | } |
509 | | - |
510 | 543 | } |
0 commit comments