mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-16 16:59:24 +00:00
docs: Content SEO updates (#2990)
* update yaml frontmatter format * update abstract document * update abstract factory * use the new pattern template * acyclic visitor seo * adapter seo * ambassador seo * acl seo * aaa seo * async method invocation seo * balking seo * bridge seo * builder seo * business delegate and bytecode seo * caching seo * callback seo * chain seo * update headings * circuit breaker seo * client session + collecting parameter seo * collection pipeline seo * combinator SEO * command seo * cqrs seo * commander seo * component seo * composite seo * composite entity seo * composite view seo * context object seo * converter seo * crtp seo * currying seo * dao seo * data bus seo * data locality seo * data mapper seo * dto seo * decorator seo * delegation seo * di seo * dirty flag seo * domain model seo * double buffer seo * double checked locking seo * double dispatch seo * dynamic proxy seo * event aggregator seo * event-based asynchronous seo * eda seo * event queue seo * event sourcing seo * execute around seo * extension objects seo * facade seo * factory seo * factory kit seo * factory method seo * fanout/fanin seo * feature toggle seo * filterer seo * fluent interface seo * flux seo * flyweight seo * front controller seo * function composition seo * game loop seo * gateway seo * guarded suspension seo * half-sync/half-async seo * health check seo * hexagonal seo * identity map seo * intercepting filter seo * interpreter seo * iterator seo * layers seo * lazy loading seo * leader election seo * leader/followers seo * lockable object seo * rename and add seo for marker interface * master-worker seo * mediator seo * memento seo * metadata mapping seo * microservice aggregator seo * api gw seo * microservices log aggregration seo * mvc seo * mvi seo * mvp seo * mvvm seo * monad seo * monitor seo * monostate seo * multiton seo * mute idiom seo * naked objects & notification seo * null object seo * object mother seo * object pool seo * observer seo * optimistic locking seo * page controller seo * page object seo * parameter object seo * partial response seo * pipeline seo * poison pill seo * presentation model seo * private class data seo * producer-consumer seo * promise seo * property seo * prototype seo * proxy seo * queue-based load leveling seo * reactor seo * registry seo * repository seo * RAII seo * retry seo * role object seo * saga seo * separated interface seo * serialized entity seo * serialized lob seo * servant seo * server session seo * service layer seo * service locator seo * service to worker seo * sharding seo * single table inheritance seo * singleton seo * spatial partition seo * special case seo * specification seo * state seo * step builder seo * strangler seo * strategy seo * subclass sandbox seo * table module seo * template method seo * throttling seo * tolerant reader seo * trampoline seo * transaction script seo * twin seo * type object seo * unit of work seo * update method seo * value object seo * version number seo * virtual proxy seo * visitor seo * seo enhancements * seo improvements * SEO enhancements * SEO improvements * SEO additions * SEO improvements * more SEO improvements * rename hexagonal + SEO improvements * SEO improvements * more SEO stuff * SEO improvements * SEO optimizations * SEO enhancements * enchance SEO * improve SEO * SEO improvements * update headers
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.iluwatar.hexagonal;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
class AppTest {
|
||||
|
||||
@Test
|
||||
void shouldExecuteApplicationWithoutException() {
|
||||
assertDoesNotThrow(() -> App.main(new String[]{}));
|
||||
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.iluwatar.hexagonal.banking;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Tests for banking
|
||||
*/
|
||||
class InMemoryBankTest {
|
||||
|
||||
private final WireTransfers bank = new InMemoryBank();
|
||||
|
||||
@Test
|
||||
void testInit() {
|
||||
assertEquals(0, bank.getFunds("foo"));
|
||||
bank.setFunds("foo", 100);
|
||||
assertEquals(100, bank.getFunds("foo"));
|
||||
bank.setFunds("bar", 150);
|
||||
assertEquals(150, bank.getFunds("bar"));
|
||||
assertTrue(bank.transferFunds(50, "bar", "foo"));
|
||||
assertEquals(150, bank.getFunds("foo"));
|
||||
assertEquals(100, bank.getFunds("bar"));
|
||||
}
|
||||
}
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.iluwatar.hexagonal.banking;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import com.mongodb.client.MongoClient;
|
||||
import com.mongodb.client.MongoClients;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import de.flapdoodle.embed.mongo.commands.ServerAddress;
|
||||
import de.flapdoodle.embed.mongo.distribution.Version;
|
||||
import de.flapdoodle.embed.mongo.transitions.Mongod;
|
||||
import de.flapdoodle.embed.mongo.transitions.RunningMongodProcess;
|
||||
import de.flapdoodle.reverse.TransitionWalker;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Tests for Mongo banking adapter
|
||||
*/
|
||||
class MongoBankTest {
|
||||
|
||||
private static final String TEST_DB = "lotteryDBTest";
|
||||
private static final String TEST_ACCOUNTS_COLLECTION = "testAccounts";
|
||||
|
||||
private static MongoClient mongoClient;
|
||||
private static MongoDatabase mongoDatabase;
|
||||
|
||||
private MongoBank mongoBank;
|
||||
|
||||
private static TransitionWalker.ReachedState<RunningMongodProcess> mongodProcess;
|
||||
|
||||
private static ServerAddress serverAddress;
|
||||
|
||||
|
||||
|
||||
@BeforeAll
|
||||
static void setUp() {
|
||||
mongodProcess = Mongod.instance().start(Version.Main.V7_0);
|
||||
serverAddress = mongodProcess.current().getServerAddress();
|
||||
mongoClient = MongoClients.create("mongodb://" + serverAddress.toString());
|
||||
mongoClient.startSession();
|
||||
mongoDatabase = mongoClient.getDatabase(TEST_DB);
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void tearDown() {
|
||||
mongoClient.close();
|
||||
mongodProcess.close();
|
||||
}
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void init() {
|
||||
System.setProperty("mongo-host", serverAddress.getHost());
|
||||
System.setProperty("mongo-port", String.valueOf(serverAddress.getPort()));
|
||||
mongoDatabase.drop();
|
||||
mongoBank = new MongoBank(mongoDatabase.getName(), TEST_ACCOUNTS_COLLECTION);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSetup() {
|
||||
assertEquals(0, mongoBank.getAccountsCollection().countDocuments());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFundTransfers() {
|
||||
assertEquals(0, mongoBank.getFunds("000-000"));
|
||||
mongoBank.setFunds("000-000", 10);
|
||||
assertEquals(10, mongoBank.getFunds("000-000"));
|
||||
assertEquals(0, mongoBank.getFunds("111-111"));
|
||||
mongoBank.transferFunds(9, "000-000", "111-111");
|
||||
assertEquals(1, mongoBank.getFunds("000-000"));
|
||||
assertEquals(9, mongoBank.getFunds("111-111"));
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.iluwatar.hexagonal.database;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import com.iluwatar.hexagonal.test.LotteryTestUtils;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Tests for {@link LotteryTicketRepository}
|
||||
*/
|
||||
class InMemoryTicketRepositoryTest {
|
||||
|
||||
private final LotteryTicketRepository repository = new InMemoryTicketRepository();
|
||||
|
||||
@BeforeEach
|
||||
void clear() {
|
||||
repository.deleteAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCrudOperations() {
|
||||
var repository = new InMemoryTicketRepository();
|
||||
assertTrue(repository.findAll().isEmpty());
|
||||
var ticket = LotteryTestUtils.createLotteryTicket();
|
||||
var id = repository.save(ticket);
|
||||
assertTrue(id.isPresent());
|
||||
assertEquals(1, repository.findAll().size());
|
||||
var optionalTicket = repository.findById(id.get());
|
||||
assertTrue(optionalTicket.isPresent());
|
||||
}
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.iluwatar.hexagonal.database;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import com.iluwatar.hexagonal.domain.LotteryNumbers;
|
||||
import com.iluwatar.hexagonal.domain.LotteryTicket;
|
||||
import com.iluwatar.hexagonal.domain.LotteryTicketId;
|
||||
import com.iluwatar.hexagonal.domain.PlayerDetails;
|
||||
import com.iluwatar.hexagonal.mongo.MongoConnectionPropertiesLoader;
|
||||
import com.mongodb.MongoClient;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Tests for Mongo based ticket repository
|
||||
*/
|
||||
@Disabled
|
||||
class MongoTicketRepositoryTest {
|
||||
|
||||
private static final String TEST_DB = "lotteryTestDB";
|
||||
private static final String TEST_TICKETS_COLLECTION = "lotteryTestTickets";
|
||||
private static final String TEST_COUNTERS_COLLECTION = "testCounters";
|
||||
|
||||
private MongoTicketRepository repository;
|
||||
|
||||
@BeforeEach
|
||||
void init() {
|
||||
MongoConnectionPropertiesLoader.load();
|
||||
var mongoClient = new MongoClient(System.getProperty("mongo-host"),
|
||||
Integer.parseInt(System.getProperty("mongo-port")));
|
||||
mongoClient.dropDatabase(TEST_DB);
|
||||
mongoClient.close();
|
||||
repository = new MongoTicketRepository(TEST_DB, TEST_TICKETS_COLLECTION,
|
||||
TEST_COUNTERS_COLLECTION);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSetup() {
|
||||
assertEquals(1, repository.getCountersCollection().countDocuments());
|
||||
assertEquals(0, repository.getTicketsCollection().countDocuments());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNextId() {
|
||||
assertEquals(1, repository.getNextId());
|
||||
assertEquals(2, repository.getNextId());
|
||||
assertEquals(3, repository.getNextId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCrudOperations() {
|
||||
// create new lottery ticket and save it
|
||||
var details = new PlayerDetails("foo@bar.com", "123-123", "07001234");
|
||||
var random = LotteryNumbers.createRandom();
|
||||
var original = new LotteryTicket(new LotteryTicketId(), details, random);
|
||||
var saved = repository.save(original);
|
||||
assertEquals(1, repository.getTicketsCollection().countDocuments());
|
||||
assertTrue(saved.isPresent());
|
||||
// fetch the saved lottery ticket from database and check its contents
|
||||
var found = repository.findById(saved.get());
|
||||
assertTrue(found.isPresent());
|
||||
var ticket = found.get();
|
||||
assertEquals("foo@bar.com", ticket.playerDetails().email());
|
||||
assertEquals("123-123", ticket.playerDetails().bankAccount());
|
||||
assertEquals("07001234", ticket.playerDetails().phoneNumber());
|
||||
assertEquals(original.lotteryNumbers(), ticket.lotteryNumbers());
|
||||
// clear the collection
|
||||
repository.deleteAll();
|
||||
assertEquals(0, repository.getTicketsCollection().countDocuments());
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.iluwatar.hexagonal.domain;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.Set;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link LotteryNumbers}
|
||||
*/
|
||||
class LotteryNumbersTest {
|
||||
|
||||
@Test
|
||||
void testGivenNumbers() {
|
||||
var numbers = LotteryNumbers.create(Set.of(1, 2, 3, 4));
|
||||
assertEquals(numbers.getNumbers().size(), 4);
|
||||
assertTrue(numbers.getNumbers().contains(1));
|
||||
assertTrue(numbers.getNumbers().contains(2));
|
||||
assertTrue(numbers.getNumbers().contains(3));
|
||||
assertTrue(numbers.getNumbers().contains(4));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNumbersCantBeModified() {
|
||||
var numbers = LotteryNumbers.create(Set.of(1, 2, 3, 4));
|
||||
assertThrows(UnsupportedOperationException.class, () -> numbers.getNumbers().add(5));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRandomNumbers() {
|
||||
var numbers = LotteryNumbers.createRandom();
|
||||
assertEquals(numbers.getNumbers().size(), LotteryNumbers.NUM_NUMBERS);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEquals() {
|
||||
var numbers1 = LotteryNumbers.create(Set.of(1, 2, 3, 4));
|
||||
var numbers2 = LotteryNumbers.create(Set.of(1, 2, 3, 4));
|
||||
assertEquals(numbers1, numbers2);
|
||||
var numbers3 = LotteryNumbers.create(Set.of(11, 12, 13, 14));
|
||||
assertNotEquals(numbers1, numbers3);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.iluwatar.hexagonal.domain;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.iluwatar.hexagonal.banking.WireTransfers;
|
||||
import com.iluwatar.hexagonal.domain.LotteryTicketCheckResult.CheckResult;
|
||||
import com.iluwatar.hexagonal.module.LotteryTestingModule;
|
||||
import com.iluwatar.hexagonal.test.LotteryTestUtils;
|
||||
import java.util.Set;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test the lottery system
|
||||
*/
|
||||
class LotteryTest {
|
||||
|
||||
private final Injector injector;
|
||||
@Inject
|
||||
private LotteryAdministration administration;
|
||||
@Inject
|
||||
private LotteryService service;
|
||||
@Inject
|
||||
private WireTransfers wireTransfers;
|
||||
|
||||
LotteryTest() {
|
||||
this.injector = Guice.createInjector(new LotteryTestingModule());
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
injector.injectMembers(this);
|
||||
// add funds to the test player's bank account
|
||||
wireTransfers.setFunds("123-12312", 100);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLottery() {
|
||||
// admin resets the lottery
|
||||
administration.resetLottery();
|
||||
assertEquals(0, administration.getAllSubmittedTickets().size());
|
||||
|
||||
// players submit the lottery tickets
|
||||
var ticket1 = service.submitTicket(LotteryTestUtils.createLotteryTicket("cvt@bbb.com",
|
||||
"123-12312", "+32425255", Set.of(1, 2, 3, 4)));
|
||||
assertTrue(ticket1.isPresent());
|
||||
var ticket2 = service.submitTicket(LotteryTestUtils.createLotteryTicket("ant@bac.com",
|
||||
"123-12312", "+32423455", Set.of(11, 12, 13, 14)));
|
||||
assertTrue(ticket2.isPresent());
|
||||
var ticket3 = service.submitTicket(LotteryTestUtils.createLotteryTicket("arg@boo.com",
|
||||
"123-12312", "+32421255", Set.of(6, 8, 13, 19)));
|
||||
assertTrue(ticket3.isPresent());
|
||||
assertEquals(3, administration.getAllSubmittedTickets().size());
|
||||
|
||||
// perform lottery
|
||||
var winningNumbers = administration.performLottery();
|
||||
|
||||
// cheat a bit for testing sake, use winning numbers to submit another ticket
|
||||
var ticket4 = service.submitTicket(LotteryTestUtils.createLotteryTicket("lucky@orb.com",
|
||||
"123-12312", "+12421255", winningNumbers.getNumbers()));
|
||||
assertTrue(ticket4.isPresent());
|
||||
assertEquals(4, administration.getAllSubmittedTickets().size());
|
||||
|
||||
// check winners
|
||||
var tickets = administration.getAllSubmittedTickets();
|
||||
for (var id : tickets.keySet()) {
|
||||
var checkResult = service.checkTicketForPrize(id, winningNumbers);
|
||||
assertNotEquals(CheckResult.TICKET_NOT_SUBMITTED, checkResult.getResult());
|
||||
if (checkResult.getResult().equals(CheckResult.WIN_PRIZE)) {
|
||||
assertTrue(checkResult.getPrizeAmount() > 0);
|
||||
} else {
|
||||
assertEquals(0, checkResult.getPrizeAmount());
|
||||
}
|
||||
}
|
||||
|
||||
// check another ticket that has not been submitted
|
||||
var checkResult = service.checkTicketForPrize(new LotteryTicketId(), winningNumbers);
|
||||
assertEquals(CheckResult.TICKET_NOT_SUBMITTED, checkResult.getResult());
|
||||
assertEquals(0, checkResult.getPrizeAmount());
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.iluwatar.hexagonal.domain;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
import com.iluwatar.hexagonal.domain.LotteryTicketCheckResult.CheckResult;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link LotteryTicketCheckResult}
|
||||
*/
|
||||
class LotteryTicketCheckResultTest {
|
||||
|
||||
@Test
|
||||
void testEquals() {
|
||||
var result1 = new LotteryTicketCheckResult(CheckResult.NO_PRIZE);
|
||||
var result2 = new LotteryTicketCheckResult(CheckResult.NO_PRIZE);
|
||||
assertEquals(result1, result2);
|
||||
var result3 = new LotteryTicketCheckResult(CheckResult.WIN_PRIZE, 300000);
|
||||
assertNotEquals(result1, result3);
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.iluwatar.hexagonal.domain;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Tests for lottery ticket id
|
||||
*/
|
||||
class LotteryTicketIdTest {
|
||||
|
||||
@Test
|
||||
void testEquals() {
|
||||
var ticketId1 = new LotteryTicketId();
|
||||
var ticketId2 = new LotteryTicketId();
|
||||
var ticketId3 = new LotteryTicketId();
|
||||
assertNotEquals(ticketId1, ticketId2);
|
||||
assertNotEquals(ticketId2, ticketId3);
|
||||
var ticketId4 = new LotteryTicketId(ticketId1.getId());
|
||||
assertEquals(ticketId1, ticketId4);
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.iluwatar.hexagonal.domain;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
import java.util.Set;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test Lottery Tickets for equality
|
||||
*/
|
||||
class LotteryTicketTest {
|
||||
|
||||
@Test
|
||||
void testEquals() {
|
||||
var details1 = new PlayerDetails("bob@foo.bar", "1212-121212", "+34332322");
|
||||
var numbers1 = LotteryNumbers.create(Set.of(1, 2, 3, 4));
|
||||
var ticket1 = new LotteryTicket(new LotteryTicketId(), details1, numbers1);
|
||||
var details2 = new PlayerDetails("bob@foo.bar", "1212-121212", "+34332322");
|
||||
var numbers2 = LotteryNumbers.create(Set.of(1, 2, 3, 4));
|
||||
var ticket2 = new LotteryTicket(new LotteryTicketId(), details2, numbers2);
|
||||
assertEquals(ticket1, ticket2);
|
||||
var details3 = new PlayerDetails("elsa@foo.bar", "1223-121212", "+49332322");
|
||||
var numbers3 = LotteryNumbers.create(Set.of(1, 2, 3, 8));
|
||||
var ticket3 = new LotteryTicket(new LotteryTicketId(), details3, numbers3);
|
||||
assertNotEquals(ticket1, ticket3);
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.iluwatar.hexagonal.domain;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link PlayerDetails}
|
||||
*/
|
||||
class PlayerDetailsTest {
|
||||
|
||||
@Test
|
||||
void testEquals() {
|
||||
var details1 = new PlayerDetails("tom@foo.bar", "11212-123434", "+12323425");
|
||||
var details2 = new PlayerDetails("tom@foo.bar", "11212-123434", "+12323425");
|
||||
assertEquals(details1, details2);
|
||||
var details3 = new PlayerDetails("john@foo.bar", "16412-123439", "+34323432");
|
||||
assertNotEquals(details1, details3);
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.iluwatar.hexagonal.eventlog;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import com.iluwatar.hexagonal.domain.PlayerDetails;
|
||||
import com.iluwatar.hexagonal.mongo.MongoConnectionPropertiesLoader;
|
||||
import com.mongodb.MongoClient;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Tests for Mongo event log
|
||||
*/
|
||||
@Disabled
|
||||
class MongoEventLogTest {
|
||||
|
||||
private static final String TEST_DB = "lotteryDBTest";
|
||||
private static final String TEST_EVENTS_COLLECTION = "testEvents";
|
||||
|
||||
private MongoEventLog mongoEventLog;
|
||||
|
||||
@BeforeEach
|
||||
void init() {
|
||||
MongoConnectionPropertiesLoader.load();
|
||||
var mongoClient = new MongoClient(System.getProperty("mongo-host"),
|
||||
Integer.parseInt(System.getProperty("mongo-port")));
|
||||
mongoClient.dropDatabase(TEST_DB);
|
||||
mongoClient.close();
|
||||
mongoEventLog = new MongoEventLog(TEST_DB, TEST_EVENTS_COLLECTION);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSetup() {
|
||||
assertEquals(0, mongoEventLog.getEventsCollection().countDocuments());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFundTransfers() {
|
||||
var playerDetails = new PlayerDetails("john@wayne.com", "000-000", "03432534543");
|
||||
mongoEventLog.prizeError(playerDetails, 1000);
|
||||
assertEquals(1, mongoEventLog.getEventsCollection().countDocuments());
|
||||
mongoEventLog.prizeError(playerDetails, 1000);
|
||||
assertEquals(2, mongoEventLog.getEventsCollection().countDocuments());
|
||||
mongoEventLog.ticketDidNotWin(playerDetails);
|
||||
assertEquals(3, mongoEventLog.getEventsCollection().countDocuments());
|
||||
mongoEventLog.ticketDidNotWin(playerDetails);
|
||||
assertEquals(4, mongoEventLog.getEventsCollection().countDocuments());
|
||||
mongoEventLog.ticketSubmitError(playerDetails);
|
||||
assertEquals(5, mongoEventLog.getEventsCollection().countDocuments());
|
||||
mongoEventLog.ticketSubmitError(playerDetails);
|
||||
assertEquals(6, mongoEventLog.getEventsCollection().countDocuments());
|
||||
mongoEventLog.ticketSubmitted(playerDetails);
|
||||
assertEquals(7, mongoEventLog.getEventsCollection().countDocuments());
|
||||
mongoEventLog.ticketSubmitted(playerDetails);
|
||||
assertEquals(8, mongoEventLog.getEventsCollection().countDocuments());
|
||||
mongoEventLog.ticketWon(playerDetails, 1000);
|
||||
assertEquals(9, mongoEventLog.getEventsCollection().countDocuments());
|
||||
mongoEventLog.ticketWon(playerDetails, 1000);
|
||||
assertEquals(10, mongoEventLog.getEventsCollection().countDocuments());
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.iluwatar.hexagonal.test;
|
||||
|
||||
import com.iluwatar.hexagonal.domain.LotteryNumbers;
|
||||
import com.iluwatar.hexagonal.domain.LotteryTicket;
|
||||
import com.iluwatar.hexagonal.domain.LotteryTicketId;
|
||||
import com.iluwatar.hexagonal.domain.PlayerDetails;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Utilities for lottery tests
|
||||
*/
|
||||
public class LotteryTestUtils {
|
||||
|
||||
/**
|
||||
* @return lottery ticket
|
||||
*/
|
||||
public static LotteryTicket createLotteryTicket() {
|
||||
return createLotteryTicket("foo@bar.com", "12231-213132", "+99324554", Set.of(1, 2, 3, 4));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return lottery ticket
|
||||
*/
|
||||
public static LotteryTicket createLotteryTicket(String email, String account, String phone,
|
||||
Set<Integer> givenNumbers) {
|
||||
var details = new PlayerDetails(email, account, phone);
|
||||
var numbers = LotteryNumbers.create(givenNumbers);
|
||||
return new LotteryTicket(new LotteryTicketId(), details, numbers);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user