mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-19 01:26:35 +00:00
deps: Refactor dependencies (#3224)
* remove spring dep move junit, logging, mockito under dep mgmt * upgrade anti-corruption-layer deps * async method invocation * balking, bloc * bridge to bytecode * caching * callback - cqrs * component - health check * hexagonal - metadata mapping * rest of the patterns * remove checkstyle, take spotless into use
This commit is contained in:
@@ -43,11 +43,10 @@ import lombok.extern.slf4j.Slf4j;
|
||||
*
|
||||
* <p>In this example, we create a new Lockable object with the SwordOfAragorn implementation of it.
|
||||
* Afterward we create 6 Creatures with the Elf, Orc and Human implementations and assign them each
|
||||
* to a Fiend object and the Sword is the target object. Because there is only one Sword, and it uses
|
||||
* the Lockable Object pattern, only one creature can hold the sword at a given time. When the sword
|
||||
* is locked, any other alive Fiends will try to lock, which will result in a race to lock the
|
||||
* to a Fiend object and the Sword is the target object. Because there is only one Sword, and it
|
||||
* uses the Lockable Object pattern, only one creature can hold the sword at a given time. When the
|
||||
* sword is locked, any other alive Fiends will try to lock, which will result in a race to lock the
|
||||
* sword.
|
||||
*
|
||||
*/
|
||||
@Slf4j
|
||||
public class App implements Runnable {
|
||||
|
||||
@@ -26,16 +26,12 @@ package com.iluwatar.lockableobject;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* An exception regarding the locking process of a Lockable object.
|
||||
*/
|
||||
/** An exception regarding the locking process of a Lockable object. */
|
||||
public class LockingException extends RuntimeException {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 8556381044865867037L;
|
||||
@Serial private static final long serialVersionUID = 8556381044865867037L;
|
||||
|
||||
public LockingException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ import lombok.NonNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* An implementation of a Lockable object. This is the Sword of Aragorn and every creature wants
|
||||
* to possess it!
|
||||
* An implementation of a Lockable object. This is the Sword of Aragorn and every creature wants to
|
||||
* possess it!
|
||||
*/
|
||||
@Slf4j
|
||||
public class SwordOfAragorn implements Lockable {
|
||||
|
||||
@@ -109,5 +109,4 @@ public abstract class Creature {
|
||||
public synchronized boolean isAlive() {
|
||||
return getHealth() > 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,8 +35,7 @@ public enum CreatureStats {
|
||||
HUMAN_HEALTH(60),
|
||||
HUMAN_DAMAGE(60);
|
||||
|
||||
@Getter
|
||||
final int value;
|
||||
@Getter final int value;
|
||||
|
||||
CreatureStats(int value) {
|
||||
this.value = value;
|
||||
|
||||
@@ -97,7 +97,7 @@ class CreatureTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidDamageTest(){
|
||||
void invalidDamageTest() {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> elf.hit(-50));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,12 +32,11 @@ class ExceptionsTest {
|
||||
private static final String MSG = "test";
|
||||
|
||||
@Test
|
||||
void testException(){
|
||||
void testException() {
|
||||
Exception e;
|
||||
try{
|
||||
try {
|
||||
throw new LockingException(MSG);
|
||||
}
|
||||
catch(LockingException ex){
|
||||
} catch (LockingException ex) {
|
||||
e = ex;
|
||||
}
|
||||
Assertions.assertEquals(MSG, e.getMessage());
|
||||
|
||||
@@ -39,14 +39,14 @@ class FeindTest {
|
||||
private Lockable sword;
|
||||
|
||||
@BeforeEach
|
||||
void init(){
|
||||
void init() {
|
||||
elf = new Elf("Nagdil");
|
||||
orc = new Orc("Ghandar");
|
||||
sword = new SwordOfAragorn();
|
||||
}
|
||||
|
||||
@Test
|
||||
void nullTests(){
|
||||
void nullTests() {
|
||||
Assertions.assertThrows(NullPointerException.class, () -> new Feind(null, null));
|
||||
Assertions.assertThrows(NullPointerException.class, () -> new Feind(elf, null));
|
||||
Assertions.assertThrows(NullPointerException.class, () -> new Feind(null, sword));
|
||||
@@ -67,5 +67,4 @@ class FeindTest {
|
||||
sword.unlock(elf.isAlive() ? elf : orc);
|
||||
Assertions.assertNull(sword.getLocker());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.junit.jupiter.api.Test;
|
||||
class SubCreaturesTests {
|
||||
|
||||
@Test
|
||||
void statsTest(){
|
||||
void statsTest() {
|
||||
var elf = new Elf("Limbar");
|
||||
var orc = new Orc("Dargal");
|
||||
var human = new Human("Jerry");
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ class TheSwordOfAragornTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidLockerTest(){
|
||||
void invalidLockerTest() {
|
||||
var sword = new SwordOfAragorn();
|
||||
Assertions.assertThrows(NullPointerException.class, () -> sword.lock(null));
|
||||
Assertions.assertThrows(NullPointerException.class, () -> sword.unlock(null));
|
||||
|
||||
Reference in New Issue
Block a user