mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-09-04 00:17:24 +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:
@@ -40,12 +40,16 @@ public class App {
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
MmaBantamweightFighter fighter1 = new MmaBantamweightFighter("Joe", "Johnson", "The Geek", "Muay Thai");
|
||||
MmaBantamweightFighter fighter2 = new MmaBantamweightFighter("Ed", "Edwards", "The Problem Solver", "Judo");
|
||||
MmaBantamweightFighter fighter1 =
|
||||
new MmaBantamweightFighter("Joe", "Johnson", "The Geek", "Muay Thai");
|
||||
MmaBantamweightFighter fighter2 =
|
||||
new MmaBantamweightFighter("Ed", "Edwards", "The Problem Solver", "Judo");
|
||||
fighter1.fight(fighter2);
|
||||
|
||||
MmaHeavyweightFighter fighter3 = new MmaHeavyweightFighter("Dave", "Davidson", "The Bug Smasher", "Kickboxing");
|
||||
MmaHeavyweightFighter fighter4 = new MmaHeavyweightFighter("Jack", "Jackson", "The Pragmatic", "Brazilian Jiu-Jitsu");
|
||||
MmaHeavyweightFighter fighter3 =
|
||||
new MmaHeavyweightFighter("Dave", "Davidson", "The Bug Smasher", "Kickboxing");
|
||||
MmaHeavyweightFighter fighter4 =
|
||||
new MmaHeavyweightFighter("Jack", "Jackson", "The Pragmatic", "Brazilian Jiu-Jitsu");
|
||||
fighter3.fight(fighter4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,5 +32,4 @@ package crtp;
|
||||
public interface Fighter<T> {
|
||||
|
||||
void fight(T t);
|
||||
|
||||
}
|
||||
|
||||
@@ -24,13 +24,10 @@
|
||||
*/
|
||||
package crtp;
|
||||
|
||||
/**
|
||||
* MmaBantamweightFighter class.
|
||||
*/
|
||||
/** MmaBantamweightFighter class. */
|
||||
class MmaBantamweightFighter extends MmaFighter<MmaBantamweightFighter> {
|
||||
|
||||
public MmaBantamweightFighter(String name, String surname, String nickName, String speciality) {
|
||||
super(name, surname, nickName, speciality);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,13 +24,10 @@
|
||||
*/
|
||||
package crtp;
|
||||
|
||||
/**
|
||||
* MmaHeavyweightFighter.
|
||||
*/
|
||||
/** MmaHeavyweightFighter. */
|
||||
public class MmaHeavyweightFighter extends MmaFighter<MmaHeavyweightFighter> {
|
||||
|
||||
public MmaHeavyweightFighter(String name, String surname, String nickName, String speciality) {
|
||||
super(name, surname, nickName, speciality);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,13 +24,10 @@
|
||||
*/
|
||||
package crtp;
|
||||
|
||||
/**
|
||||
* MmaLightweightFighter class.
|
||||
*/
|
||||
/** MmaLightweightFighter class. */
|
||||
class MmaLightweightFighter extends MmaFighter<MmaLightweightFighter> {
|
||||
|
||||
public MmaLightweightFighter(String name, String surname, String nickName, String speciality) {
|
||||
super(name, surname, nickName, speciality);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,13 +28,11 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Application test
|
||||
*/
|
||||
/** Application test */
|
||||
class AppTest {
|
||||
|
||||
@Test
|
||||
void shouldExecuteApplicationWithoutException() {
|
||||
assertDoesNotThrow(() -> App.main(new String[]{}));
|
||||
assertDoesNotThrow(() -> App.main(new String[] {}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,37 +24,38 @@
|
||||
*/
|
||||
package crtp;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@Slf4j
|
||||
public class FightTest {
|
||||
|
||||
/**
|
||||
* A fighter has signed a contract with a promotion, and he will face some other fighters. A list of opponents is ready
|
||||
* but for some reason not all of them belong to the same weight class. Let's ensure that the fighter will only face
|
||||
* opponents in the same weight class.
|
||||
* A fighter has signed a contract with a promotion, and he will face some other fighters. A list
|
||||
* of opponents is ready but for some reason not all of them belong to the same weight class.
|
||||
* Let's ensure that the fighter will only face opponents in the same weight class.
|
||||
*/
|
||||
@Test
|
||||
void testFighterCanFightOnlyAgainstSameWeightOpponents() {
|
||||
MmaBantamweightFighter fighter = new MmaBantamweightFighter("Joe", "Johnson", "The Geek", "Muay Thai");
|
||||
MmaBantamweightFighter fighter =
|
||||
new MmaBantamweightFighter("Joe", "Johnson", "The Geek", "Muay Thai");
|
||||
List<MmaFighter<?>> opponents = getOpponents();
|
||||
List<MmaFighter<?>> challenged = new ArrayList<>();
|
||||
|
||||
opponents.forEach(challenger -> {
|
||||
try {
|
||||
((MmaBantamweightFighter) challenger).fight(fighter);
|
||||
challenged.add(challenger);
|
||||
} catch (ClassCastException e) {
|
||||
LOGGER.error(e.getMessage());
|
||||
}
|
||||
});
|
||||
opponents.forEach(
|
||||
challenger -> {
|
||||
try {
|
||||
((MmaBantamweightFighter) challenger).fight(fighter);
|
||||
challenged.add(challenger);
|
||||
} catch (ClassCastException e) {
|
||||
LOGGER.error(e.getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
assertFalse(challenged.isEmpty());
|
||||
assertTrue(challenged.stream().allMatch(c -> c instanceof MmaBantamweightFighter));
|
||||
@@ -62,13 +63,10 @@ public class FightTest {
|
||||
|
||||
private static List<MmaFighter<?>> getOpponents() {
|
||||
return List.of(
|
||||
new MmaBantamweightFighter("Ed", "Edwards", "The Problem Solver", "Judo"),
|
||||
new MmaLightweightFighter("Evan", "Evans", "Clean Coder", "Sambo"),
|
||||
new MmaHeavyweightFighter("Dave", "Davidson", "The Bug Smasher", "Kickboxing"),
|
||||
new MmaBantamweightFighter("Ray", "Raymond", "Scrum Master", "Karate"),
|
||||
new MmaHeavyweightFighter("Jack", "Jackson", "The Pragmatic", "Brazilian Jiu-Jitsu")
|
||||
);
|
||||
new MmaBantamweightFighter("Ed", "Edwards", "The Problem Solver", "Judo"),
|
||||
new MmaLightweightFighter("Evan", "Evans", "Clean Coder", "Sambo"),
|
||||
new MmaHeavyweightFighter("Dave", "Davidson", "The Bug Smasher", "Kickboxing"),
|
||||
new MmaBantamweightFighter("Ray", "Raymond", "Scrum Master", "Karate"),
|
||||
new MmaHeavyweightFighter("Jack", "Jackson", "The Pragmatic", "Brazilian Jiu-Jitsu"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user