|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2019 Intuit |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + *******************************************************************************/ |
| 16 | +package com.intuit.payment.data; |
| 17 | + |
| 18 | +import com.intuit.payment.data.Charge.ChargeStatus; |
| 19 | +import org.apache.commons.lang.builder.ReflectionToStringBuilder; |
| 20 | +import org.testng.Assert; |
| 21 | +import org.testng.annotations.BeforeMethod; |
| 22 | +import org.testng.annotations.BeforeTest; |
| 23 | +import org.testng.annotations.Test; |
| 24 | + |
| 25 | +import java.math.BigDecimal; |
| 26 | +import java.util.Date; |
| 27 | + |
| 28 | +public class ChargeTest { |
| 29 | + |
| 30 | + private String id; |
| 31 | + private Date created; |
| 32 | + private ChargeStatus status; |
| 33 | + private BigDecimal amount; |
| 34 | + private String currency; |
| 35 | + private String token; |
| 36 | + private Card card; |
| 37 | + private PaymentContext context; |
| 38 | + private Boolean capture; |
| 39 | + private String authCode; |
| 40 | + private Capture captureDetail; |
| 41 | + private Refund[] refundDetail; |
| 42 | + private String description; |
| 43 | + private String avsStreet; |
| 44 | + private String avsZip; |
| 45 | + private String cardSecurityCodeMatch; |
| 46 | + private String appType; |
| 47 | + private String cardOnFile; |
| 48 | + |
| 49 | + private Charge charge; |
| 50 | + |
| 51 | + @BeforeTest |
| 52 | + public void init() { |
| 53 | + id = "id"; |
| 54 | + created = new Date(1572473285); |
| 55 | + status = ChargeStatus.AUTHORIZED; |
| 56 | + amount = new BigDecimal(1); |
| 57 | + currency = "money"; |
| 58 | + token = "token"; |
| 59 | + card = new Card(); |
| 60 | + context = new PaymentContext(); |
| 61 | + capture = false; |
| 62 | + authCode = "123456"; |
| 63 | + captureDetail = new Capture(); |
| 64 | + refundDetail = new Refund[]{new Refund()}; |
| 65 | + description = "description"; |
| 66 | + avsStreet = "avsStreet"; |
| 67 | + avsZip = "avsZip"; |
| 68 | + cardSecurityCodeMatch = "cardSecurityCodeMatch"; |
| 69 | + appType = "appType"; |
| 70 | + cardOnFile = "cardOnFile"; |
| 71 | + } |
| 72 | + |
| 73 | + @BeforeMethod |
| 74 | + public void setUpWithBuilder() { |
| 75 | + charge = new Charge.Builder() |
| 76 | + .id(id) |
| 77 | + .created(created) |
| 78 | + .status(status) |
| 79 | + .amount(amount) |
| 80 | + .currency(currency) |
| 81 | + .token(token) |
| 82 | + .card(card) |
| 83 | + .context(context) |
| 84 | + .capture(capture) |
| 85 | + .authCode(authCode) |
| 86 | + .captureDetail(captureDetail) |
| 87 | + .refundDetail(refundDetail) |
| 88 | + .description(description) |
| 89 | + .avsStreet(avsStreet) |
| 90 | + .avsZip(avsZip) |
| 91 | + .cardSecurityCodeMatch(cardSecurityCodeMatch) |
| 92 | + .appType(appType) |
| 93 | + .cardOnFile(cardOnFile) |
| 94 | + .build(); |
| 95 | + } |
| 96 | + |
| 97 | + @Test |
| 98 | + public void testConstructor() { |
| 99 | + charge = new Charge(); |
| 100 | + Assert.assertNotNull(charge); |
| 101 | + } |
| 102 | + |
| 103 | + @Test |
| 104 | + public void testAllGetters() { |
| 105 | + Assert.assertEquals(charge.getId(), id); |
| 106 | + Assert.assertEquals(charge.getCreated(), created); |
| 107 | + Assert.assertEquals(charge.getStatus(), status); |
| 108 | + Assert.assertEquals(charge.getAmount(), amount); |
| 109 | + Assert.assertEquals(charge.getCurrency(), currency); |
| 110 | + Assert.assertEquals(charge.getToken(), token); |
| 111 | + Assert.assertEquals(charge.getCard(), card); |
| 112 | + Assert.assertEquals(charge.getContext(), context); |
| 113 | + Assert.assertEquals(charge.getCapture(), capture); |
| 114 | + Assert.assertEquals(charge.getAuthCode(), authCode); |
| 115 | + Assert.assertEquals(charge.getCaptureDetail(), captureDetail); |
| 116 | + Assert.assertEquals(charge.getRefundDetail(), refundDetail); |
| 117 | + Assert.assertEquals(charge.getDescription(), description); |
| 118 | + Assert.assertEquals(charge.getAvsStreet(), avsStreet); |
| 119 | + Assert.assertEquals(charge.getAvsZip(), avsZip); |
| 120 | + Assert.assertEquals(charge.getCardSecurityCodeMatch(), cardSecurityCodeMatch); |
| 121 | + Assert.assertEquals(charge.getAppType(), appType); |
| 122 | + Assert.assertEquals(charge.getCardOnFile(), cardOnFile); |
| 123 | + } |
| 124 | + |
| 125 | + @Test |
| 126 | + public void testAllSetters() { |
| 127 | + String newId = "id"; |
| 128 | + Date newCreated = new Date(1572473285); |
| 129 | + ChargeStatus newStatus = ChargeStatus.AUTHORIZED; |
| 130 | + BigDecimal newAmount = new BigDecimal(1); |
| 131 | + String newCurrency = "money"; |
| 132 | + String newToken = "token"; |
| 133 | + Card newCard = new Card(); |
| 134 | + PaymentContext newContext = new PaymentContext(); |
| 135 | + Boolean newCapture = false; |
| 136 | + String newAuthCode = "123456"; |
| 137 | + Capture newCaptureDetail = new Capture(); |
| 138 | + Refund[] newRefundDetail = new Refund[]{new Refund()}; |
| 139 | + String newDescription = "description"; |
| 140 | + String newAvsStreet = "avsStreet"; |
| 141 | + String newAvsZip = "avsZip"; |
| 142 | + String newCardSecurityCodeMatch = "cardSecurityCodeMatch"; |
| 143 | + String newAppType = "appType"; |
| 144 | + String newCardOnFile = "cardOnFile"; |
| 145 | + |
| 146 | + charge.setId(newId); |
| 147 | + charge.setCreated(newCreated); |
| 148 | + charge.setStatus(newStatus); |
| 149 | + charge.setAmount(newAmount); |
| 150 | + charge.setCurrency(newCurrency); |
| 151 | + charge.setToken(newToken); |
| 152 | + charge.setCard(newCard); |
| 153 | + charge.setContext(newContext); |
| 154 | + charge.setCapture(newCapture); |
| 155 | + charge.setAuthCode(newAuthCode); |
| 156 | + charge.setCaptureDetail(newCaptureDetail); |
| 157 | + charge.setRefundDetail(newRefundDetail); |
| 158 | + charge.setDescription(newDescription); |
| 159 | + charge.setAvsStreet(newAvsStreet); |
| 160 | + charge.setAvsZip(newAvsZip); |
| 161 | + charge.setCardSecurityCodeMatch(newCardSecurityCodeMatch); |
| 162 | + charge.setAppType(newAppType); |
| 163 | + charge.setCardOnFile(newCardOnFile); |
| 164 | + |
| 165 | + Assert.assertEquals(charge.getId(), newId); |
| 166 | + Assert.assertEquals(charge.getCreated(), newCreated); |
| 167 | + Assert.assertEquals(charge.getStatus(), newStatus); |
| 168 | + Assert.assertEquals(charge.getAmount(), newAmount); |
| 169 | + Assert.assertEquals(charge.getCurrency(), newCurrency); |
| 170 | + Assert.assertEquals(charge.getToken(), newToken); |
| 171 | + Assert.assertEquals(charge.getCard(), newCard); |
| 172 | + Assert.assertEquals(charge.getContext(), newContext); |
| 173 | + Assert.assertEquals(charge.getCapture(), newCapture); |
| 174 | + Assert.assertEquals(charge.getAuthCode(), newAuthCode); |
| 175 | + Assert.assertEquals(charge.getCaptureDetail(), newCaptureDetail); |
| 176 | + Assert.assertEquals(charge.getRefundDetail(), newRefundDetail); |
| 177 | + Assert.assertEquals(charge.getDescription(), newDescription); |
| 178 | + Assert.assertEquals(charge.getAvsStreet(), newAvsStreet); |
| 179 | + Assert.assertEquals(charge.getAvsZip(), newAvsZip); |
| 180 | + Assert.assertEquals(charge.getCardSecurityCodeMatch(), newCardSecurityCodeMatch); |
| 181 | + Assert.assertEquals(charge.getAppType(), newAppType); |
| 182 | + Assert.assertEquals(charge.getCardOnFile(), newCardOnFile); |
| 183 | + } |
| 184 | + |
| 185 | + @Test |
| 186 | + public void testToString() { |
| 187 | + String expectedResult = ReflectionToStringBuilder.toString(charge); |
| 188 | + String actualResult = charge.toString(); |
| 189 | + Assert.assertTrue(actualResult.contains(expectedResult)); |
| 190 | + } |
| 191 | +} |
0 commit comments