Skip to content

Commit d2f620a

Browse files
committed
Added tests for lottery ticket repository
1 parent 8b147c4 commit d2f620a

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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.assertTrue;
27+
28+
import java.util.Arrays;
29+
import java.util.HashSet;
30+
import java.util.Optional;
31+
import java.util.UUID;
32+
33+
import org.junit.Test;
34+
35+
import com.iluwatar.hexagonal.database.LotteryTicketRepositoryMock;
36+
37+
/**
38+
*
39+
* Tests for {@link LotteryTicketRepository}
40+
*
41+
*/
42+
public class LotteryTicketRepositoryTest {
43+
44+
@Test
45+
public void testCrudOperations() {
46+
LotteryTicketRepository repository = new LotteryTicketRepositoryMock();
47+
assertEquals(repository.findAll().size(), 0);
48+
LotteryTicket ticket = createLotteryTicket();
49+
Optional<UUID> uuid = repository.save(ticket);
50+
assertTrue(uuid.isPresent());
51+
assertEquals(repository.findAll().size(), 1);
52+
Optional<LotteryTicket> optionalTicket = repository.findByUuid(uuid.get());
53+
assertTrue(optionalTicket.isPresent());
54+
}
55+
56+
private LotteryTicket createLotteryTicket() {
57+
PlayerDetails details = PlayerDetails.create("foo@bar.com", "12231-213132", "+99324554");
58+
LotteryNumbers numbers = LotteryNumbers.create(new HashSet<>(Arrays.asList(1, 2, 3, 4)));
59+
return LotteryTicket.create(details, numbers);
60+
}
61+
}

0 commit comments

Comments
 (0)