Skip to content

Commit a3ac136

Browse files
Leah ZhaoLeah Zhao
authored andcommitted
adding unittests for Capture.java and Restaurant.java
1 parent af51b32 commit a3ac136

File tree

2 files changed

+149
-0
lines changed

2 files changed

+149
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.intuit.payment.data;
2+
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
3+
import org.testng.Assert;
4+
import org.testng.annotations.BeforeMethod;
5+
import org.testng.annotations.BeforeTest;
6+
import org.testng.annotations.Test;
7+
8+
import java.math.BigDecimal;
9+
import java.util.Date;
10+
11+
/**
12+
* @author wontonswaggie
13+
*/
14+
public class CaptureTest {
15+
private Date created;
16+
private BigDecimal amount;
17+
private PaymentContext context;
18+
private String description;
19+
private Capture capture;
20+
21+
@BeforeTest
22+
public void init() {
23+
created = new Date();
24+
amount = new BigDecimal(20.00);
25+
context = new PaymentContext();
26+
description = "this is a capture test";
27+
}
28+
29+
@BeforeMethod
30+
public void setUp() {
31+
capture = new Capture.Builder()
32+
.created(created)
33+
.amount(amount)
34+
.context(context)
35+
.description(description)
36+
.build();
37+
}
38+
39+
@Test
40+
public void testAllGetters() {
41+
Assert.assertEquals(capture.getCreated(), created);
42+
Assert.assertEquals(capture.getAmount(), amount);
43+
Assert.assertEquals(capture.getContext(), context);
44+
Assert.assertEquals(capture.getDescription(), description);
45+
}
46+
47+
@Test
48+
public void testAllSetters() {
49+
Date newCreated = new Date();
50+
BigDecimal newAmount = new BigDecimal(30.00);
51+
PaymentContext newContext = new PaymentContext();
52+
String newDescription = "this is a new capture test";
53+
54+
capture.setCreated(newCreated);
55+
capture.setAmount(newAmount);
56+
capture.setContext(newContext);
57+
capture.setDescription(newDescription);
58+
59+
Assert.assertEquals(capture.getCreated(), newCreated);
60+
Assert.assertEquals(capture.getAmount(), newAmount);
61+
Assert.assertEquals(capture.getContext(), newContext);
62+
Assert.assertEquals(capture.getDescription(), newDescription);
63+
}
64+
65+
@Test
66+
public void testToString() {
67+
String expectedResult = ReflectionToStringBuilder.toString(capture);
68+
String actualResult = capture.toString();
69+
Assert.assertTrue(actualResult.contains(expectedResult));
70+
}
71+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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 wontonswaggie
13+
*/
14+
public class RestaurantTest {
15+
private String serverID;
16+
private BigDecimal foodAmount;
17+
private BigDecimal beverageAmount;
18+
private BigDecimal taxAmount;
19+
private BigDecimal tipAmount;
20+
private Restaurant restaurant;
21+
22+
@BeforeTest
23+
public void init() {
24+
serverID = "1234";
25+
foodAmount = new BigDecimal(100);
26+
beverageAmount = new BigDecimal(50);
27+
taxAmount = new BigDecimal(0.08);
28+
tipAmount = new BigDecimal(3);
29+
}
30+
31+
@BeforeMethod
32+
public void setUp() {
33+
restaurant = new Restaurant.Builder()
34+
.serverID(serverID)
35+
.foodAmount(foodAmount)
36+
.beverageAmount(beverageAmount)
37+
.taxAmount(taxAmount)
38+
.tipAmount(tipAmount)
39+
.build();
40+
}
41+
42+
@Test
43+
public void testAllGetters() {
44+
Assert.assertEquals(restaurant.getServerID(), serverID);
45+
Assert.assertEquals(restaurant.getFoodAmount(), foodAmount);
46+
Assert.assertEquals(restaurant.getBeverageAmount(), beverageAmount);
47+
Assert.assertEquals(restaurant.getTaxAmount(), taxAmount);
48+
Assert.assertEquals(restaurant.getTipAmount(), tipAmount);
49+
}
50+
51+
@Test
52+
public void testAllSetters() {
53+
String newServerID = "5678";
54+
BigDecimal newFoodAmount = new BigDecimal(200);
55+
BigDecimal newBeverageAmount = new BigDecimal(250);
56+
BigDecimal newTaxAmount = new BigDecimal(2.08);
57+
BigDecimal newTipAmount = new BigDecimal(23);
58+
59+
restaurant.setServerID(newServerID);
60+
restaurant.setFoodAmount(newFoodAmount);
61+
restaurant.setBeverageAmount(newBeverageAmount);
62+
restaurant.setTaxAmount(newTaxAmount);
63+
restaurant.setTipAmount(newTipAmount);
64+
65+
Assert.assertEquals(restaurant.getServerID(), newServerID);
66+
Assert.assertEquals(restaurant.getFoodAmount(), newFoodAmount);
67+
Assert.assertEquals(restaurant.getBeverageAmount(), newBeverageAmount);
68+
Assert.assertEquals(restaurant.getTaxAmount(), newTaxAmount);
69+
Assert.assertEquals(restaurant.getTipAmount(), newTipAmount);
70+
}
71+
72+
@Test
73+
public void testToString() {
74+
String expectedResult = ReflectionToStringBuilder.toString(restaurant);
75+
String actualResult = restaurant.toString();
76+
Assert.assertTrue(actualResult.contains(expectedResult));
77+
}
78+
}

0 commit comments

Comments
 (0)