Implement admin interface
This commit is contained in:
parent
656b599687
commit
39a1c1e956
@ -28,7 +28,14 @@ package com.iluwatar.hexagonal;
|
||||
*
|
||||
*/
|
||||
public class App {
|
||||
/**
|
||||
* Program entry point
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Running hexagonal example");
|
||||
// submit some lottery tickets
|
||||
|
||||
// perform lottery
|
||||
|
||||
// check all the tickets
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@
|
||||
*/
|
||||
package com.iluwatar.hexagonal.domain;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -31,7 +31,7 @@ import java.util.List;
|
||||
*/
|
||||
public interface LotteryAdministration {
|
||||
|
||||
List<LotteryTicket> getAllSubmittedTickets();
|
||||
Map<LotteryTicketId, LotteryTicket> getAllSubmittedTickets();
|
||||
LotteryNumbers performLottery();
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
package com.iluwatar.hexagonal.domain;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.iluwatar.hexagonal.database.LotteryTicketRepositoryMock;
|
||||
|
||||
/**
|
||||
*
|
||||
* Lottery administration implementation
|
||||
*
|
||||
*/
|
||||
public class LotteryAdministrationImpl implements LotteryAdministration {
|
||||
|
||||
private final LotteryTicketRepository repository;
|
||||
|
||||
public LotteryAdministrationImpl() {
|
||||
repository = new LotteryTicketRepositoryMock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<LotteryTicketId, LotteryTicket> getAllSubmittedTickets() {
|
||||
return repository.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LotteryNumbers performLottery() {
|
||||
return LotteryNumbers.createRandom();
|
||||
}
|
||||
}
|
@ -27,6 +27,11 @@ import java.util.Optional;
|
||||
import com.iluwatar.hexagonal.database.LotteryTicketRepositoryMock;
|
||||
import com.iluwatar.hexagonal.domain.LotteryTicketCheckResult.CheckResult;
|
||||
|
||||
/**
|
||||
*
|
||||
* Implementation for lottery service
|
||||
*
|
||||
*/
|
||||
public class LotteryServiceImpl implements LotteryService {
|
||||
|
||||
private final LotteryTicketRepository repository;
|
||||
@ -45,7 +50,7 @@ public class LotteryServiceImpl implements LotteryService {
|
||||
Optional<LotteryTicket> optional = repository.findById(id);
|
||||
if (optional.isPresent()) {
|
||||
if (optional.get().getNumbers().equals(winningNumbers)) {
|
||||
return new LotteryTicketCheckResult(CheckResult.WIN_PRIZE);
|
||||
return new LotteryTicketCheckResult(CheckResult.WIN_PRIZE, 1000);
|
||||
} else {
|
||||
return new LotteryTicketCheckResult(CheckResult.NO_PRIZE);
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
package com.iluwatar.hexagonal.domain;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.iluwatar.hexagonal.database.LotteryTicketRepositoryMock;
|
||||
|
||||
/**
|
||||
*
|
||||
* Tests for lottery administration
|
||||
*
|
||||
*/
|
||||
public class LotteryAdministrationTest {
|
||||
|
||||
private LotteryTicketRepository repository = new LotteryTicketRepositoryMock();
|
||||
private LotteryAdministration admin = new LotteryAdministrationImpl();
|
||||
|
||||
@Before
|
||||
public void submitTickets() {
|
||||
repository.save(LotteryTestUtils.createLotteryTicket());
|
||||
repository.save(LotteryTestUtils.createLotteryTicket());
|
||||
repository.save(LotteryTestUtils.createLotteryTicket());
|
||||
repository.save(LotteryTestUtils.createLotteryTicket());
|
||||
repository.save(LotteryTestUtils.createLotteryTicket());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllTickets() {
|
||||
assertEquals(admin.getAllSubmittedTickets().size(), 4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPerformLottery() {
|
||||
assertEquals(admin.performLottery().getNumbers().size(), 4);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user