/
PaydayTransactionTest.java
226 lines (210 loc) · 9.21 KB
/
PaydayTransactionTest.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
package payday;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import payday.employee.affiliation.command.ChangeAffiliatedTransaction;
import payday.employee.affiliation.command.ServiceChargeTransaction;
import payday.employee.classification.command.TimeCardTransaction;
import payday.employee.command.AddHourlyEmployee;
import payday.employee.command.AddSalariedEmployee;
import java.util.Calendar;
import java.util.Date;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
/**
* @author myeongju.jung
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@Transactional
public class PaydayTransactionTest {
@Test
public void testPaySingleSalariedEmployee() throws Exception {
// given
final Integer empId = 1;
final double salary = 1000.00;
new AddSalariedEmployee(empId, "Bob", "Home", salary).execute();
Date payDate = getDate(2001, Calendar.NOVEMBER, 30);
// when
PaydayTransaction pt = new PaydayTransaction(payDate);
pt.execute();
// then
Paycheck pc = pt.getPaycheck(empId);
assertPaycheck(pc, salary, 0.0, salary, "Hold");
}
@SuppressWarnings("SameParameterValue")
private void assertPaycheck(Paycheck pc, double grossPay, double deductions, double netPay, String disposition) {
assertThat(pc, is(notNullValue()));
assertThat(pc.getGrossPay(), is(grossPay));
assertThat(pc.getDeductions(), is(deductions));
assertThat(pc.getNetPay(), is(netPay));
assertThat(pc.getField("Disposition"), is(disposition));
}
@SuppressWarnings("SameParameterValue")
private Date getDate(int year, int month, int date) {
Calendar payCalendar = Calendar.getInstance();
payCalendar.set(year, month, date);
return payCalendar.getTime();
}
@Test
public void testPaySingleSalariedEmployeeOnWrongDate() throws Exception {
final Integer empId = 1;
final double salary = 1000.00;
new AddSalariedEmployee(empId, "Bob", "Home", salary).execute();
Date payDate = getDate(2001, Calendar.NOVEMBER, 29);
// when
PaydayTransaction pt = new PaydayTransaction(payDate);
pt.execute();
// then
Paycheck pc = pt.getPaycheck(empId);
assertThat(pc, is(nullValue()));
}
@Test
public void testPaySalariedUnionMemberDues() throws Exception {
// given
final Integer empId = 1;
final double salary = 1000.00;
new AddSalariedEmployee(empId, "Bob", "Home", salary).execute();
final double dues = 9.42;
new ChangeAffiliatedTransaction(empId, dues).execute();
Date payDate = getDate(2001, Calendar.NOVEMBER, 30);
// when
PaydayTransaction pt = new PaydayTransaction(payDate);
pt.execute();
// then
Paycheck pc = pt.getPaycheck(empId);
final double deductions = dues * 5; // 조합비 * 주 (해당 월은 금요일이 5번)
assertPaycheck(pc, salary, deductions, salary - deductions, "Hold");
}
@Test
public void testPaySingleHourlyEmployeeNoTimeCards() throws Exception {
// given
final Integer empId = 2;
new AddHourlyEmployee(empId, "Bill", "Home", 15.25).execute();
Date payDate = getDate(2017, Calendar.JULY, 7); // 금요일
// when
PaydayTransaction pt = new PaydayTransaction(payDate);
pt.execute();
// then
Paycheck pc = pt.getPaycheck(empId);
assertPaycheck(pc, 0.0, 0.0, 0.0, "Hold");
}
@Test
public void testPaySingleHourlyEmployeeOneTimeCard() throws Exception {
// given
final Integer empId = 2;
final double hourlyWage = 15.25; // 시간당 급여
new AddHourlyEmployee(empId, "Bill", "Home", hourlyWage).execute();
Date payDate = getDate(2017, Calendar.JULY, 7); // 금요일
double hours = 2.0; // 일한 시간
new TimeCardTransaction(payDate.getTime(), hours, empId).execute();
// when
PaydayTransaction pt = new PaydayTransaction(payDate);
pt.execute();
// then
Paycheck pc = pt.getPaycheck(empId);
final double pay = hourlyWage * hours; // 급여 = 시간당 급여 * 일한 시간
assertPaycheck(pc, pay, 0.0, pay, "Hold");
}
@Test
public void testPaySingleHourlyEmployeeOnWrongDate() throws Exception {
// given
final Integer empId = 2;
final double hourlyWage = 15.25; // 시간당 급여
new AddHourlyEmployee(empId, "Bill", "Home", hourlyWage).execute();
Date payDate = getDate(2017, Calendar.JULY, 6); // 목요일
double hours = 9.0; // 일한 시간
new TimeCardTransaction(payDate.getTime(), hours, empId).execute();
// when
PaydayTransaction pt = new PaydayTransaction(payDate);
pt.execute();
// then
Paycheck pc = pt.getPaycheck(empId);
assertThat(pc, is(nullValue()));
}
@Test
public void testPaySingleHourlyEmployeeTwoTimeCards() throws Exception {
// given
final Integer empId = 2;
final double hourlyWage = 15.25; // 시간당 급여
new AddHourlyEmployee(empId, "Bill", "Home", hourlyWage).execute();
Date payDate = getDate(2017, Calendar.JULY, 7); // 금요일
final double hours = 2.0; // 일한 시간1
new TimeCardTransaction(payDate.getTime(), hours, empId).execute();
final double hours2 = 5.0;
new TimeCardTransaction(getDate(2017, Calendar.JULY, 6).getTime(), hours2, empId).execute();
// when
PaydayTransaction pt = new PaydayTransaction(payDate);
pt.execute();
// then
Paycheck pc = pt.getPaycheck(empId);
final double pay = hourlyWage * (hours + hours2); // 급여 = 시간당 급여 * 일한 시간
assertPaycheck(pc, pay, 0.0, pay, "Hold");
}
@Test
public void testPaySingleHourlyEmployeeWithTimeCardsSpanningTwoPayPeriods() throws Exception {
// given
final Integer empId = 2;
final double hourlyWage = 15.25; // 시간당 급여
new AddHourlyEmployee(empId, "Bill", "Home", hourlyWage).execute();
Date payDate = getDate(2017, Calendar.JULY, 14); // 금요일
final double hours = 2.0; // 일한 시간1
new TimeCardTransaction(payDate.getTime(), hours, empId).execute();
final double hours2 = 5.0;
new TimeCardTransaction(getDate(2017, Calendar.JULY, 7).getTime(), hours2, empId).execute(); // 이전 기간에 일한 것 : 제외 대상
// when
PaydayTransaction pt = new PaydayTransaction(payDate);
pt.execute();
// then
Paycheck pc = pt.getPaycheck(empId);
final double pay = hourlyWage * hours; // 급여 = 시간당 급여 * 일한 시간
assertPaycheck(pc, pay, 0.0, pay, "Hold");
}
@Test
public void testPayHourlyUnionMemberServiceCharge() throws Exception {
// given
final Integer empId = 1;
final double hourlyWage = 15.24;
new AddHourlyEmployee(empId, "Bill", "Home", hourlyWage).execute();
double dues = 9.42;
new ChangeAffiliatedTransaction(empId, dues).execute();
Date payDate = getDate(2001, Calendar.NOVEMBER, 9);
final double charge = 19.42;
new ServiceChargeTransaction(empId, payDate.getTime(), charge).execute();
final double hours = 8.0;
new TimeCardTransaction(payDate.getTime(), hours, empId).execute();
// when
PaydayTransaction pt = new PaydayTransaction(payDate);
pt.execute();
// then
Paycheck pc = pt.getPaycheck(empId);
assertPaycheck(pc, hourlyWage * hours, dues + charge, (hourlyWage * hours) - (dues + charge), "Hold");
}
@Test
public void testServiceChargesSpanningMultiplePayPeriods() throws Exception {
// given
final Integer empId = 1;
final double hourlyWage = 15.24;
new AddHourlyEmployee(empId, "Bill", "Home", hourlyWage).execute();
double dues = 9.42;
new ChangeAffiliatedTransaction(empId, dues).execute();
Date payDate = getDate(2001, Calendar.NOVEMBER, 9);
final double charge = 19.42;
addServiceCharge(empId, getDate(2001, Calendar.NOVEMBER, 2), 100.00); // 지난 주 금요일
addServiceCharge(empId, payDate, charge); // 기간 내
addServiceCharge(empId, getDate(2001, Calendar.NOVEMBER, 16), 200.00); // 다음 주 금요일
final double hours = 8.0;
new TimeCardTransaction(payDate.getTime(), hours, empId).execute();
// when
PaydayTransaction pt = new PaydayTransaction(payDate);
pt.execute();
// then
Paycheck pc = pt.getPaycheck(empId);
assertPaycheck(pc, hourlyWage * hours, dues + charge, (hourlyWage * hours) - (dues + charge), "Hold");
}
private void addServiceCharge(Integer empId, Date date, double charge) {
new ServiceChargeTransaction(empId, date.getTime(), charge).execute();
}
}