Skip to content

Commit 2785f69

Browse files
committed
Add lottery ticket check result
1 parent 804ffc3 commit 2785f69

3 files changed

Lines changed: 145 additions & 1 deletion

File tree

hexagonal/src/main/java/com/iluwatar/hexagonal/domain/LotteryService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ public interface LotteryService {
3131

3232
LotteryTicketSubmitResult submitTicket(LotteryTicket ticket);
3333

34-
void checkTicketForPrize(LotteryTicket ticket);
34+
LotteryTicketCheckResult checkTicketForPrize(LotteryTicket ticket);
3535
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/**
2+
* The MIT License
3+
* Copyright (c) 2014 Ilkka Seppälä
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*/
23+
package com.iluwatar.hexagonal.domain;
24+
25+
/**
26+
*
27+
* Represents lottery ticket check result.
28+
*
29+
*/
30+
public class LotteryTicketCheckResult {
31+
32+
public enum CheckResult {WIN_PRIZE, NO_PRIZE, TICKET_NOT_SUBMITTED};
33+
34+
private final CheckResult checkResult;
35+
36+
private final int prizeAmount;
37+
38+
/**
39+
* Constructor.
40+
*/
41+
public LotteryTicketCheckResult(CheckResult result) {
42+
checkResult = result;
43+
prizeAmount = 0;
44+
}
45+
46+
/**
47+
* Constructor.
48+
*/
49+
public LotteryTicketCheckResult(CheckResult result, int amount) {
50+
checkResult = result;
51+
prizeAmount = amount;
52+
}
53+
54+
/**
55+
* @return check result
56+
*/
57+
public CheckResult getResult() {
58+
return checkResult;
59+
}
60+
61+
/**
62+
* @return prize amount
63+
*/
64+
public int getPrizeAmount() {
65+
return prizeAmount;
66+
}
67+
68+
@Override
69+
public int hashCode() {
70+
final int prime = 31;
71+
int result = 1;
72+
result = prime * result + ((checkResult == null) ? 0 : checkResult.hashCode());
73+
result = prime * result + prizeAmount;
74+
return result;
75+
}
76+
77+
@Override
78+
public boolean equals(Object obj) {
79+
if (this == obj) {
80+
return true;
81+
}
82+
if (obj == null) {
83+
return false;
84+
}
85+
if (getClass() != obj.getClass()) {
86+
return false;
87+
}
88+
LotteryTicketCheckResult other = (LotteryTicketCheckResult) obj;
89+
if (checkResult != other.checkResult) {
90+
return false;
91+
}
92+
if (prizeAmount != other.prizeAmount) {
93+
return false;
94+
}
95+
return true;
96+
}
97+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* The MIT License
3+
* Copyright (c) 2014 Ilkka Seppälä
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*/
23+
package com.iluwatar.hexagonal.domain;
24+
25+
import static org.junit.Assert.assertEquals;
26+
import static org.junit.Assert.assertFalse;
27+
28+
import org.junit.Test;
29+
30+
import com.iluwatar.hexagonal.domain.LotteryTicketCheckResult.CheckResult;
31+
32+
/**
33+
*
34+
* Unit tests for {@link LotteryTicketCheckResult}
35+
*
36+
*/
37+
public class LotteryTicketCheckResultTest {
38+
39+
@Test
40+
public void testEquals() {
41+
LotteryTicketCheckResult result1 = new LotteryTicketCheckResult(CheckResult.NO_PRIZE);
42+
LotteryTicketCheckResult result2 = new LotteryTicketCheckResult(CheckResult.NO_PRIZE);
43+
assertEquals(result1, result2);
44+
LotteryTicketCheckResult result3 = new LotteryTicketCheckResult(CheckResult.WIN_PRIZE, 300000);
45+
assertFalse(result1.equals(result3));
46+
}
47+
}

0 commit comments

Comments
 (0)