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