Compare commits

..

14 Commits

Author SHA1 Message Date
0fad8b9b6c Addressed checkstyle issue 2018-10-21 17:20:52 +05:30
10179007e8 Addressed review comments 2018-10-21 17:19:41 +05:30
70b4931ab8 Removed unused import from Promise 2018-10-20 18:01:41 +05:30
543eb9a4be Minor refactorings and code style changes. 1) Removed several use of raw types 2) Removed unnecessary throws clauses 3) Used lambda expressions wherever applicable 4) Used apt assertion methods for readability 5) Use of try with resources wherever applicable 6) Corrected incorrect order of assertXXX arguments 2018-10-20 17:50:52 +05:30
2f569d670a Made minor changes in some patterns such as removed throws clause where not needed, changed incorrect order of arguments in assertEquals 2018-10-17 21:11:31 +05:30
db33cc533b Remove CII best practices badge 2018-10-13 18:40:10 +03:00
8433c7b712 Merge pull request #793 from andrievsky/master
Fix redundant list alloc in LotteryNumbers
2018-10-13 18:28:40 +03:00
ee74fec53c Fix pattern title 2018-09-30 21:36:32 +03:00
7a7e891384 Set version for next development iteration 2018-09-30 21:05:57 +03:00
26d6d96f78 Reach milestone 1.20.0 2018-09-30 21:03:48 +03:00
3cec7a9ec1 Merge pull request #796 from LyndonArmitage/module-ignore-test-output
Delete & Ignore output.txt & error.txt
2018-09-25 22:49:25 +03:00
b079aec1fd Merge pull request #794 from iluwatar/Issue781
#781 Resolved ClasscastException from Acyclic Visitor
2018-09-25 22:45:25 +03:00
8f53df91b9 Delete & Ignore output.txt & error.txt
Both output.txt and error.txt are produced by tests.
Each file contained a header that was overridden upon executing said
tests causing tracked files to be changed.

