invalidProperties =
+ null; // Invalid properties, causing NullPointerException
// Throw null pointer exception
- assertThrows(NullPointerException.class, () -> {
- // Attempt to construct a document with invalid properties
- new DocumentImplementation(invalidProperties);
- });
+ assertThrows(
+ NullPointerException.class,
+ () -> {
+ // Attempt to construct a document with invalid properties
+ new DocumentImplementation(invalidProperties);
+ });
}
@Test
@@ -97,11 +98,11 @@ class AbstractDocumentTest {
DocumentImplementation nestedDocument = new DocumentImplementation(new HashMap<>());
nestedDocument.put("nestedKey", "nestedValue");
-
document.put("nested", nestedDocument);
// Retrieving the nested document
- DocumentImplementation retrievedNestedDocument = (DocumentImplementation) document.get("nested");
+ DocumentImplementation retrievedNestedDocument =
+ (DocumentImplementation) document.get("nested");
assertNotNull(retrievedNestedDocument);
assertEquals("nestedValue", retrievedNestedDocument.get("nestedKey"));
diff --git a/abstract-document/src/test/java/com/iluwatar/abstractdocument/AppTest.java b/abstract-document/src/test/java/com/iluwatar/abstractdocument/AppTest.java
index 09af6d7b5..16dcba0db 100644
--- a/abstract-document/src/test/java/com/iluwatar/abstractdocument/AppTest.java
+++ b/abstract-document/src/test/java/com/iluwatar/abstractdocument/AppTest.java
@@ -24,25 +24,21 @@
*/
package com.iluwatar.abstractdocument;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
-/**
- * Simple App test
- */
+import org.junit.jupiter.api.Test;
+
+/** Simple App test */
class AppTest {
/**
* Issue: Add at least one assertion to this test case.
*
- * Solution: Inserted assertion to check whether the execution of the main method in {@link App}
- * throws an exception.
+ * Solution: Inserted assertion to check whether the execution of the main method in {@link
+ * App} throws an exception.
*/
-
@Test
void shouldExecuteAppWithoutException() {
assertDoesNotThrow(() -> App.main(null));
}
-
}
diff --git a/abstract-document/src/test/java/com/iluwatar/abstractdocument/DomainTest.java b/abstract-document/src/test/java/com/iluwatar/abstractdocument/DomainTest.java
index 4b52fa7a6..fc29dea45 100644
--- a/abstract-document/src/test/java/com/iluwatar/abstractdocument/DomainTest.java
+++ b/abstract-document/src/test/java/com/iluwatar/abstractdocument/DomainTest.java
@@ -24,18 +24,16 @@
*/
package com.iluwatar.abstractdocument;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
import com.iluwatar.abstractdocument.domain.Car;
import com.iluwatar.abstractdocument.domain.Part;
import com.iluwatar.abstractdocument.domain.enums.Property;
-import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Map;
+import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-/**
- * Test for Part and Car
- */
+/** Test for Part and Car */
class DomainTest {
private static final String TEST_PART_TYPE = "test-part-type";
@@ -47,11 +45,11 @@ class DomainTest {
@Test
void shouldConstructPart() {
- var partProperties = Map.of(
- Property.TYPE.toString(), TEST_PART_TYPE,
- Property.MODEL.toString(), TEST_PART_MODEL,
- Property.PRICE.toString(), (Object) TEST_PART_PRICE
- );
+ var partProperties =
+ Map.of(
+ Property.TYPE.toString(), TEST_PART_TYPE,
+ Property.MODEL.toString(), TEST_PART_MODEL,
+ Property.PRICE.toString(), (Object) TEST_PART_PRICE);
var part = new Part(partProperties);
assertEquals(TEST_PART_TYPE, part.getType().orElseThrow());
assertEquals(TEST_PART_MODEL, part.getModel().orElseThrow());
@@ -60,15 +58,14 @@ class DomainTest {
@Test
void shouldConstructCar() {
- var carProperties = Map.of(
- Property.MODEL.toString(), TEST_CAR_MODEL,
- Property.PRICE.toString(), TEST_CAR_PRICE,
- Property.PARTS.toString(), List.of(Map.of(), Map.of())
- );
+ var carProperties =
+ Map.of(
+ Property.MODEL.toString(), TEST_CAR_MODEL,
+ Property.PRICE.toString(), TEST_CAR_PRICE,
+ Property.PARTS.toString(), List.of(Map.of(), Map.of()));
var car = new Car(carProperties);
assertEquals(TEST_CAR_MODEL, car.getModel().orElseThrow());
assertEquals(TEST_CAR_PRICE, car.getPrice().orElseThrow());
assertEquals(2, car.getParts().count());
}
-
}
diff --git a/abstract-factory/pom.xml b/abstract-factory/pom.xml
index 99a92423b..60fbf72ef 100644
--- a/abstract-factory/pom.xml
+++ b/abstract-factory/pom.xml
@@ -34,6 +34,14 @@
abstract-factory
+
+ org.slf4j
+ slf4j-api
+
+
+ ch.qos.logback
+ logback-classic
+
org.junit.jupiter
junit-jupiter-engine
diff --git a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/App.java b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/App.java
index e360822ca..798cbe4fd 100644
--- a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/App.java
+++ b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/App.java
@@ -74,6 +74,7 @@ public class App implements Runnable {
/**
* Creates kingdom.
+ *
* @param kingdomType type of Kingdom
*/
public void createKingdom(final Kingdom.FactoryMaker.KingdomType kingdomType) {
@@ -82,4 +83,4 @@ public class App implements Runnable {
kingdom.setCastle(kingdomFactory.createCastle());
kingdom.setArmy(kingdomFactory.createArmy());
}
-}
\ No newline at end of file
+}
diff --git a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/Army.java b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/Army.java
index 3efec4c87..78c75323f 100644
--- a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/Army.java
+++ b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/Army.java
@@ -24,9 +24,7 @@
*/
package com.iluwatar.abstractfactory;
-/**
- * Army interface.
- */
+/** Army interface. */
public interface Army {
String getDescription();
diff --git a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/Castle.java b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/Castle.java
index 8fca06819..ee1e16f3c 100644
--- a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/Castle.java
+++ b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/Castle.java
@@ -24,9 +24,7 @@
*/
package com.iluwatar.abstractfactory;
-/**
- * Castle interface.
- */
+/** Castle interface. */
public interface Castle {
String getDescription();
diff --git a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfArmy.java b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfArmy.java
index 055d2cc75..d7e46c145 100644
--- a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfArmy.java
+++ b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfArmy.java
@@ -24,9 +24,7 @@
*/
package com.iluwatar.abstractfactory;
-/**
- * ElfArmy.
- */
+/** ElfArmy. */
public class ElfArmy implements Army {
static final String DESCRIPTION = "This is the elven army!";
diff --git a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfCastle.java b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfCastle.java
index 5b0c26c42..136afb11f 100644
--- a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfCastle.java
+++ b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfCastle.java
@@ -24,9 +24,7 @@
*/
package com.iluwatar.abstractfactory;
-/**
- * ElfCastle.
- */
+/** ElfCastle. */
public class ElfCastle implements Castle {
static final String DESCRIPTION = "This is the elven castle!";
diff --git a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfKing.java b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfKing.java
index 0696e1d09..9b0d3a6f1 100644
--- a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfKing.java
+++ b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfKing.java
@@ -24,9 +24,7 @@
*/
package com.iluwatar.abstractfactory;
-/**
- * ElfKing.
- */
+/** ElfKing. */
public class ElfKing implements King {
static final String DESCRIPTION = "This is the elven king!";
diff --git a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfKingdomFactory.java b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfKingdomFactory.java
index f45d2ee03..b09a2f47c 100644
--- a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfKingdomFactory.java
+++ b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfKingdomFactory.java
@@ -24,9 +24,7 @@
*/
package com.iluwatar.abstractfactory;
-/**
- * ElfKingdomFactory concrete factory.
- */
+/** ElfKingdomFactory concrete factory. */
public class ElfKingdomFactory implements KingdomFactory {
@Override
@@ -43,5 +41,4 @@ public class ElfKingdomFactory implements KingdomFactory {
public Army createArmy() {
return new ElfArmy();
}
-
}
diff --git a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/King.java b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/King.java
index 01af71a6a..9f65ed434 100644
--- a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/King.java
+++ b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/King.java
@@ -24,9 +24,7 @@
*/
package com.iluwatar.abstractfactory;
-/**
- * King interface.
- */
+/** King interface. */
public interface King {
String getDescription();
diff --git a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/Kingdom.java b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/Kingdom.java
index db1c65ca4..d1f85a6a4 100644
--- a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/Kingdom.java
+++ b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/Kingdom.java
@@ -27,9 +27,7 @@ package com.iluwatar.abstractfactory;
import lombok.Getter;
import lombok.Setter;
-/**
- * Helper class to manufacture {@link KingdomFactory} beans.
- */
+/** Helper class to manufacture {@link KingdomFactory} beans. */
@Getter
@Setter
public class Kingdom {
@@ -38,21 +36,16 @@ public class Kingdom {
private Castle castle;
private Army army;
- /**
- * The factory of kingdom factories.
- */
+ /** The factory of kingdom factories. */
public static class FactoryMaker {
- /**
- * Enumeration for the different types of Kingdoms.
- */
+ /** Enumeration for the different types of Kingdoms. */
public enum KingdomType {
- ELF, ORC
+ ELF,
+ ORC
}
- /**
- * The factory method to create KingdomFactory concrete objects.
- */
+ /** The factory method to create KingdomFactory concrete objects. */
public static KingdomFactory makeFactory(KingdomType type) {
return switch (type) {
case ELF -> new ElfKingdomFactory();
diff --git a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/KingdomFactory.java b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/KingdomFactory.java
index fdfe19dc0..199c6697d 100644
--- a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/KingdomFactory.java
+++ b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/KingdomFactory.java
@@ -24,9 +24,7 @@
*/
package com.iluwatar.abstractfactory;
-/**
- * KingdomFactory factory interface.
- */
+/** KingdomFactory factory interface. */
public interface KingdomFactory {
Castle createCastle();
@@ -34,5 +32,4 @@ public interface KingdomFactory {
King createKing();
Army createArmy();
-
}
diff --git a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcArmy.java b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcArmy.java
index d687c32e8..31ed6896d 100644
--- a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcArmy.java
+++ b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcArmy.java
@@ -24,9 +24,7 @@
*/
package com.iluwatar.abstractfactory;
-/**
- * OrcArmy.
- */
+/** OrcArmy. */
public class OrcArmy implements Army {
static final String DESCRIPTION = "This is the orc army!";
diff --git a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcCastle.java b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcCastle.java
index f842bb3c6..bdae5709a 100644
--- a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcCastle.java
+++ b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcCastle.java
@@ -24,9 +24,7 @@
*/
package com.iluwatar.abstractfactory;
-/**
- * OrcCastle.
- */
+/** OrcCastle. */
public class OrcCastle implements Castle {
static final String DESCRIPTION = "This is the orc castle!";
diff --git a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcKing.java b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcKing.java
index e25d93bfb..7f106d45a 100644
--- a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcKing.java
+++ b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcKing.java
@@ -24,9 +24,7 @@
*/
package com.iluwatar.abstractfactory;
-/**
- * OrcKing.
- */
+/** OrcKing. */
public class OrcKing implements King {
static final String DESCRIPTION = "This is the orc king!";
diff --git a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcKingdomFactory.java b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcKingdomFactory.java
index c80728a87..82d258570 100644
--- a/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcKingdomFactory.java
+++ b/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcKingdomFactory.java
@@ -24,9 +24,7 @@
*/
package com.iluwatar.abstractfactory;
-/**
- * OrcKingdomFactory concrete factory.
- */
+/** OrcKingdomFactory concrete factory. */
public class OrcKingdomFactory implements KingdomFactory {
@Override
diff --git a/abstract-factory/src/test/java/com/iluwatar/abstractfactory/AbstractFactoryTest.java b/abstract-factory/src/test/java/com/iluwatar/abstractfactory/AbstractFactoryTest.java
index 0f7708e07..b5dde940c 100644
--- a/abstract-factory/src/test/java/com/iluwatar/abstractfactory/AbstractFactoryTest.java
+++ b/abstract-factory/src/test/java/com/iluwatar/abstractfactory/AbstractFactoryTest.java
@@ -24,14 +24,12 @@
*/
package com.iluwatar.abstractfactory;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
-/**
- * Tests for abstract factory.
- */
+import org.junit.jupiter.api.Test;
+
+/** Tests for abstract factory. */
class AbstractFactoryTest {
private final App app = new App();
diff --git a/abstract-factory/src/test/java/com/iluwatar/abstractfactory/AppTest.java b/abstract-factory/src/test/java/com/iluwatar/abstractfactory/AppTest.java
index 736a7f8b7..9f53691a5 100644
--- a/abstract-factory/src/test/java/com/iluwatar/abstractfactory/AppTest.java
+++ b/abstract-factory/src/test/java/com/iluwatar/abstractfactory/AppTest.java
@@ -24,18 +24,16 @@
*/
package com.iluwatar.abstractfactory;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
-/**
- * Check whether the execution of the main method in {@link App} throws an exception.
- */
+import org.junit.jupiter.api.Test;
+
+/** Check whether the execution of the main method in {@link App} throws an exception. */
class AppTest {
-
+
@Test
void shouldExecuteApplicationWithoutException() {
- assertDoesNotThrow(() -> App.main(new String[]{}));
+ assertDoesNotThrow(() -> App.main(new String[] {}));
}
}
diff --git a/active-object/pom.xml b/active-object/pom.xml
index 08a09e664..aa26dbbe2 100644
--- a/active-object/pom.xml
+++ b/active-object/pom.xml
@@ -34,6 +34,14 @@
active-object
+
+ org.slf4j
+ slf4j-api
+
+
+ ch.qos.logback
+ logback-classic
+
org.junit.jupiter
junit-jupiter-engine
diff --git a/active-object/src/main/java/com/iluwatar/activeobject/ActiveCreature.java b/active-object/src/main/java/com/iluwatar/activeobject/ActiveCreature.java
index c7b661845..5a440020c 100644
--- a/active-object/src/main/java/com/iluwatar/activeobject/ActiveCreature.java
+++ b/active-object/src/main/java/com/iluwatar/activeobject/ActiveCreature.java
@@ -29,86 +29,87 @@ import java.util.concurrent.LinkedBlockingQueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/**
- * ActiveCreature class is the base of the active object example.
- *
- */
+/** ActiveCreature class is the base of the active object example. */
public abstract class ActiveCreature {
-
+
private static final Logger logger = LoggerFactory.getLogger(ActiveCreature.class.getName());
private BlockingQueue requests;
-
+
private String name;
-
+
private Thread thread; // Thread of execution.
-
+
private int status; // status of the thread of execution.
- /**
- * Constructor and initialization.
- */
+ /** Constructor and initialization. */
protected ActiveCreature(String name) {
this.name = name;
this.status = 0;
this.requests = new LinkedBlockingQueue<>();
- thread = new Thread(() -> {
- boolean infinite = true;
- while (infinite) {
- try {
- requests.take().run();
- } catch (InterruptedException e) {
- if (this.status != 0) {
- logger.error("Thread was interrupted. --> {}", e.getMessage());
- }
- infinite = false;
- Thread.currentThread().interrupt();
- }
- }
- });
+ thread =
+ new Thread(
+ () -> {
+ boolean infinite = true;
+ while (infinite) {
+ try {
+ requests.take().run();
+ } catch (InterruptedException e) {
+ if (this.status != 0) {
+ logger.error("Thread was interrupted. --> {}", e.getMessage());
+ }
+ infinite = false;
+ Thread.currentThread().interrupt();
+ }
+ }
+ });
thread.start();
}
/**
* Eats the porridge.
+ *
* @throws InterruptedException due to firing a new Runnable.
*/
public void eat() throws InterruptedException {
- requests.put(() -> {
- logger.info("{} is eating!", name());
- logger.info("{} has finished eating!", name());
- });
+ requests.put(
+ () -> {
+ logger.info("{} is eating!", name());
+ logger.info("{} has finished eating!", name());
+ });
}
/**
* Roam the wastelands.
+ *
* @throws InterruptedException due to firing a new Runnable.
*/
public void roam() throws InterruptedException {
- requests.put(() ->
- logger.info("{} has started to roam in the wastelands.", name())
- );
+ requests.put(() -> logger.info("{} has started to roam in the wastelands.", name()));
}
-
+
/**
* Returns the name of the creature.
+ *
* @return the name of the creature.
*/
public String name() {
return this.name;
}
-
+
/**
* Kills the thread of execution.
+ *
* @param status of the thread of execution. 0 == OK, the rest is logging an error.
*/
public void kill(int status) {
this.status = status;
this.thread.interrupt();
}
-
+
/**
* Returns the status of the thread of execution.
+ *
* @return the status of the thread of execution.
*/
public int getStatus() {
diff --git a/active-object/src/main/java/com/iluwatar/activeobject/App.java b/active-object/src/main/java/com/iluwatar/activeobject/App.java
index b88b4c559..ca3a5526e 100644
--- a/active-object/src/main/java/com/iluwatar/activeobject/App.java
+++ b/active-object/src/main/java/com/iluwatar/activeobject/App.java
@@ -30,17 +30,17 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * The Active Object pattern helps to solve synchronization difficulties without using
- * 'synchronized' methods. The active object will contain a thread-safe data structure
- * (such as BlockingQueue) and use to synchronize method calls by moving the logic of the method
- * into an invocator(usually a Runnable) and store it in the DSA.
- *
+ * The Active Object pattern helps to solve synchronization difficulties without using
+ * 'synchronized' methods. The active object will contain a thread-safe data structure (such as
+ * BlockingQueue) and use to synchronize method calls by moving the logic of the method into an
+ * invocator(usually a Runnable) and store it in the DSA.
+ *
* In this example, we fire 20 threads to modify a value in the target class.
*/
public class App implements Runnable {
-
+
private static final Logger logger = LoggerFactory.getLogger(App.class.getName());
-
+
private static final int NUM_CREATURES = 3;
/**
@@ -48,11 +48,11 @@ public class App implements Runnable {
*
* @param args command line arguments.
*/
- public static void main(String[] args) {
+ public static void main(String[] args) {
var app = new App();
app.run();
}
-
+
@Override
public void run() {
List creatures = new ArrayList<>();
diff --git a/active-object/src/main/java/com/iluwatar/activeobject/Orc.java b/active-object/src/main/java/com/iluwatar/activeobject/Orc.java
index 8f5570a86..30adde034 100644
--- a/active-object/src/main/java/com/iluwatar/activeobject/Orc.java
+++ b/active-object/src/main/java/com/iluwatar/activeobject/Orc.java
@@ -24,14 +24,10 @@
*/
package com.iluwatar.activeobject;
-/**
- * An implementation of the ActiveCreature class.
- *
- */
+/** An implementation of the ActiveCreature class. */
public class Orc extends ActiveCreature {
public Orc(String name) {
super(name);
}
-
}
diff --git a/active-object/src/test/java/com/iluwatar/activeobject/ActiveCreatureTest.java b/active-object/src/test/java/com/iluwatar/activeobject/ActiveCreatureTest.java
index 5441ed6b0..be79e2fb5 100644
--- a/active-object/src/test/java/com/iluwatar/activeobject/ActiveCreatureTest.java
+++ b/active-object/src/test/java/com/iluwatar/activeobject/ActiveCreatureTest.java
@@ -27,17 +27,16 @@ package com.iluwatar.activeobject;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
-class ActiveCreatureTest {
-
- @Test
- void executionTest() throws InterruptedException {
- ActiveCreature orc = new Orc("orc1");
- assertEquals("orc1",orc.name());
- assertEquals(0,orc.getStatus());
- orc.eat();
- orc.roam();
- orc.kill(0);
- }
-
+class ActiveCreatureTest {
+
+ @Test
+ void executionTest() throws InterruptedException {
+ ActiveCreature orc = new Orc("orc1");
+ assertEquals("orc1", orc.name());
+ assertEquals(0, orc.getStatus());
+ orc.eat();
+ orc.roam();
+ orc.kill(0);
+ }
}
diff --git a/active-object/src/test/java/com/iluwatar/activeobject/AppTest.java b/active-object/src/test/java/com/iluwatar/activeobject/AppTest.java
index 8ef2f142c..559e2a1f5 100644
--- a/active-object/src/test/java/com/iluwatar/activeobject/AppTest.java
+++ b/active-object/src/test/java/com/iluwatar/activeobject/AppTest.java
@@ -28,11 +28,10 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import org.junit.jupiter.api.Test;
-
class AppTest {
- @Test
- void shouldExecuteApplicationWithoutException() {
- assertDoesNotThrow(() -> App.main(new String[]{}));
- }
+ @Test
+ void shouldExecuteApplicationWithoutException() {
+ assertDoesNotThrow(() -> App.main(new String[] {}));
+ }
}
diff --git a/acyclic-visitor/pom.xml b/acyclic-visitor/pom.xml
index 52604048e..b4f5646b7 100644
--- a/acyclic-visitor/pom.xml
+++ b/acyclic-visitor/pom.xml
@@ -34,6 +34,14 @@
acyclic-visitor
+
+ org.slf4j
+ slf4j-api
+
+
+ ch.qos.logback
+ logback-classic
+
org.junit.jupiter
junit-jupiter-engine
diff --git a/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/AllModemVisitor.java b/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/AllModemVisitor.java
index 38da4923a..a3b1679a2 100644
--- a/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/AllModemVisitor.java
+++ b/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/AllModemVisitor.java
@@ -28,6 +28,4 @@ package com.iluwatar.acyclicvisitor;
* All ModemVisitor interface extends all visitor interfaces. This interface provides ease of use
* when a visitor needs to visit all modem types.
*/
-public interface AllModemVisitor extends ZoomVisitor, HayesVisitor {
-
-}
+public interface AllModemVisitor extends ZoomVisitor, HayesVisitor {}
diff --git a/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/App.java b/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/App.java
index 64d4d039a..3b7c6cd61 100644
--- a/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/App.java
+++ b/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/App.java
@@ -37,9 +37,7 @@ package com.iluwatar.acyclicvisitor;
*/
public class App {
- /**
- * Program's entry point.
- */
+ /** Program's entry point. */
public static void main(String[] args) {
var conUnix = new ConfigureForUnixVisitor();
var conDos = new ConfigureForDosVisitor();
@@ -50,6 +48,6 @@ public class App {
hayes.accept(conDos); // Hayes modem with Dos configurator
zoom.accept(conDos); // Zoom modem with Dos configurator
hayes.accept(conUnix); // Hayes modem with Unix configurator
- zoom.accept(conUnix); // Zoom modem with Unix configurator
+ zoom.accept(conUnix); // Zoom modem with Unix configurator
}
}
diff --git a/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ConfigureForDosVisitor.java b/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ConfigureForDosVisitor.java
index 9f9f29187..267a8d66a 100644
--- a/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ConfigureForDosVisitor.java
+++ b/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ConfigureForDosVisitor.java
@@ -27,8 +27,7 @@ package com.iluwatar.acyclicvisitor;
import lombok.extern.slf4j.Slf4j;
/**
- * ConfigureForDosVisitor class implements both zoom's and hayes' visit method for Dos
- * manufacturer.
+ * ConfigureForDosVisitor class implements both zoom's and hayes' visit method for Dos manufacturer.
*/
@Slf4j
public class ConfigureForDosVisitor implements AllModemVisitor {
diff --git a/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ConfigureForUnixVisitor.java b/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ConfigureForUnixVisitor.java
index 097f19c0d..d9fd14f69 100644
--- a/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ConfigureForUnixVisitor.java
+++ b/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ConfigureForUnixVisitor.java
@@ -37,4 +37,4 @@ public class ConfigureForUnixVisitor implements ZoomVisitor {
public void visit(Zoom zoom) {
LOGGER.info(zoom + " used with Unix configurator.");
}
-}
\ No newline at end of file
+}
diff --git a/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/Hayes.java b/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/Hayes.java
index 384df8a4d..e0b2fcc2b 100644
--- a/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/Hayes.java
+++ b/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/Hayes.java
@@ -26,15 +26,11 @@ package com.iluwatar.acyclicvisitor;
import lombok.extern.slf4j.Slf4j;
-/**
- * Hayes class implements its accept method.
- */
+/** Hayes class implements its accept method. */
@Slf4j
public class Hayes implements Modem {
- /**
- * Accepts all visitors but honors only HayesVisitor.
- */
+ /** Accepts all visitors but honors only HayesVisitor. */
@Override
public void accept(ModemVisitor modemVisitor) {
if (modemVisitor instanceof HayesVisitor) {
@@ -42,12 +38,9 @@ public class Hayes implements Modem {
} else {
LOGGER.info("Only HayesVisitor is allowed to visit Hayes modem");
}
-
}
- /**
- * Hayes' modem's toString method.
- */
+ /** Hayes' modem's toString method. */
@Override
public String toString() {
return "Hayes modem";
diff --git a/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/HayesVisitor.java b/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/HayesVisitor.java
index a33c87cfa..aad9b9709 100644
--- a/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/HayesVisitor.java
+++ b/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/HayesVisitor.java
@@ -24,9 +24,7 @@
*/
package com.iluwatar.acyclicvisitor;
-/**
- * HayesVisitor interface.
- */
+/** HayesVisitor interface. */
public interface HayesVisitor extends ModemVisitor {
void visit(Hayes hayes);
}
diff --git a/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/Modem.java b/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/Modem.java
index fd15ee422..855257445 100644
--- a/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/Modem.java
+++ b/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/Modem.java
@@ -24,10 +24,7 @@
*/
package com.iluwatar.acyclicvisitor;
-/**
- * //Modem abstract class.
- * converted to an interface
- */
+/** //Modem abstract class. converted to an interface */
public interface Modem {
void accept(ModemVisitor modemVisitor);
}
diff --git a/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/Zoom.java b/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/Zoom.java
index e9f02e1ad..59b50a54a 100644
--- a/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/Zoom.java
+++ b/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/Zoom.java
@@ -26,15 +26,11 @@ package com.iluwatar.acyclicvisitor;
import lombok.extern.slf4j.Slf4j;
-/**
- * Zoom class implements its accept method.
- */
+/** Zoom class implements its accept method. */
@Slf4j
public class Zoom implements Modem {
- /**
- * Accepts all visitors but honors only ZoomVisitor.
- */
+ /** Accepts all visitors but honors only ZoomVisitor. */
@Override
public void accept(ModemVisitor modemVisitor) {
if (modemVisitor instanceof ZoomVisitor) {
@@ -44,9 +40,7 @@ public class Zoom implements Modem {
}
}
- /**
- * Zoom modem's toString method.
- */
+ /** Zoom modem's toString method. */
@Override
public String toString() {
return "Zoom modem";
diff --git a/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ZoomVisitor.java b/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ZoomVisitor.java
index 639af1c65..5388ded6f 100644
--- a/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ZoomVisitor.java
+++ b/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ZoomVisitor.java
@@ -24,9 +24,7 @@
*/
package com.iluwatar.acyclicvisitor;
-/**
- * ZoomVisitor interface.
- */
+/** ZoomVisitor interface. */
public interface ZoomVisitor extends ModemVisitor {
void visit(Zoom zoom);
}
diff --git a/acyclic-visitor/src/test/java/com/iluwatar/acyclicvisitor/AppTest.java b/acyclic-visitor/src/test/java/com/iluwatar/acyclicvisitor/AppTest.java
index 9cc242d8f..7a21498a6 100644
--- a/acyclic-visitor/src/test/java/com/iluwatar/acyclicvisitor/AppTest.java
+++ b/acyclic-visitor/src/test/java/com/iluwatar/acyclicvisitor/AppTest.java
@@ -24,25 +24,22 @@
*/
package com.iluwatar.acyclicvisitor;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
-/**
- * Tests that the Acyclic Visitor example runs without errors.
- */
+import org.junit.jupiter.api.Test;
+
+/** Tests that the Acyclic Visitor example runs without errors. */
class AppTest {
/**
* Issue: Add at least one assertion to this test case.
*
- * Solution: Inserted assertion to check whether the execution of the main method in {@link App}
- * throws an exception.
+ * Solution: Inserted assertion to check whether the execution of the main method in {@link
+ * App} throws an exception.
*/
-
@Test
void shouldExecuteApplicationWithoutException() {
- assertDoesNotThrow(() -> App.main(new String[]{}));
+ assertDoesNotThrow(() -> App.main(new String[] {}));
}
-}
\ No newline at end of file
+}
diff --git a/acyclic-visitor/src/test/java/com/iluwatar/acyclicvisitor/HayesTest.java b/acyclic-visitor/src/test/java/com/iluwatar/acyclicvisitor/HayesTest.java
index 66640e3ca..a989d9287 100644
--- a/acyclic-visitor/src/test/java/com/iluwatar/acyclicvisitor/HayesTest.java
+++ b/acyclic-visitor/src/test/java/com/iluwatar/acyclicvisitor/HayesTest.java
@@ -24,14 +24,12 @@
*/
package com.iluwatar.acyclicvisitor;
-import org.junit.jupiter.api.Test;
-
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;
-/**
- * Hayes test class
- */
+import org.junit.jupiter.api.Test;
+
+/** Hayes test class */
class HayesTest {
@Test
diff --git a/acyclic-visitor/src/test/java/com/iluwatar/acyclicvisitor/ZoomTest.java b/acyclic-visitor/src/test/java/com/iluwatar/acyclicvisitor/ZoomTest.java
index df7b7e840..d5fe79965 100644
--- a/acyclic-visitor/src/test/java/com/iluwatar/acyclicvisitor/ZoomTest.java
+++ b/acyclic-visitor/src/test/java/com/iluwatar/acyclicvisitor/ZoomTest.java
@@ -24,16 +24,13 @@
*/
package com.iluwatar.acyclicvisitor;
-
-import org.junit.jupiter.api.Test;
-
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
-/**
- * Zoom test class
- */
+import org.junit.jupiter.api.Test;
+
+/** Zoom test class */
class ZoomTest {
@Test
diff --git a/adapter/pom.xml b/adapter/pom.xml
index d54cbd048..6e7f45a51 100644
--- a/adapter/pom.xml
+++ b/adapter/pom.xml
@@ -34,6 +34,14 @@
adapter
+
+ org.slf4j
+ slf4j-api
+
+
+ ch.qos.logback
+ logback-classic
+
org.junit.jupiter
junit-jupiter-engine
diff --git a/adapter/src/main/java/com/iluwatar/adapter/App.java b/adapter/src/main/java/com/iluwatar/adapter/App.java
index 1f572813c..a4fa74274 100644
--- a/adapter/src/main/java/com/iluwatar/adapter/App.java
+++ b/adapter/src/main/java/com/iluwatar/adapter/App.java
@@ -37,16 +37,15 @@ package com.iluwatar.adapter;
* The Adapter ({@link FishingBoatAdapter}) converts the interface of the adaptee class ({@link
* FishingBoat}) into a suitable one expected by the client ({@link RowingBoat}).
*
- *
The story of this implementation is this.
Pirates are coming! we need a {@link
- * RowingBoat} to flee! We have a {@link FishingBoat} and our captain. We have no time to make up a
- * new ship! we need to reuse this {@link FishingBoat}. The captain needs a rowing boat which he can
- * operate. The spec is in {@link RowingBoat}. We will use the Adapter pattern to reuse {@link
- * FishingBoat}.
+ *
The story of this implementation is this.
+ * Pirates are coming! we need a {@link RowingBoat} to flee! We have a {@link FishingBoat} and our
+ * captain. We have no time to make up a new ship! we need to reuse this {@link FishingBoat}. The
+ * captain needs a rowing boat which he can operate. The spec is in {@link RowingBoat}. We will use
+ * the Adapter pattern to reuse {@link FishingBoat}.
*/
public final class App {
- private App() {
- }
+ private App() {}
/**
* Program entry point.
diff --git a/adapter/src/main/java/com/iluwatar/adapter/Captain.java b/adapter/src/main/java/com/iluwatar/adapter/Captain.java
index 3d6d7746d..3b771e9d8 100644
--- a/adapter/src/main/java/com/iluwatar/adapter/Captain.java
+++ b/adapter/src/main/java/com/iluwatar/adapter/Captain.java
@@ -29,7 +29,8 @@ import lombok.NoArgsConstructor;
import lombok.Setter;
/**
- * The Captain uses {@link RowingBoat} to sail.
This is the client in the pattern.
+ * The Captain uses {@link RowingBoat} to sail.
+ * This is the client in the pattern.
*/
@Setter
@NoArgsConstructor
@@ -41,5 +42,4 @@ public final class Captain {
void row() {
rowingBoat.row();
}
-
}
diff --git a/adapter/src/main/java/com/iluwatar/adapter/FishingBoat.java b/adapter/src/main/java/com/iluwatar/adapter/FishingBoat.java
index e692d8598..dd39f88f1 100644
--- a/adapter/src/main/java/com/iluwatar/adapter/FishingBoat.java
+++ b/adapter/src/main/java/com/iluwatar/adapter/FishingBoat.java
@@ -36,5 +36,4 @@ final class FishingBoat {
void sail() {
LOGGER.info("The fishing boat is sailing");
}
-
}
diff --git a/adapter/src/main/java/com/iluwatar/adapter/RowingBoat.java b/adapter/src/main/java/com/iluwatar/adapter/RowingBoat.java
index c8714ef91..55eeeaf4b 100644
--- a/adapter/src/main/java/com/iluwatar/adapter/RowingBoat.java
+++ b/adapter/src/main/java/com/iluwatar/adapter/RowingBoat.java
@@ -25,10 +25,10 @@
package com.iluwatar.adapter;
/**
- * The interface expected by the client.
A rowing boat is rowed to move.
+ * The interface expected by the client.
+ * A rowing boat is rowed to move.
*/
public interface RowingBoat {
void row();
-
}
diff --git a/adapter/src/test/java/com/iluwatar/adapter/AdapterPatternTest.java b/adapter/src/test/java/com/iluwatar/adapter/AdapterPatternTest.java
index 10024ff0d..bc4984da3 100644
--- a/adapter/src/test/java/com/iluwatar/adapter/AdapterPatternTest.java
+++ b/adapter/src/test/java/com/iluwatar/adapter/AdapterPatternTest.java
@@ -24,17 +24,15 @@
*/
package com.iluwatar.adapter;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import java.util.HashMap;
-import java.util.Map;
-
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
-/**
- * Tests for the adapter pattern.
- */
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/** Tests for the adapter pattern. */
class AdapterPatternTest {
private Map beans;
@@ -43,9 +41,7 @@ class AdapterPatternTest {
private static final String ROWING_BEAN = "captain";
- /**
- * This method runs before the test execution and sets the bean objects in the beans Map.
- */
+ /** This method runs before the test execution and sets the bean objects in the beans Map. */
@BeforeEach
void setup() {
beans = new HashMap<>();
diff --git a/adapter/src/test/java/com/iluwatar/adapter/AppTest.java b/adapter/src/test/java/com/iluwatar/adapter/AppTest.java
index be51d2687..a2cc4c22b 100644
--- a/adapter/src/test/java/com/iluwatar/adapter/AppTest.java
+++ b/adapter/src/test/java/com/iluwatar/adapter/AppTest.java
@@ -24,23 +24,17 @@
*/
package com.iluwatar.adapter;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
-/**
- * Tests that Adapter example runs without errors.
- */
+import org.junit.jupiter.api.Test;
+
+/** Tests that Adapter example runs without errors. */
class AppTest {
- /**
- * Check whether the execution of the main method in {@link App}
- * throws an exception.
- */
-
+ /** Check whether the execution of the main method in {@link App} throws an exception. */
@Test
void shouldExecuteApplicationWithoutException() {
- assertDoesNotThrow(() -> App.main(new String[]{}));
+ assertDoesNotThrow(() -> App.main(new String[] {}));
}
}
diff --git a/ambassador/pom.xml b/ambassador/pom.xml
index a6d702426..15e4a07f0 100644
--- a/ambassador/pom.xml
+++ b/ambassador/pom.xml
@@ -34,6 +34,14 @@
4.0.0
ambassador
+
+ org.slf4j
+ slf4j-api
+
+
+ ch.qos.logback
+ logback-classic
+
org.junit.jupiter
junit-jupiter-engine
diff --git a/ambassador/src/main/java/com/iluwatar/ambassador/App.java b/ambassador/src/main/java/com/iluwatar/ambassador/App.java
index ff025d9b2..8de149fe0 100644
--- a/ambassador/src/main/java/com/iluwatar/ambassador/App.java
+++ b/ambassador/src/main/java/com/iluwatar/ambassador/App.java
@@ -28,8 +28,8 @@ package com.iluwatar.ambassador;
* The ambassador pattern creates a helper service that sends network requests on behalf of a
* client. It is often used in cloud-based applications to offload features of a remote service.
*
- * An ambassador service can be thought of as an out-of-process proxy that is co-located with
- * the client. Similar to the proxy design pattern, the ambassador service provides an interface for
+ *
An ambassador service can be thought of as an out-of-process proxy that is co-located with the
+ * client. Similar to the proxy design pattern, the ambassador service provides an interface for
* another remote service. In addition to the interface, the ambassador provides extra functionality
* and features, specifically offloaded common connectivity tasks. This usually consists of
* monitoring, logging, routing, security etc. This is extremely useful in legacy applications where
@@ -37,14 +37,11 @@ package com.iluwatar.ambassador;
* capabilities.
*
*
In this example, we will the ({@link ServiceAmbassador}) class represents the ambassador while
- * the
- * ({@link RemoteService}) class represents a remote application.
+ * the ({@link RemoteService}) class represents a remote application.
*/
public class App {
- /**
- * Entry point.
- */
+ /** Entry point. */
public static void main(String[] args) {
var host1 = new Client();
var host2 = new Client();
diff --git a/ambassador/src/main/java/com/iluwatar/ambassador/Client.java b/ambassador/src/main/java/com/iluwatar/ambassador/Client.java
index d0f81c1dd..0baabf4ff 100644
--- a/ambassador/src/main/java/com/iluwatar/ambassador/Client.java
+++ b/ambassador/src/main/java/com/iluwatar/ambassador/Client.java
@@ -26,9 +26,7 @@ package com.iluwatar.ambassador;
import lombok.extern.slf4j.Slf4j;
-/**
- * A simple Client.
- */
+/** A simple Client. */
@Slf4j
public class Client {
diff --git a/ambassador/src/main/java/com/iluwatar/ambassador/RemoteService.java b/ambassador/src/main/java/com/iluwatar/ambassador/RemoteService.java
index eba634494..d99348040 100644
--- a/ambassador/src/main/java/com/iluwatar/ambassador/RemoteService.java
+++ b/ambassador/src/main/java/com/iluwatar/ambassador/RemoteService.java
@@ -29,9 +29,7 @@ import static java.lang.Thread.sleep;
import com.iluwatar.ambassador.util.RandomProvider;
import lombok.extern.slf4j.Slf4j;
-/**
- * A remote legacy application represented by a Singleton implementation.
- */
+/** A remote legacy application represented by a Singleton implementation. */
@Slf4j
public class RemoteService implements RemoteServiceInterface {
private static final int THRESHOLD = 200;
@@ -49,9 +47,7 @@ public class RemoteService implements RemoteServiceInterface {
this(Math::random);
}
- /**
- * This constructor is used for testing purposes only.
- */
+ /** This constructor is used for testing purposes only. */
RemoteService(RandomProvider randomProvider) {
this.randomProvider = randomProvider;
}
@@ -75,7 +71,8 @@ public class RemoteService implements RemoteServiceInterface {
LOGGER.error("Thread sleep state interrupted", e);
Thread.currentThread().interrupt();
}
- return waitTime <= THRESHOLD ? value * 10
+ return waitTime <= THRESHOLD
+ ? value * 10
: RemoteServiceStatus.FAILURE.getRemoteServiceStatusValue();
}
}
diff --git a/ambassador/src/main/java/com/iluwatar/ambassador/RemoteServiceInterface.java b/ambassador/src/main/java/com/iluwatar/ambassador/RemoteServiceInterface.java
index 104d81ec2..aa6012bae 100644
--- a/ambassador/src/main/java/com/iluwatar/ambassador/RemoteServiceInterface.java
+++ b/ambassador/src/main/java/com/iluwatar/ambassador/RemoteServiceInterface.java
@@ -24,9 +24,7 @@
*/
package com.iluwatar.ambassador;
-/**
- * Interface shared by ({@link RemoteService}) and ({@link ServiceAmbassador}).
- */
+/** Interface shared by ({@link RemoteService}) and ({@link ServiceAmbassador}). */
interface RemoteServiceInterface {
long doRemoteFunction(int value);
diff --git a/ambassador/src/main/java/com/iluwatar/ambassador/RemoteServiceStatus.java b/ambassador/src/main/java/com/iluwatar/ambassador/RemoteServiceStatus.java
index 8f1a0a1a4..8549ed724 100644
--- a/ambassador/src/main/java/com/iluwatar/ambassador/RemoteServiceStatus.java
+++ b/ambassador/src/main/java/com/iluwatar/ambassador/RemoteServiceStatus.java
@@ -29,17 +29,14 @@ import lombok.Getter;
/**
* Holds information regarding the status of the Remote Service.
*
- *
This Enum replaces the integer value previously
- * stored in {@link RemoteServiceInterface} as SonarCloud was identifying
- * it as an issue. All test cases have been checked after changes,
- * without failures.
+ * This Enum replaces the integer value previously stored in {@link RemoteServiceInterface} as
+ * SonarCloud was identifying it as an issue. All test cases have been checked after changes,
+ * without failures.
*/
-
public enum RemoteServiceStatus {
FAILURE(-1);
- @Getter
- private final long remoteServiceStatusValue;
+ @Getter private final long remoteServiceStatusValue;
RemoteServiceStatus(long remoteServiceStatusValue) {
this.remoteServiceStatusValue = remoteServiceStatusValue;
diff --git a/ambassador/src/main/java/com/iluwatar/ambassador/ServiceAmbassador.java b/ambassador/src/main/java/com/iluwatar/ambassador/ServiceAmbassador.java
index f3f30a09d..4d3101697 100644
--- a/ambassador/src/main/java/com/iluwatar/ambassador/ServiceAmbassador.java
+++ b/ambassador/src/main/java/com/iluwatar/ambassador/ServiceAmbassador.java
@@ -40,8 +40,7 @@ public class ServiceAmbassador implements RemoteServiceInterface {
private static final int RETRIES = 3;
private static final int DELAY_MS = 3000;
- ServiceAmbassador() {
- }
+ ServiceAmbassador() {}
@Override
public long doRemoteFunction(int value) {
diff --git a/ambassador/src/main/java/com/iluwatar/ambassador/util/RandomProvider.java b/ambassador/src/main/java/com/iluwatar/ambassador/util/RandomProvider.java
index e8243cdcc..4eba2fada 100644
--- a/ambassador/src/main/java/com/iluwatar/ambassador/util/RandomProvider.java
+++ b/ambassador/src/main/java/com/iluwatar/ambassador/util/RandomProvider.java
@@ -24,9 +24,7 @@
*/
package com.iluwatar.ambassador.util;
-/**
- * An interface for randomness. Useful for testing purposes.
- */
+/** An interface for randomness. Useful for testing purposes. */
public interface RandomProvider {
double random();
}
diff --git a/ambassador/src/test/java/com/iluwatar/ambassador/AppTest.java b/ambassador/src/test/java/com/iluwatar/ambassador/AppTest.java
index cea0eeac7..ddb2d6eff 100644
--- a/ambassador/src/test/java/com/iluwatar/ambassador/AppTest.java
+++ b/ambassador/src/test/java/com/iluwatar/ambassador/AppTest.java
@@ -24,25 +24,22 @@
*/
package com.iluwatar.ambassador;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
-/**
- * Application test
- */
+import org.junit.jupiter.api.Test;
+
+/** Application test */
class AppTest {
/**
* Issue: Add at least one assertion to this test case.
*
- * Solution: Inserted assertion to check whether the execution of the main method in {@link App}
- * throws an exception.
+ *
Solution: Inserted assertion to check whether the execution of the main method in {@link
+ * App} throws an exception.
*/
-
@Test
void shouldExecuteApplicationWithoutException() {
- assertDoesNotThrow(() -> App.main(new String[]{}));
+ assertDoesNotThrow(() -> App.main(new String[] {}));
}
}
diff --git a/ambassador/src/test/java/com/iluwatar/ambassador/ClientTest.java b/ambassador/src/test/java/com/iluwatar/ambassador/ClientTest.java
index ff7f027f6..24603efff 100644
--- a/ambassador/src/test/java/com/iluwatar/ambassador/ClientTest.java
+++ b/ambassador/src/test/java/com/iluwatar/ambassador/ClientTest.java
@@ -24,13 +24,11 @@
*/
package com.iluwatar.ambassador;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertTrue;
-/**
- * Test for {@link Client}
- */
+import org.junit.jupiter.api.Test;
+
+/** Test for {@link Client} */
class ClientTest {
@Test
@@ -38,6 +36,7 @@ class ClientTest {
Client client = new Client();
var result = client.useService(10);
- assertTrue(result == 100 || result == RemoteServiceStatus.FAILURE.getRemoteServiceStatusValue());
+ assertTrue(
+ result == 100 || result == RemoteServiceStatus.FAILURE.getRemoteServiceStatusValue());
}
}
diff --git a/ambassador/src/test/java/com/iluwatar/ambassador/RemoteServiceTest.java b/ambassador/src/test/java/com/iluwatar/ambassador/RemoteServiceTest.java
index 5fed19a16..81e4f7441 100644
--- a/ambassador/src/test/java/com/iluwatar/ambassador/RemoteServiceTest.java
+++ b/ambassador/src/test/java/com/iluwatar/ambassador/RemoteServiceTest.java
@@ -29,9 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import com.iluwatar.ambassador.util.RandomProvider;
import org.junit.jupiter.api.Test;
-/**
- * Test for {@link RemoteService}
- */
+/** Test for {@link RemoteService} */
class RemoteServiceTest {
@Test
diff --git a/ambassador/src/test/java/com/iluwatar/ambassador/ServiceAmbassadorTest.java b/ambassador/src/test/java/com/iluwatar/ambassador/ServiceAmbassadorTest.java
index 50c354c14..0543b2e7e 100644
--- a/ambassador/src/test/java/com/iluwatar/ambassador/ServiceAmbassadorTest.java
+++ b/ambassador/src/test/java/com/iluwatar/ambassador/ServiceAmbassadorTest.java
@@ -24,18 +24,17 @@
*/
package com.iluwatar.ambassador;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertTrue;
-/**
- * Test for {@link ServiceAmbassador}
- */
+import org.junit.jupiter.api.Test;
+
+/** Test for {@link ServiceAmbassador} */
class ServiceAmbassadorTest {
@Test
void test() {
long result = new ServiceAmbassador().doRemoteFunction(10);
- assertTrue(result == 100 || result == RemoteServiceStatus.FAILURE.getRemoteServiceStatusValue());
+ assertTrue(
+ result == 100 || result == RemoteServiceStatus.FAILURE.getRemoteServiceStatusValue());
}
}
diff --git a/anti-corruption-layer/pom.xml b/anti-corruption-layer/pom.xml
index 711e006b7..2fddfd3ec 100644
--- a/anti-corruption-layer/pom.xml
+++ b/anti-corruption-layer/pom.xml
@@ -45,8 +45,8 @@
test
- junit
- junit
+ org.junit.jupiter
+ junit-jupiter-engine
test
diff --git a/anti-corruption-layer/src/main/java/com/iluwatar/corruption/App.java b/anti-corruption-layer/src/main/java/com/iluwatar/corruption/App.java
index ce2dbffd6..f7cf8f075 100644
--- a/anti-corruption-layer/src/main/java/com/iluwatar/corruption/App.java
+++ b/anti-corruption-layer/src/main/java/com/iluwatar/corruption/App.java
@@ -28,9 +28,8 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
- * This layer translates communications between the two systems,
- * allowing one system to remain unchanged while the other can avoid compromising
- * its design and technological approach.
+ * This layer translates communications between the two systems, allowing one system to remain
+ * unchanged while the other can avoid compromising its design and technological approach.
*/
@SpringBootApplication
public class App {
diff --git a/anti-corruption-layer/src/main/java/com/iluwatar/corruption/package-info.java b/anti-corruption-layer/src/main/java/com/iluwatar/corruption/package-info.java
index c8f72fca4..880d98c7d 100644
--- a/anti-corruption-layer/src/main/java/com/iluwatar/corruption/package-info.java
+++ b/anti-corruption-layer/src/main/java/com/iluwatar/corruption/package-info.java
@@ -23,30 +23,26 @@
* THE SOFTWARE.
*/
/**
- * Context and problem
- * Most applications rely on other systems for some data or functionality.
- * For example, when a legacy application is migrated to a modern system,
- * it may still need existing legacy resources. New features must be able to call the legacy system.
- * This is especially true of gradual migrations,
- * where different features of a larger application are moved to a modern system over time.
+ * Context and problem Most applications rely on other systems for some data or functionality. For
+ * example, when a legacy application is migrated to a modern system, it may still need existing
+ * legacy resources. New features must be able to call the legacy system. This is especially true of
+ * gradual migrations, where different features of a larger application are moved to a modern system
+ * over time.
*
- * Often these legacy systems suffer from quality issues such as convoluted data schemas
- * or obsolete APIs.
- * The features and technologies used in legacy systems can vary widely from more modern systems.
- * To interoperate with the legacy system,
- * the new application may need to support outdated infrastructure, protocols, data models, APIs,
- * or other features that you wouldn't otherwise put into a modern application.
+ *
Often these legacy systems suffer from quality issues such as convoluted data schemas or
+ * obsolete APIs. The features and technologies used in legacy systems can vary widely from more
+ * modern systems. To interoperate with the legacy system, the new application may need to support
+ * outdated infrastructure, protocols, data models, APIs, or other features that you wouldn't
+ * otherwise put into a modern application.
*
- *
Maintaining access between new and legacy systems can force the new system to adhere to
- * at least some of the legacy system's APIs or other semantics.
- * When these legacy features have quality issues, supporting them "corrupts" what might
- * otherwise be a cleanly designed modern application.
- * Similar issues can arise with any external system that your development team doesn't control,
- * not just legacy systems.
+ *
Maintaining access between new and legacy systems can force the new system to adhere to at
+ * least some of the legacy system's APIs or other semantics. When these legacy features have
+ * quality issues, supporting them "corrupts" what might otherwise be a cleanly designed modern
+ * application. Similar issues can arise with any external system that your development team doesn't
+ * control, not just legacy systems.
*
*
Solution Isolate the different subsystems by placing an anti-corruption layer between them.
- * This layer translates communications between the two systems,
- * allowing one system to remain unchanged while the other can avoid compromising
- * its design and technological approach.
+ * This layer translates communications between the two systems, allowing one system to remain
+ * unchanged while the other can avoid compromising its design and technological approach.
*/
package com.iluwatar.corruption;
diff --git a/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/AntiCorruptionLayer.java b/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/AntiCorruptionLayer.java
index fae658ee5..4e8a17fa5 100644
--- a/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/AntiCorruptionLayer.java
+++ b/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/AntiCorruptionLayer.java
@@ -33,36 +33,34 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
- * The class represents an anti-corruption layer.
- * The main purpose of the class is to provide a layer between the modern and legacy systems.
- * The class is responsible for converting the data from one system to another
- * decoupling the systems to each other
+ * The class represents an anti-corruption layer. The main purpose of the class is to provide a
+ * layer between the modern and legacy systems. The class is responsible for converting the data
+ * from one system to another decoupling the systems to each other
*
- *
It allows using one system a domain model of the other system
- * without changing the domain model of the system.
+ *
It allows using one system a domain model of the other system without changing the domain
+ * model of the system.
*/
@Service
public class AntiCorruptionLayer {
- @Autowired
- private LegacyShop legacyShop;
-
+ @Autowired private LegacyShop legacyShop;
/**
* The method converts the order from the legacy system to the modern system.
+ *
* @param id the id of the order
* @return the order in the modern system
*/
public Optional findOrderInLegacySystem(String id) {
- return legacyShop.findOrder(id).map(o ->
- new ModernOrder(
- o.getId(),
- new Customer(o.getCustomer()),
- new Shipment(o.getItem(), o.getQty(), o.getPrice()),
- ""
- )
- );
+ return legacyShop
+ .findOrder(id)
+ .map(
+ o ->
+ new ModernOrder(
+ o.getId(),
+ new Customer(o.getCustomer()),
+ new Shipment(o.getItem(), o.getQty(), o.getPrice()),
+ ""));
}
-
}
diff --git a/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/DataStore.java b/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/DataStore.java
index e9fdaa14e..e84578528 100644
--- a/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/DataStore.java
+++ b/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/DataStore.java
@@ -29,6 +29,7 @@ import java.util.Optional;
/**
* The class represents a data store for the modern system.
+ *
* @param the type of the value stored in the data store
*/
public abstract class DataStore {
@@ -44,6 +45,5 @@ public abstract class DataStore {
public Optional put(String key, V value) {
return Optional.ofNullable(inner.put(key, value));
-
}
}
diff --git a/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/ShopException.java b/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/ShopException.java
index 103fcfccd..c0acd288e 100644
--- a/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/ShopException.java
+++ b/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/ShopException.java
@@ -24,9 +24,7 @@
*/
package com.iluwatar.corruption.system;
-/**
- * The class represents a general exception for the shop.
- */
+/** The class represents a general exception for the shop. */
public class ShopException extends Exception {
public ShopException(String message) {
super(message);
@@ -41,9 +39,12 @@ public class ShopException extends Exception {
* @throws ShopException the exception
*/
public static ShopException throwIncorrectData(String lhs, String rhs) throws ShopException {
- throw new ShopException("The order is already placed but has an incorrect data:\n"
- + "Incoming order: " + lhs + "\n"
- + "Existing order: " + rhs);
+ throw new ShopException(
+ "The order is already placed but has an incorrect data:\n"
+ + "Incoming order: "
+ + lhs
+ + "\n"
+ + "Existing order: "
+ + rhs);
}
-
}
diff --git a/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/legacy/LegacyOrder.java b/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/legacy/LegacyOrder.java
index 2481d19c8..45faa06cb 100644
--- a/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/legacy/LegacyOrder.java
+++ b/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/legacy/LegacyOrder.java
@@ -28,8 +28,8 @@ import lombok.AllArgsConstructor;
import lombok.Data;
/**
- * The class represents an order in the legacy system.
- * The class is used by the legacy system to store the data.
+ * The class represents an order in the legacy system. The class is used by the legacy system to
+ * store the data.
*/
@Data
@AllArgsConstructor
diff --git a/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/legacy/LegacyStore.java b/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/legacy/LegacyStore.java
index b29b71d87..ec1d613a7 100644
--- a/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/legacy/LegacyStore.java
+++ b/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/legacy/LegacyStore.java
@@ -28,10 +28,8 @@ import com.iluwatar.corruption.system.DataStore;
import org.springframework.stereotype.Service;
/**
- * The class represents a data store for the legacy system.
- * The class is used by the legacy system to store the data.
+ * The class represents a data store for the legacy system. The class is used by the legacy system
+ * to store the data.
*/
@Service
-public class LegacyStore extends DataStore {
-}
-
+public class LegacyStore extends DataStore {}
diff --git a/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/modern/Customer.java b/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/modern/Customer.java
index dd3351415..130f36d39 100644
--- a/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/modern/Customer.java
+++ b/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/modern/Customer.java
@@ -27,9 +27,7 @@ package com.iluwatar.corruption.system.modern;
import lombok.AllArgsConstructor;
import lombok.Data;
-/**
- * The class represents a customer in the modern system.
- */
+/** The class represents a customer in the modern system. */
@Data
@AllArgsConstructor
public class Customer {
diff --git a/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/modern/ModernOrder.java b/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/modern/ModernOrder.java
index 94c4f57b9..7b6298501 100644
--- a/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/modern/ModernOrder.java
+++ b/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/modern/ModernOrder.java
@@ -27,9 +27,7 @@ package com.iluwatar.corruption.system.modern;
import lombok.AllArgsConstructor;
import lombok.Data;
-/**
- * The class represents an order in the modern system.
- */
+/** The class represents an order in the modern system. */
@Data
@AllArgsConstructor
public class ModernOrder {
@@ -39,6 +37,4 @@ public class ModernOrder {
private Shipment shipment;
private String extra;
-
-
}
diff --git a/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/modern/ModernShop.java b/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/modern/ModernShop.java
index 45cd355be..24080abe1 100644
--- a/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/modern/ModernShop.java
+++ b/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/modern/ModernShop.java
@@ -31,20 +31,18 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
- * The class represents a modern shop system.
- * The main purpose of the class is to place orders and find orders.
+ * The class represents a modern shop system. The main purpose of the class is to place orders and
+ * find orders.
*/
@Service
public class ModernShop {
- @Autowired
- private ModernStore store;
+ @Autowired private ModernStore store;
- @Autowired
- private AntiCorruptionLayer acl;
+ @Autowired private AntiCorruptionLayer acl;
/**
- * Places the order in the modern system.
- * If the order is already present in the legacy system, then no need to place it again.
+ * Places the order in the modern system. If the order is already present in the legacy system,
+ * then no need to place it again.
*/
public void placeOrder(ModernOrder order) throws ShopException {
@@ -62,9 +60,7 @@ public class ModernShop {
}
}
- /**
- * Finds the order in the modern system.
- */
+ /** Finds the order in the modern system. */
public Optional findOrder(String orderId) {
return store.get(orderId);
}
diff --git a/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/modern/ModernStore.java b/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/modern/ModernStore.java
index 4ec4d7dbc..4fb3952fa 100644
--- a/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/modern/ModernStore.java
+++ b/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/modern/ModernStore.java
@@ -27,10 +27,6 @@ package com.iluwatar.corruption.system.modern;
import com.iluwatar.corruption.system.DataStore;
import org.springframework.stereotype.Service;
-/**
- * The class represents a data store for the modern system.
- */
+/** The class represents a data store for the modern system. */
@Service
-public class ModernStore extends DataStore {
-}
-
+public class ModernStore extends DataStore {}
diff --git a/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/modern/Shipment.java b/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/modern/Shipment.java
index 292c0d8e3..085a3921c 100644
--- a/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/modern/Shipment.java
+++ b/anti-corruption-layer/src/main/java/com/iluwatar/corruption/system/modern/Shipment.java
@@ -28,8 +28,8 @@ import lombok.AllArgsConstructor;
import lombok.Data;
/**
- * The class represents a shipment in the modern system.
- * The class is used by the modern system to store the data.
+ * The class represents a shipment in the modern system. The class is used by the modern system to
+ * store the data.
*/
@Data
@AllArgsConstructor
diff --git a/anti-corruption-layer/src/test/java/com/iluwatar/corruption/system/AntiCorruptionLayerTest.java b/anti-corruption-layer/src/test/java/com/iluwatar/corruption/system/AntiCorruptionLayerTest.java
index ba24c8981..ee46d124e 100644
--- a/anti-corruption-layer/src/test/java/com/iluwatar/corruption/system/AntiCorruptionLayerTest.java
+++ b/anti-corruption-layer/src/test/java/com/iluwatar/corruption/system/AntiCorruptionLayerTest.java
@@ -24,88 +24,73 @@
*/
package com.iluwatar.corruption.system;
+import static org.junit.jupiter.api.Assertions.*;
+
import com.iluwatar.corruption.system.legacy.LegacyOrder;
import com.iluwatar.corruption.system.legacy.LegacyShop;
import com.iluwatar.corruption.system.modern.Customer;
import com.iluwatar.corruption.system.modern.ModernOrder;
import com.iluwatar.corruption.system.modern.ModernShop;
import com.iluwatar.corruption.system.modern.Shipment;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import java.util.Optional;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
-import java.util.Optional;
-
-import static org.junit.jupiter.api.Assertions.*;
-
-@RunWith(SpringRunner.class)
+@ExtendWith(SpringExtension.class)
@SpringBootTest
public class AntiCorruptionLayerTest {
- @Autowired
- private LegacyShop legacyShop;
+ @Autowired private LegacyShop legacyShop;
- @Autowired
- private ModernShop modernShop;
+ @Autowired private ModernShop modernShop;
+ /**
+ * Test the anti-corruption layer. Main intention is to demonstrate how the anti-corruption layer
+ * works. The 2 shops (modern and legacy) should operate independently and in the same time
+ * synchronize the data.
+ */
+ @Test
+ public void antiCorruptionLayerTest() throws ShopException {
+ // a new order comes to the legacy shop.
+ LegacyOrder legacyOrder = new LegacyOrder("1", "addr1", "item1", 1, 1);
+ // place the order in the legacy shop.
+ legacyShop.placeOrder(legacyOrder);
+ // the order is placed as usual since there is no other orders with the id in the both systems.
+ Optional legacyOrderWithIdOne = legacyShop.findOrder("1");
+ assertEquals(Optional.of(legacyOrder), legacyOrderWithIdOne);
- /**
- * Test the anti-corruption layer.
- * Main intention is to demonstrate how the anti-corruption layer works.
- *
- * The 2 shops (modern and legacy) should operate independently and in the same time synchronize the data.
- * To avoid corrupting the domain models of the 2 shops, we use an anti-corruption layer
- * that transforms one model to another under the hood.
- *
- */
- @Test
- public void antiCorruptionLayerTest() throws ShopException {
+ // a new order (or maybe just the same order) appears in the modern shop
+ ModernOrder modernOrder =
+ new ModernOrder("1", new Customer("addr1"), new Shipment("item1", 1, 1), "");
+ // the system places it, but it checks if there is an order with the same id in the legacy shop.
+ modernShop.placeOrder(modernOrder);
- // a new order comes to the legacy shop.
- LegacyOrder legacyOrder = new LegacyOrder("1", "addr1", "item1", 1, 1);
- // place the order in the legacy shop.
- legacyShop.placeOrder(legacyOrder);
- // the order is placed as usual since there is no other orders with the id in the both systems.
- Optional legacyOrderWithIdOne = legacyShop.findOrder("1");
- assertEquals(Optional.of(legacyOrder), legacyOrderWithIdOne);
+ Optional modernOrderWithIdOne = modernShop.findOrder("1");
+ // there is no new order placed since there is already an order with the same id in the legacy
+ // shop.
+ assertTrue(modernOrderWithIdOne.isEmpty());
+ }
- // a new order (or maybe just the same order) appears in the modern shop.
- ModernOrder modernOrder = new ModernOrder("1", new Customer("addr1"), new Shipment("item1", 1, 1), "");
-
- // the system places it, but it checks if there is an order with the same id in the legacy shop.
- modernShop.placeOrder(modernOrder);
-
- Optional modernOrderWithIdOne = modernShop.findOrder("1");
- // there is no new order placed since there is already an order with the same id in the legacy shop.
- assertTrue(modernOrderWithIdOne.isEmpty());
-
- }
- /**
- * Test the anti-corruption layer.
- * Main intention is to demonstrate how the anti-corruption layer works.
- *
- * This test tests the anti-corruption layer from the rule the orders should be the same in the both systems.
- *
- */
- @Test(expected = ShopException.class)
- public void antiCorruptionLayerWithExTest() throws ShopException {
-
- // a new order comes to the legacy shop.
- LegacyOrder legacyOrder = new LegacyOrder("1", "addr1", "item1", 1, 1);
- // place the order in the legacy shop.
- legacyShop.placeOrder(legacyOrder);
- // the order is placed as usual since there is no other orders with the id in the both systems.
- Optional legacyOrderWithIdOne = legacyShop.findOrder("1");
- assertEquals(Optional.of(legacyOrder), legacyOrderWithIdOne);
-
- // a new order but with the same id and different data appears in the modern shop
- ModernOrder modernOrder = new ModernOrder("1", new Customer("addr1"), new Shipment("item1", 10, 1), "");
-
- // the system rejects the order since there are 2 orders with contradiction there.
- modernShop.placeOrder(modernOrder);
-
-
- }
-}
\ No newline at end of file
+ /**
+ * Test the anti-corruption layer when a conflict occurs between systems. This test ensures that
+ * an exception is thrown when conflicting orders are placed.
+ */
+ @Test
+ public void antiCorruptionLayerWithExTest() throws ShopException {
+ // a new order comes to the legacy shop.
+ LegacyOrder legacyOrder = new LegacyOrder("1", "addr1", "item1", 1, 1);
+ // place the order in the legacy shop.
+ legacyShop.placeOrder(legacyOrder);
+ // the order is placed as usual since there is no other orders with the id in the both systems.
+ Optional legacyOrderWithIdOne = legacyShop.findOrder("1");
+ assertEquals(Optional.of(legacyOrder), legacyOrderWithIdOne);
+ // a new order but with the same id and different data appears in the modern shop
+ ModernOrder modernOrder =
+ new ModernOrder("1", new Customer("addr1"), new Shipment("item1", 10, 1), "");
+ // the system rejects the order since there are 2 orders with contradiction there.
+ assertThrows(ShopException.class, () -> modernShop.placeOrder(modernOrder));
+ }
+}
diff --git a/arrange-act-assert/src/main/java/com/iluwatar/arrangeactassert/Cash.java b/arrange-act-assert/src/main/java/com/iluwatar/arrangeactassert/Cash.java
index c3f5e6fe4..0c31b1f89 100644
--- a/arrange-act-assert/src/main/java/com/iluwatar/arrangeactassert/Cash.java
+++ b/arrange-act-assert/src/main/java/com/iluwatar/arrangeactassert/Cash.java
@@ -35,12 +35,12 @@ public class Cash {
private int amount;
- //plus
+ // plus
void plus(int addend) {
amount += addend;
}
- //minus
+ // minus
boolean minus(int subtrahend) {
if (amount >= subtrahend) {
amount -= subtrahend;
@@ -50,7 +50,7 @@ public class Cash {
}
}
- //count
+ // count
int count() {
return amount;
}
diff --git a/arrange-act-assert/src/test/java/com/iluwatar/arrangeactassert/CashAAATest.java b/arrange-act-assert/src/test/java/com/iluwatar/arrangeactassert/CashAAATest.java
index b771cb6e7..ebb261277 100644
--- a/arrange-act-assert/src/test/java/com/iluwatar/arrangeactassert/CashAAATest.java
+++ b/arrange-act-assert/src/test/java/com/iluwatar/arrangeactassert/CashAAATest.java
@@ -35,8 +35,11 @@ import org.junit.jupiter.api.Test;
* tests, so they're easier to read, maintain and enhance.
*
* It breaks tests down into three clear and distinct steps:
+ *
*
1. Arrange: Perform the setup and initialization required for the test.
+ *
*
2. Act: Take action(s) required for the test.
+ *
*
3. Assert: Verify the outcome(s) of the test.
*
*
This pattern has several significant benefits. It creates a clear separation between a test's
@@ -48,53 +51,52 @@ import org.junit.jupiter.api.Test;
* clearly about the three steps your test will perform. But it makes tests more natural to write at
* the same time since you already have an outline.
*
- *
In ({@link CashAAATest}) we have four test methods. Each of them has only one reason to
- * change and one reason to fail. In a large and complicated code base, tests that honor the single
+ *
In ({@link CashAAATest}) we have four test methods. Each of them has only one reason to change
+ * and one reason to fail. In a large and complicated code base, tests that honor the single
* responsibility principle are much easier to troubleshoot.
*/
-
class CashAAATest {
@Test
void testPlus() {
- //Arrange
+ // Arrange
var cash = new Cash(3);
- //Act
+ // Act
cash.plus(4);
- //Assert
+ // Assert
assertEquals(7, cash.count());
}
@Test
void testMinus() {
- //Arrange
+ // Arrange
var cash = new Cash(8);
- //Act
+ // Act
var result = cash.minus(5);
- //Assert
+ // Assert
assertTrue(result);
assertEquals(3, cash.count());
}
@Test
void testInsufficientMinus() {
- //Arrange
+ // Arrange
var cash = new Cash(1);
- //Act
+ // Act
var result = cash.minus(6);
- //Assert
+ // Assert
assertFalse(result);
assertEquals(1, cash.count());
}
@Test
void testUpdate() {
- //Arrange
+ // Arrange
var cash = new Cash(5);
- //Act
+ // Act
cash.plus(6);
var result = cash.minus(3);
- //Assert
+ // Assert
assertTrue(result);
assertEquals(8, cash.count());
}
diff --git a/arrange-act-assert/src/test/java/com/iluwatar/arrangeactassert/CashAntiAAATest.java b/arrange-act-assert/src/test/java/com/iluwatar/arrangeactassert/CashAntiAAATest.java
index 142fd623a..575682251 100644
--- a/arrange-act-assert/src/test/java/com/iluwatar/arrangeactassert/CashAntiAAATest.java
+++ b/arrange-act-assert/src/test/java/com/iluwatar/arrangeactassert/CashAntiAAATest.java
@@ -37,23 +37,22 @@ import org.junit.jupiter.api.Test;
* single responsibility principle. If this test method failed after a small code change, it might
* take some digging to discover why.
*/
-
class CashAntiAAATest {
@Test
void testCash() {
- //initialize
+ // initialize
var cash = new Cash(3);
- //test plus
+ // test plus
cash.plus(4);
assertEquals(7, cash.count());
- //test minus
+ // test minus
cash = new Cash(8);
assertTrue(cash.minus(5));
assertEquals(3, cash.count());
assertFalse(cash.minus(6));
assertEquals(3, cash.count());
- //test update
+ // test update
cash.plus(5);
assertTrue(cash.minus(5));
assertEquals(3, cash.count());
diff --git a/async-method-invocation/pom.xml b/async-method-invocation/pom.xml
index 52a03369f..d9ddd918c 100644
--- a/async-method-invocation/pom.xml
+++ b/async-method-invocation/pom.xml
@@ -34,6 +34,14 @@
async-method-invocation
+
+ org.slf4j
+ slf4j-api
+
+
+ ch.qos.logback
+ logback-classic
+
org.junit.jupiter
junit-jupiter-engine
diff --git a/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/App.java b/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/App.java
index 01fd8f1c6..ec3beed3b 100644
--- a/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/App.java
+++ b/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/App.java
@@ -30,15 +30,15 @@ import lombok.extern.slf4j.Slf4j;
/**
* In this example, we are launching space rockets and deploying lunar rovers.
*
- * The application demonstrates the async method invocation pattern. The key parts of the
- * pattern are AsyncResult which is an intermediate container for an asynchronously
- * evaluated value, AsyncCallback which can be provided to be executed on task
- * completion and AsyncExecutor that manages the execution of the async tasks.
+ *
The application demonstrates the async method invocation pattern. The key parts of the pattern
+ * are AsyncResult which is an intermediate container for an asynchronously evaluated
+ * value, AsyncCallback which can be provided to be executed on task completion and
+ * AsyncExecutor that manages the execution of the async tasks.
*
- *
The main method shows example flow of async invocations. The main thread starts multiple
- * tasks with variable durations and then continues its own work. When the main thread has done it's
- * job it collects the results of the async tasks. Two of the tasks are handled with callbacks,
- * meaning the callbacks are executed immediately when the tasks complete.
+ *
The main method shows example flow of async invocations. The main thread starts multiple tasks
+ * with variable durations and then continues its own work. When the main thread has done it's job
+ * it collects the results of the async tasks. Two of the tasks are handled with callbacks, meaning
+ * the callbacks are executed immediately when the tasks complete.
*
*
Noteworthy difference of thread usage between the async results and callbacks is that the
* async results are collected in the main thread but the callbacks are executed within the worker
@@ -62,10 +62,7 @@ public class App {
private static final String ROCKET_LAUNCH_LOG_PATTERN = "Space rocket <%s> launched successfully";
- /**
- * Program entry point.
- */
-
+ /** Program entry point. */
public static void main(String[] args) throws Exception {
// construct a new executor that will run async tasks
var executor = new ThreadAsyncExecutor();
@@ -74,8 +71,8 @@ public class App {
final var asyncResult1 = executor.startProcess(lazyval(10, 500));
final var asyncResult2 = executor.startProcess(lazyval("test", 300));
final var asyncResult3 = executor.startProcess(lazyval(50L, 700));
- final var asyncResult4 = executor.startProcess(lazyval(20, 400),
- callback("Deploying lunar rover"));
+ final var asyncResult4 =
+ executor.startProcess(lazyval(20, 400), callback("Deploying lunar rover"));
final var asyncResult5 =
executor.startProcess(lazyval("callback", 600), callback("Deploying lunar rover"));
@@ -99,7 +96,7 @@ public class App {
/**
* Creates a callable that lazily evaluates to given value with artificial delay.
*
- * @param value value to evaluate
+ * @param value value to evaluate
* @param delayMillis artificial delay in milliseconds
* @return new callable for lazy evaluation
*/
diff --git a/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/AsyncExecutor.java b/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/AsyncExecutor.java
index fcea6d071..3bae90830 100644
--- a/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/AsyncExecutor.java
+++ b/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/AsyncExecutor.java
@@ -27,9 +27,7 @@ package com.iluwatar.async.method.invocation;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
-/**
- * AsyncExecutor interface.
- */
+/** AsyncExecutor interface. */
public interface AsyncExecutor {
/**
@@ -44,7 +42,7 @@ public interface AsyncExecutor {
* Starts processing of an async task. Returns immediately with async result. Executes callback
* when the task is completed.
*
- * @param task task to be executed asynchronously
+ * @param task task to be executed asynchronously
* @param callback callback to be executed on task completion
* @return async result for the task
*/
@@ -56,7 +54,7 @@ public interface AsyncExecutor {
*
* @param asyncResult async result of a task
* @return evaluated value of the completed task
- * @throws ExecutionException if execution has failed, containing the root cause
+ * @throws ExecutionException if execution has failed, containing the root cause
* @throws InterruptedException if the execution is interrupted
*/
T endProcess(AsyncResult asyncResult) throws ExecutionException, InterruptedException;
diff --git a/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/AsyncResult.java b/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/AsyncResult.java
index d71cf0def..3eebdc4e7 100644
--- a/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/AsyncResult.java
+++ b/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/AsyncResult.java
@@ -44,7 +44,7 @@ public interface AsyncResult {
* Gets the value of completed async task.
*
* @return evaluated value or throws ExecutionException if execution has failed
- * @throws ExecutionException if execution has failed, containing the root cause
+ * @throws ExecutionException if execution has failed, containing the root cause
* @throws IllegalStateException if execution is not completed
*/
T getValue() throws ExecutionException;
diff --git a/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/ThreadAsyncExecutor.java b/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/ThreadAsyncExecutor.java
index f4a50e0d6..a1261f341 100644
--- a/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/ThreadAsyncExecutor.java
+++ b/async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/ThreadAsyncExecutor.java
@@ -24,19 +24,14 @@
*/
package com.iluwatar.async.method.invocation;
-import java.util.Optional;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicInteger;
-/**
- * Implementation of async executor that creates a new thread for every task.
- */
+/** Implementation of async executor that creates a new thread for every task. */
public class ThreadAsyncExecutor implements AsyncExecutor {
- /**
- * Index for thread naming.
- */
+ /** Index for thread naming. */
private final AtomicInteger idx = new AtomicInteger(0);
@Override
@@ -47,19 +42,22 @@ public class ThreadAsyncExecutor implements AsyncExecutor {
@Override
public AsyncResult startProcess(Callable task, AsyncCallback callback) {
var result = new CompletableResult<>(callback);
- new Thread(() -> {
- try {
- result.setValue(task.call());
- } catch (Exception ex) {
- result.setException(ex);
- }
- }, "executor-" + idx.incrementAndGet()).start();
+ new Thread(
+ () -> {
+ try {
+ result.setValue(task.call());
+ } catch (Exception ex) {
+ result.setException(ex);
+ }
+ },
+ "executor-" + idx.incrementAndGet())
+ .start();
return result;
}
@Override
- public T endProcess(AsyncResult asyncResult) throws ExecutionException,
- InterruptedException {
+ public T endProcess(AsyncResult asyncResult)
+ throws ExecutionException, InterruptedException {
if (!asyncResult.isCompleted()) {
asyncResult.await();
}
diff --git a/async-method-invocation/src/test/java/com/iluwatar/async/method/invocation/AppTest.java b/async-method-invocation/src/test/java/com/iluwatar/async/method/invocation/AppTest.java
index f31c5549b..d58a3f6b5 100644
--- a/async-method-invocation/src/test/java/com/iluwatar/async/method/invocation/AppTest.java
+++ b/async-method-invocation/src/test/java/com/iluwatar/async/method/invocation/AppTest.java
@@ -24,26 +24,22 @@
*/
package com.iluwatar.async.method.invocation;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
-/**
- * Application test
- */
+import org.junit.jupiter.api.Test;
+
+/** Application test */
class AppTest {
/**
* Issue: Add at least one assertion to this test case.
*
- * Solution: Inserted assertion to check whether the execution of the main method in {@link App}
- * throws an exception.
+ * Solution: Inserted assertion to check whether the execution of the main method in {@link
+ * App} throws an exception.
*/
-
@Test
void shouldExecuteApplicationWithoutException() {
- assertDoesNotThrow(() -> App.main(new String[]{}));
-
+ assertDoesNotThrow(() -> App.main(new String[] {}));
}
}
diff --git a/async-method-invocation/src/test/java/com/iluwatar/async/method/invocation/ThreadAsyncExecutorTest.java b/async-method-invocation/src/test/java/com/iluwatar/async/method/invocation/ThreadAsyncExecutorTest.java
index c9f85f48d..d6540ce77 100644
--- a/async-method-invocation/src/test/java/com/iluwatar/async/method/invocation/ThreadAsyncExecutorTest.java
+++ b/async-method-invocation/src/test/java/com/iluwatar/async/method/invocation/ThreadAsyncExecutorTest.java
@@ -33,7 +33,6 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import static org.mockito.internal.verification.VerificationModeFactory.times;
-import java.util.Optional;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import org.junit.jupiter.api.BeforeEach;
@@ -43,49 +42,43 @@ import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-/**
- * ThreadAsyncExecutorTest
- *
- */
+/** ThreadAsyncExecutorTest */
class ThreadAsyncExecutorTest {
- @Captor
- private ArgumentCaptor exceptionCaptor;
+ @Captor private ArgumentCaptor exceptionCaptor;
- @Mock
- private Callable