-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathBudgetPlanTest.java
More file actions
108 lines (93 loc) · 3.15 KB
/
Copy pathBudgetPlanTest.java
File metadata and controls
108 lines (93 loc) · 3.15 KB
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
package com.odde.tdd;
import org.junit.Test;
import java.time.YearMonth;
import java.util.*;
import static org.junit.Assert.assertEquals;
public class BudgetPlanTest {
MockBudgetRepo budgetRepo = new MockBudgetRepo();
BudgetPlan target = new BudgetPlan(budgetRepo);
Calendar calendar = new GregorianCalendar();
@Test
public void budge_of_22_01_01() {
calendar.set(2022, Calendar.JANUARY, 1);
Date from = calendar.getTime();
Date to = calendar.getTime();
double amount = target.getBudget(from, to);
assertEquals(1.0, amount, 0.0);
}
@Test
public void budge_from_22_01_01_to_22_01_02() {
calendar.set(2022, Calendar.JANUARY, 1);
Date from = calendar.getTime();
calendar.set(2022, Calendar.JANUARY, 3);
Date to = calendar.getTime();
double amount = target.getBudget(from, to);
assertEquals(3.0, amount, 0.0);
}
@Test
public void budge_from_22_01_31_to_22_02_01() {
calendar.set(2022, Calendar.JANUARY, 31);
Date from = calendar.getTime();
calendar.set(2022, Calendar.FEBRUARY, 1);
Date to = calendar.getTime();
double amount = target.getBudget(from, to);
assertEquals(3.0, amount, 0.0);
}
@Test
public void budget_from_22_01_31_to_22_03_01() {
calendar.set(2022, Calendar.JANUARY, 31);
Date from = calendar.getTime();
calendar.set(2022, Calendar.MARCH, 1);
Date to = calendar.getTime();
double amount = target.getBudget(from, to);
assertEquals(60.0, amount, 0.0);
}
@Test
public void budget_from_21_12_31_to_22_02_01() {
calendar.set(2021, Calendar.DECEMBER, 31);
Date from = calendar.getTime();
calendar.set(2022, Calendar.FEBRUARY, 1);
Date to = calendar.getTime();
double amount = target.getBudget(from, to);
assertEquals(34.0, amount, 0.0);
}
@Test
public void budge_from_21_12_31_to_23_01_01() {
calendar.set(2021, Calendar.DECEMBER, 31);
Date from = calendar.getTime();
calendar.set(2023, Calendar.JANUARY, 1);
Date to = calendar.getTime();
double amount = target.getBudget(from, to);
assertEquals(2384.0, amount, 0);
}
@Test
public void budget_from_20_01_01_to_20_12_31() {
calendar.set(2020, Calendar.JANUARY, 1);
Date from = calendar.getTime();
calendar.set(2020, Calendar.DECEMBER, 31);
Date to = calendar.getTime();
double amount = target.getBudget(from, to);
assertEquals(0, amount, 0);
}
}
class MockBudgetRepo implements BudgetRepo {
@Override
public List<Budget> findAll() {
return Arrays.asList(
new Budget(YearMonth.of(2021, 12), 31),
new Budget(YearMonth.of(2022, 1), 31),
new Budget(YearMonth.of(2022, 2), 56),
new Budget(YearMonth.of(2022, 3), 93),
new Budget(YearMonth.of(2022, 4), 120),
new Budget(YearMonth.of(2022, 5), 155),
new Budget(YearMonth.of(2022, 6), 180),
new Budget(YearMonth.of(2022, 7), 217),
new Budget(YearMonth.of(2022, 8), 248),
new Budget(YearMonth.of(2022, 9), 270),
new Budget(YearMonth.of(2022, 10), 310),
new Budget(YearMonth.of(2022, 11), 330),
new Budget(YearMonth.of(2022, 12), 372),
new Budget(YearMonth.of(2023, 1), 31)
);
}
}