Skip to content

Commit 4bb7dda

Browse files
committed
Work on admin tests
1 parent 39a1c1e commit 4bb7dda

7 files changed

Lines changed: 92 additions & 2 deletions

File tree

hexagonal/src/main/java/com/iluwatar/hexagonal/database/LotteryTicketRepositoryMock.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*/
3838
public class LotteryTicketRepositoryMock implements LotteryTicketRepository {
3939

40-
private Map<LotteryTicketId, LotteryTicket> tickets = new HashMap<>();
40+
private static Map<LotteryTicketId, LotteryTicket> tickets = new HashMap<>();
4141

4242
@Override
4343
public Optional<LotteryTicket> findById(LotteryTicketId id) {
@@ -60,4 +60,9 @@ public Optional<LotteryTicketId> save(LotteryTicket ticket) {
6060
public Map<LotteryTicketId, LotteryTicket> findAll() {
6161
return tickets;
6262
}
63+
64+
@Override
65+
public void deleteAll() {
66+
tickets.clear();
67+
}
6368
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ public interface LotteryAdministration {
3333

3434
Map<LotteryTicketId, LotteryTicket> getAllSubmittedTickets();
3535
LotteryNumbers performLottery();
36+
void resetLottery();
3637

3738
}

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
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+
*/
123
package com.iluwatar.hexagonal.domain;
224

325
import java.util.Map;
@@ -26,4 +48,9 @@ public Map<LotteryTicketId, LotteryTicket> getAllSubmittedTickets() {
2648
public LotteryNumbers performLottery() {
2749
return LotteryNumbers.createRandom();
2850
}
51+
52+
@Override
53+
public void resetLottery() {
54+
repository.deleteAll();
55+
}
2956
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ public interface LotteryTicketRepository {
3535
Optional<LotteryTicket> findById(LotteryTicketId id);
3636
Optional<LotteryTicketId> save(LotteryTicket ticket);
3737
Map<LotteryTicketId, LotteryTicket> findAll();
38+
void deleteAll();
3839

3940
}

hexagonal/src/test/java/com/iluwatar/hexagonal/domain/LotteryAdministrationTest.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
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+
*/
123
package com.iluwatar.hexagonal.domain;
224

325
import static org.junit.Assert.assertEquals;
@@ -19,6 +41,7 @@ public class LotteryAdministrationTest {
1941

2042
@Before
2143
public void submitTickets() {
44+
repository.deleteAll();
2245
repository.save(LotteryTestUtils.createLotteryTicket());
2346
repository.save(LotteryTestUtils.createLotteryTicket());
2447
repository.save(LotteryTestUtils.createLotteryTicket());
@@ -28,7 +51,7 @@ public void submitTickets() {
2851

2952
@Test
3053
public void testGetAllTickets() {
31-
assertEquals(admin.getAllSubmittedTickets().size(), 4);
54+
assertEquals(admin.getAllSubmittedTickets().size(), 5);
3255
}
3356

3457
@Test

hexagonal/src/test/java/com/iluwatar/hexagonal/domain/LotteryTestUtils.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
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+
*/
123
package com.iluwatar.hexagonal.domain;
224

325
import java.util.Arrays;
@@ -10,6 +32,9 @@
1032
*/
1133
public class LotteryTestUtils {
1234

35+
/**
36+
* @return lottery ticket
37+
*/
1338
public static LotteryTicket createLotteryTicket() {
1439
PlayerDetails details = PlayerDetails.create("[email protected]", "12231-213132", "+99324554");
1540
LotteryNumbers numbers = LotteryNumbers.create(new HashSet<>(Arrays.asList(1, 2, 3, 4)));

hexagonal/src/test/java/com/iluwatar/hexagonal/domain/LotteryTicketRepositoryTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import java.util.Optional;
2929

30+
import org.junit.Before;
3031
import org.junit.Test;
3132

3233
import com.iluwatar.hexagonal.database.LotteryTicketRepositoryMock;
@@ -38,6 +39,13 @@
3839
*/
3940
public class LotteryTicketRepositoryTest {
4041

42+
private final LotteryTicketRepository repository = new LotteryTicketRepositoryMock();
43+
44+
@Before
45+
public void clear() {
46+
repository.deleteAll();
47+
}
48+
4149
@Test
4250
public void testCrudOperations() {
4351
LotteryTicketRepository repository = new LotteryTicketRepositoryMock();

0 commit comments

Comments
 (0)