mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-08-18 04:28:04 +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:
@@ -27,16 +27,14 @@ package com.iluwatar.property;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Represents Character in game and his abilities (base stats).
|
||||
*/
|
||||
/** Represents Character in game and his abilities (base stats). */
|
||||
public class Character implements Prototype {
|
||||
|
||||
/**
|
||||
* Enumeration of Character types.
|
||||
*/
|
||||
/** Enumeration of Character types. */
|
||||
public enum Type {
|
||||
WARRIOR, MAGE, ROGUE
|
||||
WARRIOR,
|
||||
MAGE,
|
||||
ROGUE
|
||||
}
|
||||
|
||||
private final Prototype prototype;
|
||||
@@ -45,31 +43,30 @@ public class Character implements Prototype {
|
||||
private String name;
|
||||
private Type type;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
/** Constructor. */
|
||||
public Character() {
|
||||
this.prototype = new Prototype() { // Null-value object
|
||||
@Override
|
||||
public Integer get(Stats stat) {
|
||||
return null;
|
||||
}
|
||||
this.prototype =
|
||||
new Prototype() { // Null-value object
|
||||
@Override
|
||||
public Integer get(Stats stat) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(Stats stat) {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean has(Stats stat) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(Stats stat, Integer val) {
|
||||
// Does Nothing
|
||||
}
|
||||
@Override
|
||||
public void set(Stats stat, Integer val) {
|
||||
// Does Nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(Stats stat) {
|
||||
// Does Nothing.
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public void remove(Stats stat) {
|
||||
// Does Nothing.
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public Character(Type type, Prototype prototype) {
|
||||
@@ -77,9 +74,7 @@ public class Character implements Prototype {
|
||||
this.prototype = prototype;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
/** Constructor. */
|
||||
public Character(String name, Character prototype) {
|
||||
this.name = name;
|
||||
this.type = prototype.type;
|
||||
@@ -140,5 +135,4 @@ public class Character implements Prototype {
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,9 +24,7 @@
|
||||
*/
|
||||
package com.iluwatar.property;
|
||||
|
||||
/**
|
||||
* Interface for prototype inheritance.
|
||||
*/
|
||||
/** Interface for prototype inheritance. */
|
||||
public interface Prototype {
|
||||
|
||||
Integer get(Stats stat);
|
||||
|
||||
@@ -24,10 +24,14 @@
|
||||
*/
|
||||
package com.iluwatar.property;
|
||||
|
||||
/**
|
||||
* All possible attributes that Character can have.
|
||||
*/
|
||||
/** All possible attributes that Character can have. */
|
||||
public enum Stats {
|
||||
|
||||
AGILITY, STRENGTH, ATTACK_POWER, ARMOR, INTELLECT, SPIRIT, ENERGY, RAGE
|
||||
AGILITY,
|
||||
STRENGTH,
|
||||
ATTACK_POWER,
|
||||
ARMOR,
|
||||
INTELLECT,
|
||||
SPIRIT,
|
||||
ENERGY,
|
||||
RAGE
|
||||
}
|
||||
|
||||
@@ -24,17 +24,15 @@
|
||||
*/
|
||||
package com.iluwatar.property;
|
||||
|
||||
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 {
|
||||
|
||||
@Test
|
||||
void shouldExecuteWithoutException() {
|
||||
assertDoesNotThrow(() -> App.main(new String[]{}));
|
||||
assertDoesNotThrow(() -> App.main(new String[] {}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,10 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import java.util.Arrays;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* CharacterTest
|
||||
*
|
||||
*/
|
||||
/** CharacterTest */
|
||||
class CharacterTest {
|
||||
|
||||
@Test
|
||||
@@ -56,7 +53,6 @@ class CharacterTest {
|
||||
assertFalse(prototype.has(stat));
|
||||
assertNull(prototype.get(stat));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -78,7 +74,8 @@ class CharacterTest {
|
||||
prototype.set(Stats.ARMOR, 1);
|
||||
prototype.set(Stats.AGILITY, 2);
|
||||
prototype.set(Stats.INTELLECT, 3);
|
||||
var message = """
|
||||
var message =
|
||||
"""
|
||||
Stats:
|
||||
- AGILITY:2
|
||||
- ARMOR:1
|
||||
@@ -88,7 +85,8 @@ class CharacterTest {
|
||||
|
||||
final var stupid = new Character(Type.ROGUE, prototype);
|
||||
stupid.remove(Stats.INTELLECT);
|
||||
String expectedStupidString = """
|
||||
String expectedStupidString =
|
||||
"""
|
||||
Character type: ROGUE
|
||||
Stats:
|
||||
- AGILITY:2
|
||||
@@ -98,14 +96,14 @@ class CharacterTest {
|
||||
|
||||
final var weak = new Character("weak", prototype);
|
||||
weak.remove(Stats.ARMOR);
|
||||
String expectedWeakString = """
|
||||
String expectedWeakString =
|
||||
"""
|
||||
Player: weak
|
||||
Stats:
|
||||
- AGILITY:2
|
||||
- INTELLECT:3
|
||||
""";
|
||||
assertEquals(expectedWeakString, weak.toString());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -139,5 +137,4 @@ class CharacterTest {
|
||||
weak.remove(Stats.ARMOR);
|
||||
assertNull(weak.type());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user