|
| 1 | +package com.intuit.payment.data; |
| 2 | + |
| 3 | +import org.apache.commons.lang.builder.ReflectionToStringBuilder; |
| 4 | +import org.testng.Assert; |
| 5 | +import org.testng.annotations.BeforeMethod; |
| 6 | +import org.testng.annotations.BeforeTest; |
| 7 | +import org.testng.annotations.Test; |
| 8 | + |
| 9 | +import java.math.BigDecimal; |
| 10 | + |
| 11 | +public class PaymentContextTest { |
| 12 | + private BigDecimal tax; |
| 13 | + private DeviceInfo deviceInfo; |
| 14 | + private Boolean recurring; |
| 15 | + private String mobile; |
| 16 | + private String isEcommerce; |
| 17 | + private Lodging lodging; |
| 18 | + private Restaurant restaurant; |
| 19 | + private PaymentContext paymentContext; |
| 20 | + |
| 21 | + @BeforeTest |
| 22 | + public void init() { |
| 23 | + tax = new BigDecimal(20.00); |
| 24 | + deviceInfo = new DeviceInfo(); |
| 25 | + recurring = true; |
| 26 | + mobile = "android"; |
| 27 | + isEcommerce = "ecommerce"; |
| 28 | + lodging = new Lodging(); |
| 29 | + restaurant = new Restaurant(); |
| 30 | + } |
| 31 | + |
| 32 | + @BeforeMethod |
| 33 | + public void setUp() { |
| 34 | + paymentContext = new PaymentContext.Builder() |
| 35 | + .tax(tax) |
| 36 | + .deviceInfo(deviceInfo) |
| 37 | + .recurring(recurring) |
| 38 | + .mobile(mobile) |
| 39 | + .isEcommerce(isEcommerce) |
| 40 | + .lodging(lodging) |
| 41 | + .restaurant(restaurant) |
| 42 | + .build(); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + public void testAllGetters() { |
| 47 | + Assert.assertEquals(paymentContext.getTax(), tax); |
| 48 | + Assert.assertEquals(paymentContext.getDeviceInfo(), deviceInfo); |
| 49 | + Assert.assertEquals(paymentContext.getRecurring(), recurring); |
| 50 | + Assert.assertEquals(paymentContext.getMobile(), mobile); |
| 51 | + Assert.assertEquals(paymentContext.getIsEcommerce(), isEcommerce); |
| 52 | + Assert.assertEquals(paymentContext.getLodging(), lodging); |
| 53 | + Assert.assertEquals(paymentContext.getRestaurant(), restaurant); |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + public void testAllSetters() { |
| 58 | + BigDecimal newTax = new BigDecimal(40.00); |
| 59 | + DeviceInfo newDeviceInfo = new DeviceInfo(); |
| 60 | + Boolean newRecurring = true; |
| 61 | + String newMobile = "ios"; |
| 62 | + String newIsEcommerce = "new ecommerce"; |
| 63 | + Lodging newLodging = new Lodging(); |
| 64 | + Restaurant newRestaurant = new Restaurant(); |
| 65 | + |
| 66 | + paymentContext.setTax(newTax); |
| 67 | + paymentContext.setDeviceInfo(newDeviceInfo); |
| 68 | + paymentContext.setRecurring(newRecurring); |
| 69 | + paymentContext.setMobile(newMobile); |
| 70 | + paymentContext.setIsEcommerce(newIsEcommerce); |
| 71 | + paymentContext.setLodging(newLodging); |
| 72 | + paymentContext.setRestaurant(newRestaurant); |
| 73 | + |
| 74 | + Assert.assertEquals(paymentContext.getTax(), newTax); |
| 75 | + Assert.assertEquals(paymentContext.getDeviceInfo(), newDeviceInfo); |
| 76 | + Assert.assertEquals(paymentContext.getRecurring(), newRecurring); |
| 77 | + Assert.assertEquals(paymentContext.getMobile(), newMobile); |
| 78 | + Assert.assertEquals(paymentContext.getIsEcommerce(), newIsEcommerce); |
| 79 | + Assert.assertEquals(paymentContext.getLodging(), newLodging); |
| 80 | + Assert.assertEquals(paymentContext.getRestaurant(), newRestaurant); |
| 81 | + } |
| 82 | + |
| 83 | + @Test |
| 84 | + public void testToString() { |
| 85 | + String expectedResult = ReflectionToStringBuilder.toString(paymentContext); |
| 86 | + String actualResult = paymentContext.toString(); |
| 87 | + Assert.assertTrue(actualResult.contains(expectedResult)); |
| 88 | + } |
| 89 | +} |
0 commit comments