|
| 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 | +/** |
| 12 | + * @author rnair |
| 13 | + */ |
| 14 | +public class PaymentContextTest { |
| 15 | + |
| 16 | + private BigDecimal tax; |
| 17 | + private DeviceInfo deviceInfo; |
| 18 | + private Boolean recurring; |
| 19 | + private String mobile; |
| 20 | + private String isEcommerce; |
| 21 | + private Lodging lodging; |
| 22 | + private Restaurant restaurant; |
| 23 | + |
| 24 | + private PaymentContext paymentContext; |
| 25 | + |
| 26 | + @BeforeTest |
| 27 | + public void init() { |
| 28 | + tax = new BigDecimal(567.56); |
| 29 | + deviceInfo = new DeviceInfo(); |
| 30 | + recurring = false; |
| 31 | + mobile = "mobile"; |
| 32 | + isEcommerce = "false"; |
| 33 | + lodging = new Lodging(); |
| 34 | + restaurant = new Restaurant(); |
| 35 | + } |
| 36 | + |
| 37 | + @BeforeMethod |
| 38 | + public void setUp() { |
| 39 | + paymentContext = new PaymentContext.Builder() |
| 40 | + .tax(tax) |
| 41 | + .deviceInfo(deviceInfo) |
| 42 | + .recurring(recurring) |
| 43 | + .mobile(mobile) |
| 44 | + .isEcommerce(isEcommerce) |
| 45 | + .lodging(lodging) |
| 46 | + .restaurant(restaurant) |
| 47 | + .build(); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + public void testAllGetters() { |
| 52 | + Assert.assertEquals(paymentContext.getTax(), tax); |
| 53 | + Assert.assertEquals(paymentContext.getDeviceInfo(), deviceInfo); |
| 54 | + Assert.assertEquals(paymentContext.getRecurring(), recurring); |
| 55 | + Assert.assertEquals(paymentContext.getIsEcommerce(), isEcommerce); |
| 56 | + Assert.assertEquals(paymentContext.getMobile(), mobile); |
| 57 | + Assert.assertEquals(paymentContext.getLodging(), lodging); |
| 58 | + Assert.assertEquals(paymentContext.getRestaurant(), restaurant); |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + public void testAllSetters() { |
| 63 | + BigDecimal updatedTax = new BigDecimal(4545.67); |
| 64 | + DeviceInfo updatedDeviceInfo = new DeviceInfo(); |
| 65 | + Boolean udpatedRecurring = true; |
| 66 | + String udpatedMobile = "updated mobile"; |
| 67 | + String udpatedIsECommerce = "true"; |
| 68 | + Lodging udpatedLodging = new Lodging(); |
| 69 | + Restaurant udpatedRestaurant = new Restaurant(); |
| 70 | + |
| 71 | + paymentContext.setTax(updatedTax); |
| 72 | + paymentContext.setDeviceInfo(updatedDeviceInfo); |
| 73 | + paymentContext.setRecurring(udpatedRecurring); |
| 74 | + paymentContext.setMobile(udpatedMobile); |
| 75 | + paymentContext.setIsEcommerce(udpatedIsECommerce); |
| 76 | + paymentContext.setLodging(udpatedLodging); |
| 77 | + paymentContext.setRestaurant(udpatedRestaurant); |
| 78 | + |
| 79 | + Assert.assertEquals(paymentContext.getTax(), updatedTax); |
| 80 | + Assert.assertEquals(paymentContext.getDeviceInfo(), updatedDeviceInfo); |
| 81 | + Assert.assertEquals(paymentContext.getRecurring(), udpatedRecurring); |
| 82 | + Assert.assertEquals(paymentContext.getIsEcommerce(), udpatedIsECommerce); |
| 83 | + Assert.assertEquals(paymentContext.getMobile(), udpatedMobile); |
| 84 | + Assert.assertEquals(paymentContext.getLodging(), udpatedLodging); |
| 85 | + Assert.assertEquals(paymentContext.getRestaurant(), udpatedRestaurant); |
| 86 | + } |
| 87 | + |
| 88 | + @Test |
| 89 | + public void testToString() { |
| 90 | + String expectedResult = ReflectionToStringBuilder.toString(paymentContext); |
| 91 | + String actualResult = paymentContext.toString(); |
| 92 | + Assert.assertTrue(actualResult.contains(expectedResult)); |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | + |
| 97 | + |
0 commit comments