Skip to content

Commit c01a6e9

Browse files
jackykcJacky Chung
authored andcommitted
added unit test for device info data model
1 parent c701c7e commit c01a6e9

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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+
/**
10+
* @author jackykc
11+
*/
12+
public class DeviceInfoTest {
13+
14+
private String id;
15+
private String type;
16+
private String longitude;
17+
private String latitude;
18+
private Boolean encrypted;
19+
private String phoneNumber;
20+
private String macAddress;
21+
private String ipAddress;
22+
23+
private DeviceInfo deviceInfo;
24+
25+
@BeforeTest
26+
public void init() {
27+
id = "id";
28+
type = "type";
29+
longitude = "longitude";
30+
latitude = "latitude";
31+
encrypted = false;
32+
phoneNumber = "5871231234";
33+
macAddress = "00-11-11-11-11-11";
34+
ipAddress = "192.168.0.0";
35+
}
36+
37+
@BeforeMethod
38+
public void setUp() {
39+
deviceInfo = new DeviceInfo.Builder()
40+
.id(id)
41+
.type(type)
42+
.longitude(longitude)
43+
.latitude(latitude)
44+
.encrypted(encrypted)
45+
.phoneNumber(phoneNumber)
46+
.macAddress(macAddress)
47+
.ipAddress(ipAddress)
48+
.build();
49+
}
50+
51+
@Test
52+
public void testAllGetters() {
53+
Assert.assertEquals(deviceInfo.getId(), id);
54+
Assert.assertEquals(deviceInfo.getType(), type);
55+
Assert.assertEquals(deviceInfo.getLongitude(), longitude);
56+
Assert.assertEquals(deviceInfo.getLatitude(), latitude);
57+
Assert.assertEquals(deviceInfo.getEncrypted(), encrypted);
58+
Assert.assertEquals(deviceInfo.getPhoneNumber(), phoneNumber);
59+
Assert.assertEquals(deviceInfo.getMacAddress(), macAddress);
60+
Assert.assertEquals(deviceInfo.getIpAddress(), ipAddress);
61+
}
62+
63+
@Test
64+
public void testAllSetters() {
65+
String newId = "new id";
66+
String newType = "new type";
67+
String newLongitude = "new longitude";
68+
String newLatitude = "new latitude";
69+
Boolean newEncrypted = true;
70+
String newPhoneNumber = "7801231234";
71+
String newMacAddress = "00-12-12-12-12-12";
72+
String newIpAddress = "255.168.0.0";
73+
74+
deviceInfo.setId(newId);
75+
deviceInfo.setType(newType);
76+
deviceInfo.setLongitude(newLongitude);
77+
deviceInfo.setLatitude(newLatitude);
78+
deviceInfo.setEncrypted(newEncrypted);
79+
deviceInfo.setPhoneNumber(newPhoneNumber);
80+
deviceInfo.setMacAddress(newMacAddress);
81+
deviceInfo.setIpAddress(newIpAddress);
82+
83+
Assert.assertEquals(deviceInfo.getId(), newId);
84+
Assert.assertEquals(deviceInfo.getType(), newType);
85+
Assert.assertEquals(deviceInfo.getLongitude(), newLongitude);
86+
Assert.assertEquals(deviceInfo.getLatitude(), newLatitude);
87+
Assert.assertEquals(deviceInfo.getEncrypted(), newEncrypted);
88+
Assert.assertEquals(deviceInfo.getPhoneNumber(), newPhoneNumber);
89+
Assert.assertEquals(deviceInfo.getMacAddress(), newMacAddress);
90+
Assert.assertEquals(deviceInfo.getIpAddress(), newIpAddress);
91+
}
92+
93+
@Test
94+
public void testToString() {
95+
// Since we cant mock ReflectionToStringBuilder without powermock
96+
String expectedResult = ReflectionToStringBuilder.toString(deviceInfo);
97+
String actualResult = deviceInfo.toString();
98+
Assert.assertTrue(actualResult.contains(expectedResult));
99+
}
100+
}

0 commit comments

Comments
 (0)