-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCustomerTests07.java
70 lines (65 loc) · 2.25 KB
/
CustomerTests07.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* $
*
* Copyright (C) 2019 Cefalo AS.
* All Rights Reserved. No use, copying or distribution of this
* work may be made except in accordance with a valid license
* agreement from Cefalo AS. This notice must be included on all
* copies, modifications and derivatives of this work.
*/
package com.cefalo.tdd;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* @author <a href="mailto:[email protected]">Ferdous Mahmud Shaon</a>
* @author last modified by $
* @version $ $
*/
public class CustomerTests07 {
/*
* Customer has following properties:
* Name: name of the customer, String, Mandatory
*
* RewardPoints: the total reward points of a customer, default value: 0, integer
* value can only be set >=0, otherwise throws IllegalArgumentException
*
* purchaseGoods(int amount): increase the total RewardPoints count based on the following formula:
* total RewardPoints count += ceil(amount * 0.1)
* the amount cannot be <0, otherwise throw IllegalArgumentException
*
* redeemPoints(int points): decrease the total RewardPoints count by the given number of points
* if the given number of points < total RewardPoints count
* otherwise throw IllegalArgumentException
*
* */
private Customer customer;
@BeforeEach
public void setUpCustomer() {
customer = new Customer("Arnab");
}
@Test
public void testCustomerWithNameOnly() {
assertEquals("Arnab", customer.getName());
}
@Test
public void testCustomerWithRewardPoints() {
customer.setRewardPoints(100);
assertEquals(100, customer.getRewardPoints());
}
@Test
public void testCustomerWithDefaultRewardPoints() {
assertEquals(0, customer.getRewardPoints());
}
@Test
public void testCustomerWithNegativeRewardPoints() {
assertThrows(IllegalArgumentException.class, () -> customer.setRewardPoints(-10));
}
@Test
public void testCustomerWithPurchaseGoods() {
customer.setRewardPoints(100);
customer.purchaseGoods(200);
assertEquals(120,customer.getRewardPoints());
}
}