Compare commits

..

7 Commits

137 changed files with 200 additions and 222 deletions

View File

@ -8,7 +8,6 @@
[![License MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/iluwatar/java-design-patterns/master/LICENSE.md)
[![Join the chat at https://gitter.im/iluwatar/java-design-patterns](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/iluwatar/java-design-patterns?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=com.iluwatar%3Ajava-design-patterns&metric=alert_status)](https://sonarcloud.io/dashboard/index/com.iluwatar%3Ajava-design-patterns)
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/1503/badge)](https://bestpractices.coreinfrastructure.org/projects/1503)
# Introduction

View File

@ -29,7 +29,7 @@
<parent>
<artifactId>java-design-patterns</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>abstract-document</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>abstract-factory</artifactId>
<dependencies>

View File

@ -30,7 +30,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>acyclic-visitor</artifactId>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>adapter</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<artifactId>aggregator-microservices</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -29,7 +29,7 @@
<parent>
<artifactId>aggregator-microservices</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -29,7 +29,7 @@
<parent>
<artifactId>aggregator-microservices</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -29,7 +29,7 @@
<parent>
<artifactId>java-design-patterns</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>aggregator-microservices</artifactId>

View File

@ -29,7 +29,7 @@
<parent>
<artifactId>java-design-patterns</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ambassador</artifactId>

View File

@ -29,7 +29,7 @@
<parent>
<artifactId>api-gateway</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>api-gateway-service</artifactId>

View File

@ -29,7 +29,7 @@
<parent>
<artifactId>api-gateway</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -29,7 +29,7 @@
<parent>
<artifactId>java-design-patterns</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>api-gateway</artifactId>

View File

@ -29,7 +29,7 @@
<parent>
<artifactId>api-gateway</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>async-method-invocation</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<artifactId>java-design-patterns</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>bridge</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>builder</artifactId>
<dependencies>

View File

@ -30,7 +30,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>business-delegate</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>caching</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>callback</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>chain</artifactId>
<dependencies>

View File

@ -27,7 +27,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>collection-pipeline</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>command</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>composite</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<artifactId>java-design-patterns</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<dependencies>

View File

@ -21,7 +21,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>cqrs</artifactId>
<dependencies>

View File

@ -30,7 +30,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>dao</artifactId>

View File

@ -33,7 +33,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>data-bus</artifactId>
<dependencies>

View File

@ -28,7 +28,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>data-mapper</artifactId>
<dependencies>

View File

@ -28,7 +28,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>data-transfer-object</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>decorator</artifactId>
<dependencies>

View File

@ -30,7 +30,7 @@
<parent>
<artifactId>java-design-patterns</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>dependency-injection</artifactId>
<dependencies>

View File

@ -29,11 +29,11 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<groupId>com.iluwatar</groupId>
<artifactId>dirty-flag</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
<name>dirty-flag</name>
<url>http://maven.apache.org</url>
<properties>

View File

@ -27,7 +27,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>double-checked-locking</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>double-dispatch</artifactId>
<dependencies>

View File

@ -26,7 +26,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<dependencies>

View File

@ -30,7 +30,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>eip-message-channel</artifactId>
<dependencies>

View File

@ -28,7 +28,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>eip-publish-subscribe</artifactId>
<dependencies>

View File

@ -26,7 +26,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<dependencies>

View File

@ -26,7 +26,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<dependencies>

View File

@ -28,7 +28,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>event-aggregator</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>event-asynchronous</artifactId>
<dependencies>

View File

@ -31,7 +31,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>event-driven-architecture</artifactId>

View File

@ -30,7 +30,7 @@
<parent>
<artifactId>java-design-patterns</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>event-queue</artifactId>
<dependencies>

View File

@ -30,7 +30,7 @@
<parent>
<artifactId>java-design-patterns</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>event-sourcing</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>execute-around</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<artifactId>java-design-patterns</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>facade</artifactId>
<dependencies>

View File

@ -30,7 +30,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>factory-kit</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>factory-method</artifactId>
<dependencies>

View File

@ -30,7 +30,7 @@
<parent>
<artifactId>java-design-patterns</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -29,7 +29,7 @@
<parent>
<artifactId>java-design-patterns</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>flux</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>flyweight</artifactId>
<dependencies>

View File

@ -30,7 +30,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>front-controller</artifactId>
<dependencies>

View File

@ -30,7 +30,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<packaging>jar</packaging>
<artifactId>guarded-suspension</artifactId>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>half-sync-half-async</artifactId>
<dependencies>

View File

@ -30,7 +30,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>hexagonal</artifactId>
<dependencies>

View File

@ -110,21 +110,6 @@ public class MongoTicketRepository implements LotteryTicketRepository {
return result.getInteger("seq");
}
/**
* @return mongo client
*/
public MongoClient getMongoClient() {
return mongoClient;
}
/**
*
* @return mongo database
*/
public MongoDatabase getMongoDatabase() {
return database;
}
/**
*
* @return tickets collection

View File

@ -22,10 +22,10 @@
*/
package com.iluwatar.hexagonal.domain;
import java.util.ArrayList;
import com.google.common.base.Joiner;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.PrimitiveIterator;
import java.util.Random;
import java.util.Set;
@ -85,16 +85,7 @@ public class LotteryNumbers {
* @return numbers as comma separated string
*/
public String getNumbersAsString() {
List<Integer> list = new ArrayList<>();
list.addAll(numbers);
StringBuilder builder = new StringBuilder();
for (int i = 0; i < NUM_NUMBERS; i++) {
builder.append(list.get(i));
if (i < NUM_NUMBERS - 1) {
builder.append(",");
}
}
return builder.toString();
return Joiner.on(',').join(numbers);
}
/**

View File

@ -22,17 +22,18 @@
*/
package com.iluwatar.hexagonal.domain;
import java.util.concurrent.atomic.AtomicInteger;
/**
* Lottery ticked id
*/
public class LotteryTicketId {
private static volatile int numAllocated;
private static AtomicInteger numAllocated = new AtomicInteger(0);
private final int id;
public LotteryTicketId() {
this.id = numAllocated + 1;
numAllocated++;
this.id = numAllocated.incrementAndGet();
}
public LotteryTicketId(int id) {

View File

@ -27,10 +27,10 @@ import org.junit.jupiter.api.Test;
/**
* Unit test for simple App.
*/
public class AppTest {
class AppTest {
@Test
public void testApp() {
void testApp() {
String[] args = {};
App.main(args);
}

View File

@ -32,19 +32,19 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* Tests for banking
*
*/
public class InMemoryBankTest {
class InMemoryBankTest {
private final WireTransfers bank = new InMemoryBank();
@Test
public void testInit() {
assertEquals(bank.getFunds("foo"), 0);
void testInit() {
assertEquals(0, bank.getFunds("foo"));
bank.setFunds("foo", 100);
assertEquals(bank.getFunds("foo"), 100);
assertEquals(100, bank.getFunds("foo"));
bank.setFunds("bar", 150);
assertEquals(bank.getFunds("bar"), 150);
assertEquals(150, bank.getFunds("bar"));
assertTrue(bank.transferFunds(50, "bar", "foo"));
assertEquals(bank.getFunds("foo"), 150);
assertEquals(bank.getFunds("bar"), 100);
assertEquals(150, bank.getFunds("foo"));
assertEquals(100, bank.getFunds("bar"));
}
}

View File

@ -34,7 +34,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
* Tests for Mongo banking adapter
*/
@Disabled
public class MongoBankTest {
class MongoBankTest {
private static final String TEST_DB = "lotteryDBTest";
private static final String TEST_ACCOUNTS_COLLECTION = "testAccounts";
@ -42,7 +42,7 @@ public class MongoBankTest {
private MongoBank mongoBank;
@BeforeEach
public void init() {
void init() {
MongoConnectionPropertiesLoader.load();
MongoClient mongoClient = new MongoClient(System.getProperty("mongo-host"),
Integer.parseInt(System.getProperty("mongo-port")));
@ -52,12 +52,12 @@ public class MongoBankTest {
}
@Test
public void testSetup() {
void testSetup() {
assertEquals(0, mongoBank.getAccountsCollection().count());
}
@Test
public void testFundTransfers() {
void testFundTransfers() {
assertEquals(0, mongoBank.getFunds("000-000"));
mongoBank.setFunds("000-000", 10);
assertEquals(10, mongoBank.getFunds("000-000"));

View File

@ -38,23 +38,23 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* Tests for {@link LotteryTicketRepository}
*
*/
public class InMemoryTicketRepositoryTest {
class InMemoryTicketRepositoryTest {
private final LotteryTicketRepository repository = new InMemoryTicketRepository();
@BeforeEach
public void clear() {
void clear() {
repository.deleteAll();
}
@Test
public void testCrudOperations() {
void testCrudOperations() {
LotteryTicketRepository repository = new InMemoryTicketRepository();
assertEquals(repository.findAll().size(), 0);
assertTrue(repository.findAll().isEmpty());
LotteryTicket ticket = LotteryTestUtils.createLotteryTicket();
Optional<LotteryTicketId> id = repository.save(ticket);
assertTrue(id.isPresent());
assertEquals(repository.findAll().size(), 1);
assertEquals(1, repository.findAll().size());
Optional<LotteryTicket> optionalTicket = repository.findById(id.get());
assertTrue(optionalTicket.isPresent());
}

View File

@ -41,7 +41,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* Tests for Mongo based ticket repository
*/
@Disabled
public class MongoTicketRepositoryTest {
class MongoTicketRepositoryTest {
private static final String TEST_DB = "lotteryTestDB";
private static final String TEST_TICKETS_COLLECTION = "lotteryTestTickets";
@ -50,7 +50,7 @@ public class MongoTicketRepositoryTest {
private MongoTicketRepository repository;
@BeforeEach
public void init() {
void init() {
MongoConnectionPropertiesLoader.load();
MongoClient mongoClient = new MongoClient(System.getProperty("mongo-host"),
Integer.parseInt(System.getProperty("mongo-port")));
@ -61,20 +61,20 @@ public class MongoTicketRepositoryTest {
}
@Test
public void testSetup() {
assertTrue(repository.getCountersCollection().count() == 1);
assertTrue(repository.getTicketsCollection().count() == 0);
void testSetup() {
assertEquals(1, repository.getCountersCollection().count());
assertEquals(0, repository.getTicketsCollection().count());
}
@Test
public void testNextId() {
void testNextId() {
assertEquals(1, repository.getNextId());
assertEquals(2, repository.getNextId());
assertEquals(3, repository.getNextId());
}
@Test
public void testCrudOperations() {
void testCrudOperations() {
// create new lottery ticket and save it
PlayerDetails details = new PlayerDetails("foo@bar.com", "123-123", "07001234");
LotteryNumbers random = LotteryNumbers.createRandom();

View File

@ -28,7 +28,7 @@ import java.util.Arrays;
import java.util.HashSet;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ -37,10 +37,10 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* Unit tests for {@link LotteryNumbers}
*
*/
public class LotteryNumbersTest {
class LotteryNumbersTest {
@Test
public void testGivenNumbers() {
void testGivenNumbers() {
LotteryNumbers numbers = LotteryNumbers.create(
new HashSet<>(Arrays.asList(1, 2, 3, 4)));
assertEquals(numbers.getNumbers().size(), 4);
@ -51,7 +51,7 @@ public class LotteryNumbersTest {
}
@Test
public void testNumbersCantBeModified() {
void testNumbersCantBeModified() {
LotteryNumbers numbers = LotteryNumbers.create(
new HashSet<>(Arrays.asList(1, 2, 3, 4)));
assertThrows(UnsupportedOperationException.class, () -> {
@ -60,20 +60,20 @@ public class LotteryNumbersTest {
}
@Test
public void testRandomNumbers() {
void testRandomNumbers() {
LotteryNumbers numbers = LotteryNumbers.createRandom();
assertEquals(numbers.getNumbers().size(), LotteryNumbers.NUM_NUMBERS);
}
@Test
public void testEquals() {
void testEquals() {
LotteryNumbers numbers1 = LotteryNumbers.create(
new HashSet<>(Arrays.asList(1, 2, 3, 4)));
LotteryNumbers numbers2 = LotteryNumbers.create(
new HashSet<>(Arrays.asList(1, 2, 3, 4)));
assertTrue(numbers1.equals(numbers2));
assertEquals(numbers1, numbers2);
LotteryNumbers numbers3 = LotteryNumbers.create(
new HashSet<>(Arrays.asList(11, 12, 13, 14)));
assertFalse(numbers1.equals(numbers3));
assertNotEquals(numbers1, numbers3);
}
}

View File

@ -38,6 +38,7 @@ import java.util.Map;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
@ -45,7 +46,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* Test the lottery system
*
*/
public class LotteryTest {
class LotteryTest {
private Injector injector;
@Inject
@ -55,22 +56,22 @@ public class LotteryTest {
@Inject
private WireTransfers wireTransfers;
public LotteryTest() {
LotteryTest() {
this.injector = Guice.createInjector(new LotteryTestingModule());
}
@BeforeEach
public void setup() {
void setup() {
injector.injectMembers(this);
// add funds to the test player's bank account
wireTransfers.setFunds("123-12312", 100);
}
@Test
public void testLottery() {
void testLottery() {
// admin resets the lottery
administration.resetLottery();
assertEquals(administration.getAllSubmittedTickets().size(), 0);
assertEquals(0, administration.getAllSubmittedTickets().size());
// players submit the lottery tickets
Optional<LotteryTicketId> ticket1 = service.submitTicket(LotteryTestUtils.createLotteryTicket("cvt@bbb.com",
@ -82,7 +83,7 @@ public class LotteryTest {
Optional<LotteryTicketId> ticket3 = service.submitTicket(LotteryTestUtils.createLotteryTicket("arg@boo.com",
"123-12312", "+32421255", new HashSet<>(Arrays.asList(6, 8, 13, 19))));
assertTrue(ticket3.isPresent());
assertEquals(administration.getAllSubmittedTickets().size(), 3);
assertEquals(3, administration.getAllSubmittedTickets().size());
// perform lottery
LotteryNumbers winningNumbers = administration.performLottery();
@ -91,23 +92,23 @@ public class LotteryTest {
Optional<LotteryTicketId> ticket4 = service.submitTicket(LotteryTestUtils.createLotteryTicket("lucky@orb.com",
"123-12312", "+12421255", winningNumbers.getNumbers()));
assertTrue(ticket4.isPresent());
assertEquals(administration.getAllSubmittedTickets().size(), 4);
assertEquals(4, administration.getAllSubmittedTickets().size());
// check winners
Map<LotteryTicketId, LotteryTicket> tickets = administration.getAllSubmittedTickets();
for (LotteryTicketId id: tickets.keySet()) {
LotteryTicketCheckResult checkResult = service.checkTicketForPrize(id, winningNumbers);
assertTrue(checkResult.getResult() != CheckResult.TICKET_NOT_SUBMITTED);
assertNotEquals(CheckResult.TICKET_NOT_SUBMITTED, checkResult.getResult());
if (checkResult.getResult().equals(CheckResult.WIN_PRIZE)) {
assertTrue(checkResult.getPrizeAmount() > 0);
} else if (checkResult.getResult().equals(CheckResult.WIN_PRIZE)) {
assertEquals(checkResult.getPrizeAmount(), 0);
assertEquals(0, checkResult.getPrizeAmount());
}
}
// check another ticket that has not been submitted
LotteryTicketCheckResult checkResult = service.checkTicketForPrize(new LotteryTicketId(), winningNumbers);
assertTrue(checkResult.getResult() == CheckResult.TICKET_NOT_SUBMITTED);
assertEquals(checkResult.getPrizeAmount(), 0);
assertEquals(CheckResult.TICKET_NOT_SUBMITTED, checkResult.getResult());
assertEquals(0, checkResult.getPrizeAmount());
}
}

View File

@ -26,21 +26,21 @@ import com.iluwatar.hexagonal.domain.LotteryTicketCheckResult.CheckResult;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
/**
*
* Unit tests for {@link LotteryTicketCheckResult}
*
*/
public class LotteryTicketCheckResultTest {
class LotteryTicketCheckResultTest {
@Test
public void testEquals() {
void testEquals() {
LotteryTicketCheckResult result1 = new LotteryTicketCheckResult(CheckResult.NO_PRIZE);
LotteryTicketCheckResult result2 = new LotteryTicketCheckResult(CheckResult.NO_PRIZE);
assertEquals(result1, result2);
LotteryTicketCheckResult result3 = new LotteryTicketCheckResult(CheckResult.WIN_PRIZE, 300000);
assertFalse(result1.equals(result3));
assertNotEquals(result1, result3);
}
}

View File

@ -24,22 +24,22 @@ package com.iluwatar.hexagonal.domain;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
/**
* Tests for lottery ticket id
*/
public class LotteryTicketIdTest {
class LotteryTicketIdTest {
@Test
public void testEquals() {
void testEquals() {
LotteryTicketId ticketId1 = new LotteryTicketId();
LotteryTicketId ticketId2 = new LotteryTicketId();
LotteryTicketId ticketId3 = new LotteryTicketId();
assertFalse(ticketId1.equals(ticketId2));
assertFalse(ticketId2.equals(ticketId3));
assertNotEquals(ticketId1, ticketId2);
assertNotEquals(ticketId2, ticketId3);
LotteryTicketId ticketId4 = new LotteryTicketId(ticketId1.getId());
assertTrue(ticketId1.equals(ticketId4));
assertEquals(ticketId1, ticketId4);
}
}

View File

@ -29,14 +29,15 @@ import java.util.HashSet;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
/**
* Test Lottery Tickets for equality
*/
public class LotteryTicketTest {
class LotteryTicketTest {
@Test
public void testEquals() {
void testEquals() {
PlayerDetails details1 = new PlayerDetails("bob@foo.bar", "1212-121212", "+34332322");
LotteryNumbers numbers1 = LotteryNumbers.create(new HashSet<Integer>(Arrays.asList(1, 2, 3, 4)));
LotteryTicket ticket1 = new LotteryTicket(new LotteryTicketId(), details1, numbers1);
@ -47,6 +48,6 @@ public class LotteryTicketTest {
PlayerDetails details3 = new PlayerDetails("elsa@foo.bar", "1223-121212", "+49332322");
LotteryNumbers numbers3 = LotteryNumbers.create(new HashSet<Integer>(Arrays.asList(1, 2, 3, 8)));
LotteryTicket ticket3 = new LotteryTicket(new LotteryTicketId(), details3, numbers3);
assertFalse(ticket1.equals(ticket3));
assertNotEquals(ticket1, ticket3);
}
}

View File

@ -25,21 +25,21 @@ package com.iluwatar.hexagonal.domain;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
/**
*
* Unit tests for {@link PlayerDetails}
*
*/
public class PlayerDetailsTest {
class PlayerDetailsTest {
@Test
public void testEquals() {
void testEquals() {
PlayerDetails details1 = new PlayerDetails("tom@foo.bar", "11212-123434", "+12323425");
PlayerDetails details2 = new PlayerDetails("tom@foo.bar", "11212-123434", "+12323425");
assertEquals(details1, details2);
PlayerDetails details3 = new PlayerDetails("john@foo.bar", "16412-123439", "+34323432");
assertFalse(details1.equals(details3));
assertNotEquals(details1, details3);
}
}

View File

@ -35,7 +35,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
* Tests for Mongo event log
*/
@Disabled
public class MongoEventLogTest {
class MongoEventLogTest {
private static final String TEST_DB = "lotteryDBTest";
private static final String TEST_EVENTS_COLLECTION = "testEvents";
@ -43,7 +43,7 @@ public class MongoEventLogTest {
private MongoEventLog mongoEventLog;
@BeforeEach
public void init() {
void init() {
MongoConnectionPropertiesLoader.load();
MongoClient mongoClient = new MongoClient(System.getProperty("mongo-host"),
Integer.parseInt(System.getProperty("mongo-port")));
@ -53,12 +53,12 @@ public class MongoEventLogTest {
}
@Test
public void testSetup() {
void testSetup() {
assertEquals(0, mongoEventLog.getEventsCollection().count());
}
@Test
public void testFundTransfers() {
void testFundTransfers() {
PlayerDetails playerDetails = new PlayerDetails("john@wayne.com", "000-000", "03432534543");
mongoEventLog.prizeError(playerDetails, 1000);
assertEquals(1, mongoEventLog.getEventsCollection().count());

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>intercepting-filter</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>interpreter</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>iterator</artifactId>
<dependencies>

View File

@ -30,7 +30,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<groupId>com.iluwatar.layers</groupId>
<artifactId>layers</artifactId>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>lazy-loading</artifactId>
<dependencies>

View File

@ -24,7 +24,7 @@
<parent>
<artifactId>java-design-patterns</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>mediator</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>memento</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>model-view-controller</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>model-view-presenter</artifactId>
<name>model-view-presenter</name>

View File

@ -28,7 +28,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>module</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>monad</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>monostate</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>multiton</artifactId>
<dependencies>

View File

@ -21,7 +21,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>mute-idiom</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>mutex</artifactId>
<dependencies>

View File

@ -16,7 +16,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>naked-objects</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>naked-objects-dom</artifactId>

View File

@ -16,7 +16,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>naked-objects</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>naked-objects-fixture</artifactId>

View File

@ -16,7 +16,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>naked-objects</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>naked-objects-integtests</artifactId>

View File

@ -15,7 +15,7 @@
<parent>
<artifactId>java-design-patterns</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>naked-objects</artifactId>
@ -350,17 +350,17 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>naked-objects-dom</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>naked-objects-fixture</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>naked-objects-webapp</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</dependency>
</dependencies>

View File

@ -16,7 +16,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>naked-objects</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>naked-objects-webapp</artifactId>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>null-object</artifactId>
<dependencies>

View File

@ -30,7 +30,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>object-mother</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>object-pool</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0</version>
<version>1.21.0-SNAPSHOT</version>
</parent>
<artifactId>observer</artifactId>
<dependencies>

Some files were not shown because too many files have changed in this diff Show More