|
| 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