Added them to a local .gitignore file for this module.
2018-09-24 10:08:02 +01:00
1d12d94bac Fix redundant list alloc in LotteryNumbers 2018-09-11 11:55:53 +02:00
238 changed files with 442 additions and 640 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) [![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) [![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) [![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 # Introduction

View File

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

View File

@ -32,6 +32,7 @@ import java.util.stream.Stream;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/** /**
* AbstractDocument test class * AbstractDocument test class
@ -81,8 +82,8 @@ public class AbstractDocumentTest {
Map<String, Object> props = new HashMap<>(); Map<String, Object> props = new HashMap<>();
props.put(KEY, VALUE); props.put(KEY, VALUE);
DocumentImplementation document = new DocumentImplementation(props); DocumentImplementation document = new DocumentImplementation(props);
assertNotNull(document.toString().contains(KEY)); assertTrue(document.toString().contains(KEY));
assertNotNull(document.toString().contains(VALUE)); assertTrue(document.toString().contains(VALUE));
} }
} }

View File

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

View File

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

View File

@ -25,27 +25,19 @@ package com.iluwatar.acyclicvisitor;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.groups.Tuple.tuple; import static org.assertj.core.groups.Tuple.tuple;
import static uk.org.lidalia.slf4jext.Level.INFO; import static uk.org.lidalia.slf4jext.Level.INFO;
import static org.mockito.Mockito.mock;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import uk.org.lidalia.slf4jtest.TestLogger; import uk.org.lidalia.slf4jtest.TestLogger;
import uk.org.lidalia.slf4jtest.TestLoggerFactory; import uk.org.lidalia.slf4jtest.TestLoggerFactory;
import org.junit.jupiter.api.Test;
import com.iluwatar.acyclicvisitor.ConfigureForUnixVisitor;
import com.iluwatar.acyclicvisitor.Hayes;
import com.iluwatar.acyclicvisitor.HayesVisitor;
import com.iluwatar.acyclicvisitor.Zoom;
import com.iluwatar.acyclicvisitor.ZoomVisitor;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
/** /**
* ConfigureForUnixVisitor test class * ConfigureForUnixVisitor test class
*/ */
public class ConfigureForUnixVisitorTest { public class ConfigureForUnixVisitorTest {
TestLogger logger = TestLoggerFactory.getTestLogger(ConfigureForUnixVisitor.class); private static final TestLogger LOGGER = TestLoggerFactory.getTestLogger(ConfigureForUnixVisitor.class);
@AfterEach @AfterEach
public void clearLoggers() { public void clearLoggers() {
@ -59,7 +51,7 @@ public class ConfigureForUnixVisitorTest {
conUnix.visit(zoom); conUnix.visit(zoom);
assertThat(logger.getLoggingEvents()).extracting("level", "message").contains( assertThat(LOGGER.getLoggingEvents()).extracting("level", "message").contains(
tuple(INFO, zoom + " used with Unix configurator.")); tuple(INFO, zoom + " used with Unix configurator."));
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -31,7 +31,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
*/ */
public class InventoryControllerTest { public class InventoryControllerTest {
@Test @Test
public void testGetProductInventories() throws Exception { public void testGetProductInventories() {
InventoryController inventoryController = new InventoryController(); InventoryController inventoryController = new InventoryController();
int numberOfInventories = inventoryController.getProductInventories(); int numberOfInventories = inventoryController.getProductInventories();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -37,7 +37,7 @@ public class HammerTest extends WeaponTest {
* underlying weapon implementation. * underlying weapon implementation.
*/ */
@Test @Test
public void testHammer() throws Exception { public void testHammer() {
final Hammer hammer = spy(new Hammer(mock(FlyingEnchantment.class))); final Hammer hammer = spy(new Hammer(mock(FlyingEnchantment.class)));
testBasicWeaponActions(hammer); testBasicWeaponActions(hammer);
} }

View File

@ -37,7 +37,7 @@ public class SwordTest extends WeaponTest {
* underlying weapon implementation. * underlying weapon implementation.
*/ */
@Test @Test
public void testSword() throws Exception { public void testSword() {
final Sword sword = spy(new Sword(mock(FlyingEnchantment.class))); final Sword sword = spy(new Sword(mock(FlyingEnchantment.class)));
testBasicWeaponActions(sword); testBasicWeaponActions(sword);
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -41,12 +41,7 @@ public class App {
*/ */
public static void main(String[] args) { public static void main(String[] args) {
Task task = new SimpleTask(); Task task = new SimpleTask();
Callback callback = new Callback() { Callback callback = () -> LOGGER.info("I'm done now.");
@Override
public void call() {
LOGGER.info("I'm done now.");
}
};
task.executeWith(callback); task.executeWith(callback);
} }
} }

View File

@ -38,29 +38,6 @@ public class CallbackTest {
@Test @Test
public void test() { public void test() {
Callback callback = new Callback() {
@Override
public void call() {
callingCount++;
}
};
Task task = new SimpleTask();
assertEquals(new Integer(0), callingCount, "Initial calling count of 0");
task.executeWith(callback);
assertEquals(new Integer(1), callingCount, "Callback called once");
task.executeWith(callback);
assertEquals(new Integer(2), callingCount, "Callback called twice");
}
@Test
public void testWithLambdasExample() {
Callback callback = () -> callingCount++; Callback callback = () -> callingCount++;
Task task = new SimpleTask(); Task task = new SimpleTask();

View File

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

View File

@ -43,7 +43,7 @@ public class OrcKingTest {
}; };
@Test @Test
public void testMakeRequest() throws Exception { public void testMakeRequest() {
final OrcKing king = new OrcKing(); final OrcKing king = new OrcKing();
for (final Request request : REQUESTS) { for (final Request request : REQUESTS) {

View File

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

View File

@ -26,10 +26,10 @@ package com.iluwatar.collectionpipeline;
* A Car class that has the properties of make, model, year and category. * A Car class that has the properties of make, model, year and category.
*/ */
public class Car { public class Car {
private String make; private final String make;
private String model; private final String model;
private int year; private final int year;
private Category category; private final Category category;
/** /**
* Constructor to create an instance of car. * Constructor to create an instance of car.

View File

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

View File

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

View File

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

View File

@ -71,7 +71,7 @@ public class ConverterTest {
user.getFirstName().toLowerCase() + user.getLastName().toLowerCase() + "@whatever.com")); user.getFirstName().toLowerCase() + user.getLastName().toLowerCase() + "@whatever.com"));
User u1 = new User("John", "Doe", false, "12324"); User u1 = new User("John", "Doe", false, "12324");
UserDto userDto = converter.convertFromEntity(u1); UserDto userDto = converter.convertFromEntity(u1);
assertEquals(userDto.getEmail(), "johndoe@whatever.com"); assertEquals("johndoe@whatever.com", userDto.getEmail());
} }
/** /**
@ -83,6 +83,6 @@ public class ConverterTest {
ArrayList<User> users = Lists.newArrayList(new User("Camile", "Tough", false, "124sad"), ArrayList<User> users = Lists.newArrayList(new User("Camile", "Tough", false, "124sad"),
new User("Marti", "Luther", true, "42309fd"), new User("Kate", "Smith", true, "if0243")); new User("Marti", "Luther", true, "42309fd"), new User("Kate", "Smith", true, "if0243"));
List<User> fromDtos = userConverter.createFromDtos(userConverter.createFromEntities(users)); List<User> fromDtos = userConverter.createFromDtos(userConverter.createFromEntities(users));
assertEquals(fromDtos, users); assertEquals(users, fromDtos);
} }
} }

View File

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

View File

@ -96,7 +96,7 @@ public class IntegrationTest {
@Test @Test
public void testGetAuthorBooks() { public void testGetAuthorBooks() {
List<Book> books = queryService.getAuthorBooks("username1"); List<Book> books = queryService.getAuthorBooks("username1");
assertTrue(books.size() == 2); assertEquals(2, books.size());
assertTrue(books.contains(new Book("title1", 10))); assertTrue(books.contains(new Book("title1", 10)));
assertTrue(books.contains(new Book("new_title2", 30))); assertTrue(books.contains(new Book("new_title2", 30)));
} }

View File

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

View File

@ -88,13 +88,7 @@ public class CustomerTest {
@Test @Test
public void testToString() { public void testToString() {
final StringBuffer buffer = new StringBuffer(); assertEquals(String.format("Customer{id=%s, firstName='%s', lastName='%s'}",
buffer.append("Customer{id=") customer.getId(), customer.getFirstName(), customer.getLastName()), customer.toString());
.append("" + customer.getId())
.append(", firstName='")
.append(customer.getFirstName())
.append("\', lastName='")
.append(customer.getLastName() + "\'}");
assertEquals(buffer.toString(), customer.toString());
} }
} }

View File

@ -257,7 +257,7 @@ public class DbCustomerDaoTest {
private void assertCustomerCountIs(int count) throws Exception { private void assertCustomerCountIs(int count) throws Exception {
try (Stream<Customer> allCustomers = dao.getAll()) { try (Stream<Customer> allCustomers = dao.getAll()) {
assertTrue(allCustomers.count() == count); assertEquals(count, allCustomers.count());
} }
} }

View File

@ -156,7 +156,7 @@ public class InMemoryCustomerDaoTest {
private void assertCustomerCountIs(int count) throws Exception { private void assertCustomerCountIs(int count) throws Exception {
try (Stream<Customer> allCustomers = dao.getAll()) { try (Stream<Customer> allCustomers = dao.getAll()) {
assertTrue(allCustomers.count() == count); assertEquals(count, allCustomers.count());
} }
} }
} }

View File

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

View File

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

View File

@ -21,6 +21,7 @@ package com.iluwatar.datamapper;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
/** /**
* The Data Mapper (DM) is a layer of software that separates the in-memory objects from the * The Data Mapper (DM) is a layer of software that separates the in-memory objects from the
@ -43,27 +44,29 @@ public class DataMapperTest {
final StudentDataMapper mapper = new StudentDataMapperImpl(); final StudentDataMapper mapper = new StudentDataMapperImpl();
/* Create new student */ /* Create new student */
Student student = new Student(1, "Adam", 'A'); int studentId = 1;
Student student = new Student(studentId, "Adam", 'A');
/* Add student in respectibe db */ /* Add student in respectibe db */
mapper.insert(student); mapper.insert(student);
/* Check if student is added in db */ /* Check if student is added in db */
assertEquals(student.getStudentId(), mapper.find(student.getStudentId()).get().getStudentId()); assertEquals(studentId, mapper.find(student.getStudentId()).get().getStudentId());
/* Update existing student object */ /* Update existing student object */
student = new Student(student.getStudentId(), "AdamUpdated", 'A'); String updatedName = "AdamUpdated";
student = new Student(student.getStudentId(), updatedName, 'A');
/* Update student in respectibe db */ /* Update student in respectibe db */
mapper.update(student); mapper.update(student);
/* Check if student is updated in db */ /* Check if student is updated in db */
assertEquals(mapper.find(student.getStudentId()).get().getName(), "AdamUpdated"); assertEquals(updatedName, mapper.find(student.getStudentId()).get().getName());
/* Delete student in db */ /* Delete student in db */
mapper.delete(student); mapper.delete(student);
/* Result should be false */ /* Result should be false */
assertEquals(false, mapper.find(student.getStudentId()).isPresent()); assertFalse(mapper.find(student.getStudentId()).isPresent());
} }
} }

View File

@ -20,7 +20,9 @@ package com.iluwatar.datamapper;
import org.junit.jupiter.api.Test; 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.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
/** /**
@ -28,28 +30,27 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
*/ */
public final class StudentTest { public final class StudentTest {
@Test
/** /**
* This API tests the equality behaviour of Student object * This API tests the equality behaviour of Student object
* Object Equality should work as per logic defined in equals method * Object Equality should work as per logic defined in equals method
* *
* @throws Exception if any execution error during test * @throws Exception if any execution error during test
*/ */
@Test
public void testEquality() throws Exception { public void testEquality() throws Exception {
/* Create some students */ /* Create some students */
final Student firstStudent = new Student(1, "Adam", 'A'); final Student firstStudent = new Student(1, "Adam", 'A');
final Student secondStudent = new Student(2, "Donald", 'B'); final Student secondStudent = new Student(2, "Donald", 'B');
final Student secondSameStudent = new Student(2, "Donald", 'B'); final Student secondSameStudent = new Student(2, "Donald", 'B');
final Student firstSameStudent = firstStudent;
/* Check equals functionality: should return 'true' */ /* Check equals functionality: should return 'true' */
assertTrue(firstStudent.equals(firstSameStudent)); assertEquals(firstStudent, firstStudent);
/* Check equals functionality: should return 'false' */ /* Check equals functionality: should return 'false' */
assertFalse(firstStudent.equals(secondStudent)); assertNotEquals(firstStudent, secondStudent);
/* Check equals functionality: should return 'true' */ /* Check equals functionality: should return 'true' */
assertTrue(secondStudent.equals(secondSameStudent)); assertEquals(secondStudent, secondSameStudent);
} }
} }

View File

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

View File

@ -30,6 +30,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
/** /**
* tests {@link CustomerResource}. * tests {@link CustomerResource}.
@ -45,10 +46,10 @@ public class CustomerResourceTest {
List<CustomerDto> allCustomers = customerResource.getAllCustomers(); List<CustomerDto> allCustomers = customerResource.getAllCustomers();
assertEquals(allCustomers.size(), 1); assertEquals(1, allCustomers.size());
assertEquals(allCustomers.get(0).getId(), "1"); assertEquals("1", allCustomers.get(0).getId());
assertEquals(allCustomers.get(0).getFirstName(), "Melody"); assertEquals("Melody", allCustomers.get(0).getFirstName());
assertEquals(allCustomers.get(0).getLastName(), "Yates"); assertEquals("Yates", allCustomers.get(0).getLastName());
} }
@Test @Test
@ -59,9 +60,9 @@ public class CustomerResourceTest {
customerResource.save(customer); customerResource.save(customer);
List<CustomerDto> allCustomers = customerResource.getAllCustomers(); List<CustomerDto> allCustomers = customerResource.getAllCustomers();
assertEquals(allCustomers.get(0).getId(), "1"); assertEquals("1", allCustomers.get(0).getId());
assertEquals(allCustomers.get(0).getFirstName(), "Rita"); assertEquals("Rita", allCustomers.get(0).getFirstName());
assertEquals(allCustomers.get(0).getLastName(), "Reynolds"); assertEquals("Reynolds", allCustomers.get(0).getLastName());
} }
@Test @Test
@ -75,7 +76,7 @@ public class CustomerResourceTest {
customerResource.delete(customer.getId()); customerResource.delete(customer.getId());
List<CustomerDto> allCustomers = customerResource.getAllCustomers(); List<CustomerDto> allCustomers = customerResource.getAllCustomers();
assertEquals(allCustomers.size(), 0); assertTrue(allCustomers.isEmpty());
} }
} }

View File

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

View File

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

View File

@ -40,7 +40,7 @@ import com.iluwatar.delegation.simple.printers.HpPrinter;
*/ */
public class App { public class App {
public static final String MESSAGE_TO_PRINT = "hello world"; private static final String MESSAGE_TO_PRINT = "hello world";
/** /**
* Program entry point * Program entry point

View File

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

View File

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

View File

@ -22,6 +22,7 @@
*/ */
package org.dirty.flag; package org.dirty.flag;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List; import java.util.List;
@ -41,7 +42,7 @@ public class DirtyFlagTest {
public void testIsDirty() { public void testIsDirty() {
DataFetcher df = new DataFetcher(); DataFetcher df = new DataFetcher();
List<String> countries = df.fetch(); List<String> countries = df.fetch();
assertTrue(!countries.isEmpty()); assertFalse(countries.isEmpty());
} }
@Test @Test

View File

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

View File

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

View File

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

View File

@ -51,7 +51,7 @@ public class AggregatorRoute extends RouteBuilder {
* @throws Exception in case of exception during configuration * @throws Exception in case of exception during configuration
*/ */
@Override @Override
public void configure() throws Exception { public void configure() {
// Main route // Main route
from("{{entry}}").aggregate(constant(true), aggregator) from("{{entry}}").aggregate(constant(true), aggregator)
.completionSize(3).completionInterval(2000) .completionSize(3).completionInterval(2000)

View File

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

View File

@ -70,7 +70,7 @@ public class App {
}); });
context.start(); context.start();
context.getRoutes().stream().forEach(r -> LOGGER.info(r.toString())); context.getRoutes().forEach(r -> LOGGER.info(r.toString()));
context.stop(); context.stop();
} }
} }

View File

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

View File

@ -65,7 +65,7 @@ public class App {
}); });
ProducerTemplate template = context.createProducerTemplate(); ProducerTemplate template = context.createProducerTemplate();
context.start(); context.start();
context.getRoutes().stream().forEach(r -> LOGGER.info(r.toString())); context.getRoutes().forEach(r -> LOGGER.info(r.toString()));
template.sendBody("direct:origin", "Hello from origin"); template.sendBody("direct:origin", "Hello from origin");
context.stop(); context.stop();
} }

View File

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

View File

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

View File

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

View File

@ -76,7 +76,7 @@ public class KingJoffreyTest {
private class InMemoryAppender extends AppenderBase<ILoggingEvent> { private class InMemoryAppender extends AppenderBase<ILoggingEvent> {
private List<ILoggingEvent> log = new LinkedList<>(); private List<ILoggingEvent> log = new LinkedList<>();
public InMemoryAppender(Class clazz) { public InMemoryAppender(Class<?> clazz) {
((Logger) LoggerFactory.getLogger(clazz)).addAppender(this); ((Logger) LoggerFactory.getLogger(clazz)).addAppender(this);
start(); start();
} }

View File

@ -35,7 +35,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
public class WeekdayTest { public class WeekdayTest {
@Test @Test
public void testToString() throws Exception { public void testToString() {
for (final Weekday weekday : Weekday.values()) { for (final Weekday weekday : Weekday.values()) {
final String toString = weekday.toString(); final String toString = weekday.toString();
assertNotNull(toString); assertNotNull(toString);

View File

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

View File

@ -16,11 +16,12 @@
*/ */
package com.iluwatar.event.asynchronous; package com.iluwatar.event.asynchronous;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
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.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
@ -30,26 +31,19 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* *
*/ */
public class EventAsynchronousTest { public class EventAsynchronousTest {
App app;
private static final Logger LOGGER = LoggerFactory.getLogger(EventAsynchronousTest.class); private static final Logger LOGGER = LoggerFactory.getLogger(EventAsynchronousTest.class);
@BeforeEach
public void setUp() {
app = new App();
}
@Test @Test
public void testAsynchronousEvent() { public void testAsynchronousEvent() {
EventManager eventManager = new EventManager(); EventManager eventManager = new EventManager();
try { try {
int aEventId = eventManager.createAsync(60); int aEventId = eventManager.createAsync(60);
eventManager.start(aEventId); eventManager.start(aEventId);
assertTrue(eventManager.getEventPool().size() == 1); assertEquals(1, eventManager.getEventPool().size());
assertTrue(eventManager.getEventPool().size() < EventManager.MAX_RUNNING_EVENTS); assertTrue(eventManager.getEventPool().size() < EventManager.MAX_RUNNING_EVENTS);
assertTrue(eventManager.numOfCurrentlyRunningSyncEvent() == -1); assertEquals(-1, eventManager.numOfCurrentlyRunningSyncEvent());
eventManager.cancel(aEventId); eventManager.cancel(aEventId);
assertTrue(eventManager.getEventPool().size() == 0); assertTrue(eventManager.getEventPool().isEmpty());
} catch (MaxNumOfEventsAllowedException | LongRunningEventException | EventDoesNotExistException e) { } catch (MaxNumOfEventsAllowedException | LongRunningEventException | EventDoesNotExistException e) {
LOGGER.error(e.getMessage()); LOGGER.error(e.getMessage());
} }
@ -61,11 +55,11 @@ public class EventAsynchronousTest {
try { try {
int sEventId = eventManager.create(60); int sEventId = eventManager.create(60);
eventManager.start(sEventId); eventManager.start(sEventId);
assertTrue(eventManager.getEventPool().size() == 1); assertEquals(1, eventManager.getEventPool().size());
assertTrue(eventManager.getEventPool().size() < EventManager.MAX_RUNNING_EVENTS); assertTrue(eventManager.getEventPool().size() < EventManager.MAX_RUNNING_EVENTS);
assertTrue(eventManager.numOfCurrentlyRunningSyncEvent() != -1); assertNotEquals(-1, eventManager.numOfCurrentlyRunningSyncEvent());
eventManager.cancel(sEventId); eventManager.cancel(sEventId);
assertTrue(eventManager.getEventPool().size() == 0); assertTrue(eventManager.getEventPool().isEmpty());
} catch (MaxNumOfEventsAllowedException | LongRunningEventException | EventDoesNotExistException } catch (MaxNumOfEventsAllowedException | LongRunningEventException | EventDoesNotExistException
| InvalidOperationException e) { | InvalidOperationException e) {
LOGGER.error(e.getMessage()); LOGGER.error(e.getMessage());
@ -73,7 +67,7 @@ public class EventAsynchronousTest {
} }
@Test @Test
public void testUnsuccessfulSynchronousEvent() throws InvalidOperationException { public void testUnsuccessfulSynchronousEvent() {
assertThrows(InvalidOperationException.class, () -> { assertThrows(InvalidOperationException.class, () -> {
EventManager eventManager = new EventManager(); EventManager eventManager = new EventManager();
try { try {
@ -94,7 +88,7 @@ public class EventAsynchronousTest {
int eventTime = 1; int eventTime = 1;
int sEventId = eventManager.create(eventTime); int sEventId = eventManager.create(eventTime);
assertTrue(eventManager.getEventPool().size() == 1); assertEquals(1, eventManager.getEventPool().size());
eventManager.start(sEventId); eventManager.start(sEventId);
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
@ -104,7 +98,7 @@ public class EventAsynchronousTest {
while (System.currentTimeMillis() < endTime) { while (System.currentTimeMillis() < endTime) {
} }
assertTrue(eventManager.getEventPool().size() == 0); assertTrue(eventManager.getEventPool().isEmpty());
} catch (MaxNumOfEventsAllowedException | LongRunningEventException | EventDoesNotExistException } catch (MaxNumOfEventsAllowedException | LongRunningEventException | EventDoesNotExistException
| InvalidOperationException e) { | InvalidOperationException e) {
@ -121,7 +115,7 @@ public class EventAsynchronousTest {
int aEventId1 = eventManager.createAsync(eventTime); int aEventId1 = eventManager.createAsync(eventTime);
int aEventId2 = eventManager.createAsync(eventTime); int aEventId2 = eventManager.createAsync(eventTime);
int aEventId3 = eventManager.createAsync(eventTime); int aEventId3 = eventManager.createAsync(eventTime);
assertTrue(eventManager.getEventPool().size() == 3); assertEquals(3, eventManager.getEventPool().size());
eventManager.start(aEventId1); eventManager.start(aEventId1);
eventManager.start(aEventId2); eventManager.start(aEventId2);
@ -133,7 +127,7 @@ public class EventAsynchronousTest {
while (System.currentTimeMillis() < endTime) { while (System.currentTimeMillis() < endTime) {
} }
assertTrue(eventManager.getEventPool().size() == 0); assertTrue(eventManager.getEventPool().isEmpty());
} catch (MaxNumOfEventsAllowedException | LongRunningEventException | EventDoesNotExistException e) { } catch (MaxNumOfEventsAllowedException | LongRunningEventException | EventDoesNotExistException e) {
LOGGER.error(e.getMessage()); LOGGER.error(e.getMessage());

View File

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

View File

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

View File

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

View File

@ -74,7 +74,7 @@ public class App {
LOGGER.info("Running the system first time............"); LOGGER.info("Running the system first time............");
eventProcessor.reset(); eventProcessor.reset();
LOGGER.info("Creating th accounts............"); LOGGER.info("Creating the accounts............");
eventProcessor.process(new AccountCreateEvent( eventProcessor.process(new AccountCreateEvent(
0, new Date().getTime(), ACCOUNT_OF_DAENERYS, "Daenerys Targaryen")); 0, new Date().getTime(), ACCOUNT_OF_DAENERYS, "Daenerys Targaryen"));
@ -98,7 +98,7 @@ public class App {
LOGGER.info(AccountAggregate.getAccount(ACCOUNT_OF_DAENERYS).toString()); LOGGER.info(AccountAggregate.getAccount(ACCOUNT_OF_DAENERYS).toString());
LOGGER.info(AccountAggregate.getAccount(ACCOUNT_OF_JON).toString()); LOGGER.info(AccountAggregate.getAccount(ACCOUNT_OF_JON).toString());
LOGGER.info("At that point system had a shot down, state in memory is cleared............"); LOGGER.info("At that point system had a shut down, state in memory is cleared............");
AccountAggregate.resetState(); AccountAggregate.resetState();
LOGGER.info("Recover the system by the events in journal file............"); LOGGER.info("Recover the system by the events in journal file............");

View File

@ -92,7 +92,7 @@ public class MoneyTransferEvent extends DomainEvent {
} }
Account accountTo = AccountAggregate.getAccount(accountNoTo); Account accountTo = AccountAggregate.getAccount(accountNoTo);
if (accountTo == null) { if (accountTo == null) {
throw new RuntimeException("Account not found" + accountTo); throw new RuntimeException("Account not found " + accountNoTo);
} }
accountFrom.handleTransferFromEvent(this); accountFrom.handleTransferFromEvent(this);

View File

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

View File

@ -44,26 +44,17 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
@EnableRuleMigrationSupport @EnableRuleMigrationSupport
public class SimpleFileWriterTest { public class SimpleFileWriterTest {
/**
* Create a temporary folder, used to generate files in during this test
*/
@Rule @Rule
public final TemporaryFolder testFolder = new TemporaryFolder(); public final TemporaryFolder testFolder = new TemporaryFolder();
/**
* Verify if the given writer is not 'null'
*/
@Test @Test
public void testWriterNotNull() throws Exception { public void testWriterNotNull() throws Exception {
final File temporaryFile = this.testFolder.newFile(); final File temporaryFile = this.testFolder.newFile();
new SimpleFileWriter(temporaryFile.getPath(), Assertions::assertNotNull); new SimpleFileWriter(temporaryFile.getPath(), Assertions::assertNotNull);
} }
/**
* Test if the {@link SimpleFileWriter} creates a file if it doesn't exist
*/
@Test @Test
public void testNonExistentFile() throws Exception { public void testCreatesNonExistentFile() throws Exception {
final File nonExistingFile = new File(this.testFolder.getRoot(), "non-existing-file"); final File nonExistingFile = new File(this.testFolder.getRoot(), "non-existing-file");
assertFalse(nonExistingFile.exists()); assertFalse(nonExistingFile.exists());
@ -71,11 +62,8 @@ public class SimpleFileWriterTest {
assertTrue(nonExistingFile.exists()); assertTrue(nonExistingFile.exists());
} }
/**
* Test if the data written to the file writer actually gets in the file
*/
@Test @Test
public void testActualWrite() throws Exception { public void testContentsAreWrittenToFile() throws Exception {
final String testMessage = "Test message"; final String testMessage = "Test message";
final File temporaryFile = this.testFolder.newFile(); final File temporaryFile = this.testFolder.newFile();
@ -85,17 +73,15 @@ public class SimpleFileWriterTest {
assertTrue(Files.lines(temporaryFile.toPath()).allMatch(testMessage::equals)); assertTrue(Files.lines(temporaryFile.toPath()).allMatch(testMessage::equals));
} }
/**
* Verify if an {@link IOException} during the write ripples through
*/
@Test @Test
public void testIoException() throws Exception { public void testRipplesIoExceptionOccurredWhileWriting() {
String message = "Some error";
assertThrows(IOException.class, () -> { assertThrows(IOException.class, () -> {
final File temporaryFile = this.testFolder.newFile(); final File temporaryFile = this.testFolder.newFile();
new SimpleFileWriter(temporaryFile.getPath(), writer -> { new SimpleFileWriter(temporaryFile.getPath(), writer -> {
throw new IOException(""); throw new IOException(message);
}); });
}); }, message);
} }
} }

View File

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

View File

@ -32,16 +32,16 @@ import units.CommanderUnit;
*/ */
public class Commander implements CommanderExtension { public class Commander implements CommanderExtension {
private static final Logger LOGGER = LoggerFactory.getLogger(Commander.class);
private CommanderUnit unit; private CommanderUnit unit;
public Commander(CommanderUnit commanderUnit) { public Commander(CommanderUnit commanderUnit) {
this.unit = commanderUnit; this.unit = commanderUnit;
} }
final Logger logger = LoggerFactory.getLogger(Commander.class);
@Override @Override
public void commanderReady() { public void commanderReady() {
logger.info("[Commander] " + unit.getName() + " is ready!"); LOGGER.info("[Commander] " + unit.getName() + " is ready!");
} }
} }

View File

@ -32,16 +32,16 @@ import units.SergeantUnit;
*/ */
public class Sergeant implements SergeantExtension { public class Sergeant implements SergeantExtension {
private static final Logger LOGGER = LoggerFactory.getLogger(Sergeant.class);
private SergeantUnit unit; private SergeantUnit unit;
public Sergeant(SergeantUnit sergeantUnit) { public Sergeant(SergeantUnit sergeantUnit) {
this.unit = sergeantUnit; this.unit = sergeantUnit;
} }
final Logger logger = LoggerFactory.getLogger(Sergeant.class);
@Override @Override
public void sergeantReady() { public void sergeantReady() {
logger.info("[Sergeant] " + unit.getName() + " is ready! "); LOGGER.info("[Sergeant] " + unit.getName() + " is ready! ");
} }
} }

View File

@ -31,6 +31,7 @@ import units.SoldierUnit;
* Class defining Soldier * Class defining Soldier
*/ */
public class Soldier implements SoldierExtension { public class Soldier implements SoldierExtension {
private static final Logger LOGGER = LoggerFactory.getLogger(Soldier.class);
private SoldierUnit unit; private SoldierUnit unit;
@ -38,10 +39,8 @@ public class Soldier implements SoldierExtension {
this.unit = soldierUnit; this.unit = soldierUnit;
} }
final Logger logger = LoggerFactory.getLogger(Soldier.class);
@Override @Override
public void soldierReady() { public void soldierReady() {
logger.info("[Solider] " + unit.getName() + " is ready!"); LOGGER.info("[Solider] " + unit.getName() + " is ready!");
} }
} }

View File

@ -30,7 +30,7 @@ import units.CommanderUnit;
*/ */
public class CommanderTest { public class CommanderTest {
@Test @Test
public void commanderReady() throws Exception { public void commanderReady() {
final Commander commander = new Commander(new CommanderUnit("CommanderUnitTest")); final Commander commander = new Commander(new CommanderUnit("CommanderUnitTest"));
commander.commanderReady(); commander.commanderReady();

View File

@ -33,13 +33,13 @@ import static org.junit.jupiter.api.Assertions.assertNull;
*/ */
public class CommanderUnitTest { public class CommanderUnitTest {
@Test @Test
public void getUnitExtension() throws Exception { public void getUnitExtension() {
final Unit unit = new CommanderUnit("CommanderUnitName"); final Unit unit = new CommanderUnit("CommanderUnitName");
assertNull(unit.getUnitExtension("SoldierExtension")); assertNull(unit.getUnitExtension("SoldierExtension"));
assertNull(unit.getUnitExtension("SergeantExtension")); assertNull(unit.getUnitExtension("SergeantExtension"));
assertNotNull((CommanderExtension) unit.getUnitExtension("CommanderExtension")); assertNotNull(unit.getUnitExtension("CommanderExtension"));
} }
} }

View File

@ -33,12 +33,12 @@ import static org.junit.jupiter.api.Assertions.assertNull;
*/ */
public class SergeantUnitTest { public class SergeantUnitTest {
@Test @Test
public void getUnitExtension() throws Exception { public void getUnitExtension() {
final Unit unit = new SergeantUnit("SergeantUnitName"); final Unit unit = new SergeantUnit("SergeantUnitName");
assertNull(unit.getUnitExtension("SoldierExtension")); assertNull(unit.getUnitExtension("SoldierExtension"));
assertNotNull((SergeantExtension) unit.getUnitExtension("SergeantExtension")); assertNotNull(unit.getUnitExtension("SergeantExtension"));
assertNull(unit.getUnitExtension("CommanderExtension")); assertNull(unit.getUnitExtension("CommanderExtension"));
} }

View File

@ -33,11 +33,11 @@ import static org.junit.jupiter.api.Assertions.assertNull;
*/ */
public class SoldierUnitTest { public class SoldierUnitTest {
@Test @Test
public void getUnitExtension() throws Exception { public void getUnitExtension() {
final Unit unit = new SoldierUnit("SoldierUnitName"); final Unit unit = new SoldierUnit("SoldierUnitName");
assertNotNull((SoldierExtension) unit.getUnitExtension("SoldierExtension")); assertNotNull(unit.getUnitExtension("SoldierExtension"));
assertNull(unit.getUnitExtension("SergeantExtension")); assertNull(unit.getUnitExtension("SergeantExtension"));
assertNull(unit.getUnitExtension("CommanderExtension")); assertNull(unit.getUnitExtension("CommanderExtension"));

View File

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

View File

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

View File

@ -83,7 +83,7 @@ public class FactoryKitTest {
* @param weapon weapon object which is to be verified * @param weapon weapon object which is to be verified
* @param clazz expected class of the weapon * @param clazz expected class of the weapon
*/ */
private void verifyWeapon(Weapon weapon, Class clazz) { private void verifyWeapon(Weapon weapon, Class<?> clazz) {
assertTrue(clazz.isInstance(weapon), "Weapon must be an object of: " + clazz.getName()); assertTrue(clazz.isInstance(weapon), "Weapon must be an object of: " + clazz.getName());
} }
} }

View File

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

View File

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

View File

@ -40,14 +40,14 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
public class PropertiesFeatureToggleVersionTest { public class PropertiesFeatureToggleVersionTest {
@Test @Test
public void testNullPropertiesPassed() throws Exception { public void testNullPropertiesPassed() {
assertThrows(IllegalArgumentException.class, () -> { assertThrows(IllegalArgumentException.class, () -> {
new PropertiesFeatureToggleVersion(null); new PropertiesFeatureToggleVersion(null);
}); });
} }
@Test @Test
public void testNonBooleanProperty() throws Exception { public void testNonBooleanProperty() {
assertThrows(IllegalArgumentException.class, () -> { assertThrows(IllegalArgumentException.class, () -> {
final Properties properties = new Properties(); final Properties properties = new Properties();
properties.setProperty("enhancedWelcome", "Something"); properties.setProperty("enhancedWelcome", "Something");
@ -56,7 +56,7 @@ public class PropertiesFeatureToggleVersionTest {
} }
@Test @Test
public void testFeatureTurnedOn() throws Exception { public void testFeatureTurnedOn() {
final Properties properties = new Properties(); final Properties properties = new Properties();
properties.put("enhancedWelcome", true); properties.put("enhancedWelcome", true);
Service service = new PropertiesFeatureToggleVersion(properties); Service service = new PropertiesFeatureToggleVersion(properties);
@ -66,7 +66,7 @@ public class PropertiesFeatureToggleVersionTest {
} }
@Test @Test
public void testFeatureTurnedOff() throws Exception { public void testFeatureTurnedOff() {
final Properties properties = new Properties(); final Properties properties = new Properties();
properties.put("enhancedWelcome", false); properties.put("enhancedWelcome", false);
Service service = new PropertiesFeatureToggleVersion(properties); Service service = new PropertiesFeatureToggleVersion(properties);

View File

@ -41,27 +41,27 @@ public class TieredFeatureToggleVersionTest {
final Service service = new TieredFeatureToggleVersion(); final Service service = new TieredFeatureToggleVersion();
@BeforeEach @BeforeEach
public void setUp() throws Exception { public void setUp() {
UserGroup.addUserToPaidGroup(paidUser); UserGroup.addUserToPaidGroup(paidUser);
UserGroup.addUserToFreeGroup(freeUser); UserGroup.addUserToFreeGroup(freeUser);
} }
@Test @Test
public void testGetWelcomeMessageForPaidUser() throws Exception { public void testGetWelcomeMessageForPaidUser() {
final String welcomeMessage = service.getWelcomeMessage(paidUser); final String welcomeMessage = service.getWelcomeMessage(paidUser);
final String expected = "You're amazing Jamie Coder. Thanks for paying for this awesome software."; final String expected = "You're amazing Jamie Coder. Thanks for paying for this awesome software.";
assertEquals(expected, welcomeMessage); assertEquals(expected, welcomeMessage);
} }
@Test @Test
public void testGetWelcomeMessageForFreeUser() throws Exception { public void testGetWelcomeMessageForFreeUser() {
final String welcomeMessage = service.getWelcomeMessage(freeUser); final String welcomeMessage = service.getWelcomeMessage(freeUser);
final String expected = "I suppose you can use this software."; final String expected = "I suppose you can use this software.";
assertEquals(expected, welcomeMessage); assertEquals(expected, welcomeMessage);
} }
@Test @Test
public void testIsEnhancedAlwaysTrueAsTiered() throws Exception { public void testIsEnhancedAlwaysTrueAsTiered() {
assertTrue(service.isEnhanced()); assertTrue(service.isEnhanced());
} }
} }

View File

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

View File

@ -171,11 +171,11 @@ public class SimpleFluentIterable<E> implements FluentIterable<E> {
/** /**
* @return a FluentIterable from a given iterable. Calls the SimpleFluentIterable constructor. * @return a FluentIterable from a given iterable. Calls the SimpleFluentIterable constructor.
*/ */
public static final <E> FluentIterable<E> from(Iterable<E> iterable) { public static <E> FluentIterable<E> from(Iterable<E> iterable) {
return new SimpleFluentIterable<>(iterable); return new SimpleFluentIterable<>(iterable);
} }
public static final <E> FluentIterable<E> fromCopyOf(Iterable<E> iterable) { public static <E> FluentIterable<E> fromCopyOf(Iterable<E> iterable) {
List<E> copy = FluentIterable.copyToList(iterable); List<E> copy = FluentIterable.copyToList(iterable);
return new SimpleFluentIterable<>(copy); return new SimpleFluentIterable<>(copy);
} }

View File

@ -179,15 +179,15 @@ public abstract class FluentIterableTest {
} }
@Test @Test
public void testForEach() throws Exception { public void testForEach() {
final List<Integer> integers = Arrays.asList(1, 2, 3); final List<Integer> integers = Arrays.asList(1, 2, 3);
final Consumer<Integer> consumer = mock(Consumer.class); final Consumer<Integer> consumer = mock(Consumer.class);
createFluentIterable(integers).forEach(consumer); createFluentIterable(integers).forEach(consumer);
verify(consumer, times(1)).accept(Integer.valueOf(1)); verify(consumer, times(1)).accept(1);
verify(consumer, times(1)).accept(Integer.valueOf(2)); verify(consumer, times(1)).accept(2);
verify(consumer, times(1)).accept(Integer.valueOf(3)); verify(consumer, times(1)).accept(3);
verifyNoMoreInteractions(consumer); verifyNoMoreInteractions(consumer);
} }

View File

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

View File

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

View File

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

View File

@ -36,7 +36,7 @@ public class FrontController {
} }
private Command getCommand(String request) { private Command getCommand(String request) {
Class commandClass = getCommandClass(request); Class<?> commandClass = getCommandClass(request);
try { try {
return (Command) commandClass.newInstance(); return (Command) commandClass.newInstance();
} catch (Exception e) { } catch (Exception e) {
@ -44,8 +44,8 @@ public class FrontController {
} }
} }
private static Class getCommandClass(String request) { private static Class<?> getCommandClass(String request) {
Class result; Class<?> result;
try { try {
result = Class.forName("com.iluwatar.front.controller." + request + "Command"); result = Class.forName("com.iluwatar.front.controller." + request + "Command");
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {

View File

@ -34,7 +34,7 @@ import static org.junit.jupiter.api.Assertions.assertSame;
public class ApplicationExceptionTest { public class ApplicationExceptionTest {
@Test @Test
public void testCause() throws Exception { public void testCause() {
final Exception cause = new Exception(); final Exception cause = new Exception();
assertSame(cause, new ApplicationException(cause).getCause()); assertSame(cause, new ApplicationException(cause).getCause());
} }

View File

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

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