mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-21 00:24:17 +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:
@@ -37,9 +37,9 @@ import lombok.extern.slf4j.Slf4j;
|
||||
* to change the method's implementation and add a new instanceof-check. This violates the single
|
||||
* responsibility principle - a class should have only one reason to change.
|
||||
*
|
||||
* <p>Instead of the instanceof-checks a better way is to make another virtual call on the
|
||||
* parameter object. This way new functionality can be easily added without the need to modify
|
||||
* existing implementation (open-closed principle).
|
||||
* <p>Instead of the instanceof-checks a better way is to make another virtual call on the parameter
|
||||
* object. This way new functionality can be easily added without the need to modify existing
|
||||
* implementation (open-closed principle).
|
||||
*
|
||||
* <p>In this example we have hierarchy of objects ({@link GameObject}) that can collide to each
|
||||
* other. Each object has its own coordinates which are checked against the other objects'
|
||||
@@ -57,21 +57,24 @@ public class App {
|
||||
public static void main(String[] args) {
|
||||
// initialize game objects and print their status
|
||||
LOGGER.info("Init objects and print their status");
|
||||
var objects = List.of(
|
||||
new FlamingAsteroid(0, 0, 5, 5),
|
||||
new SpaceStationMir(1, 1, 2, 2),
|
||||
new Meteoroid(10, 10, 15, 15),
|
||||
new SpaceStationIss(12, 12, 14, 14)
|
||||
);
|
||||
var objects =
|
||||
List.of(
|
||||
new FlamingAsteroid(0, 0, 5, 5),
|
||||
new SpaceStationMir(1, 1, 2, 2),
|
||||
new Meteoroid(10, 10, 15, 15),
|
||||
new SpaceStationIss(12, 12, 14, 14));
|
||||
objects.forEach(o -> LOGGER.info(o.toString()));
|
||||
|
||||
// collision check
|
||||
LOGGER.info("Collision check");
|
||||
objects.forEach(o1 -> objects.forEach(o2 -> {
|
||||
if (o1 != o2 && o1.intersectsWith(o2)) {
|
||||
o1.collision(o2);
|
||||
}
|
||||
}));
|
||||
objects.forEach(
|
||||
o1 ->
|
||||
objects.forEach(
|
||||
o2 -> {
|
||||
if (o1 != o2 && o1.intersectsWith(o2)) {
|
||||
o1.collision(o2);
|
||||
}
|
||||
}));
|
||||
|
||||
// output eventual object statuses
|
||||
LOGGER.info("Print object status after collision checks");
|
||||
|
||||
@@ -24,9 +24,7 @@
|
||||
*/
|
||||
package com.iluwatar.doubledispatch;
|
||||
|
||||
/**
|
||||
* Flaming asteroid game object.
|
||||
*/
|
||||
/** Flaming asteroid game object. */
|
||||
public class FlamingAsteroid extends Meteoroid {
|
||||
|
||||
public FlamingAsteroid(int left, int top, int right, int bottom) {
|
||||
|
||||
@@ -27,9 +27,7 @@ package com.iluwatar.doubledispatch;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Game objects have coordinates and some other status information.
|
||||
*/
|
||||
/** Game objects have coordinates and some other status information. */
|
||||
@Getter
|
||||
@Setter
|
||||
public abstract class GameObject extends Rectangle {
|
||||
@@ -43,8 +41,9 @@ public abstract class GameObject extends Rectangle {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s at %s damaged=%b onFire=%b", this.getClass().getSimpleName(),
|
||||
super.toString(), isDamaged(), isOnFire());
|
||||
return String.format(
|
||||
"%s at %s damaged=%b onFire=%b",
|
||||
this.getClass().getSimpleName(), super.toString(), isDamaged(), isOnFire());
|
||||
}
|
||||
|
||||
public abstract void collision(GameObject gameObject);
|
||||
|
||||
@@ -27,9 +27,7 @@ package com.iluwatar.doubledispatch;
|
||||
import com.iluwatar.doubledispatch.constants.AppConstants;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Meteoroid game object.
|
||||
*/
|
||||
/** Meteoroid game object. */
|
||||
@Slf4j
|
||||
public class Meteoroid extends GameObject {
|
||||
|
||||
@@ -44,14 +42,14 @@ public class Meteoroid extends GameObject {
|
||||
|
||||
@Override
|
||||
public void collisionResolve(FlamingAsteroid asteroid) {
|
||||
LOGGER.info(AppConstants.HITS, asteroid.getClass().getSimpleName(), this.getClass()
|
||||
.getSimpleName());
|
||||
LOGGER.info(
|
||||
AppConstants.HITS, asteroid.getClass().getSimpleName(), this.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collisionResolve(Meteoroid meteoroid) {
|
||||
LOGGER.info(AppConstants.HITS, meteoroid.getClass().getSimpleName(), this.getClass()
|
||||
.getSimpleName());
|
||||
LOGGER.info(
|
||||
AppConstants.HITS, meteoroid.getClass().getSimpleName(), this.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,9 +27,7 @@ package com.iluwatar.doubledispatch;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* Rectangle has coordinates and can be checked for overlap against other Rectangles.
|
||||
*/
|
||||
/** Rectangle has coordinates and can be checked for overlap against other Rectangles. */
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public class Rectangle {
|
||||
@@ -40,8 +38,10 @@ public class Rectangle {
|
||||
private final int bottom;
|
||||
|
||||
boolean intersectsWith(Rectangle r) {
|
||||
return !(r.getLeft() > getRight() || r.getRight() < getLeft() || r.getTop() > getBottom() || r
|
||||
.getBottom() < getTop());
|
||||
return !(r.getLeft() > getRight()
|
||||
|| r.getRight() < getLeft()
|
||||
|| r.getTop() > getBottom()
|
||||
|| r.getBottom() < getTop());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,9 +24,7 @@
|
||||
*/
|
||||
package com.iluwatar.doubledispatch;
|
||||
|
||||
/**
|
||||
* Space station ISS game object.
|
||||
*/
|
||||
/** Space station ISS game object. */
|
||||
public class SpaceStationIss extends SpaceStationMir {
|
||||
|
||||
public SpaceStationIss(int left, int top, int right, int bottom) {
|
||||
|
||||
@@ -27,9 +27,7 @@ package com.iluwatar.doubledispatch;
|
||||
import com.iluwatar.doubledispatch.constants.AppConstants;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Space station Mir game object.
|
||||
*/
|
||||
/** Space station Mir game object. */
|
||||
@Slf4j
|
||||
public class SpaceStationMir extends GameObject {
|
||||
|
||||
@@ -44,10 +42,12 @@ public class SpaceStationMir extends GameObject {
|
||||
|
||||
@Override
|
||||
public void collisionResolve(FlamingAsteroid asteroid) {
|
||||
LOGGER.info(AppConstants.HITS + " {} is damaged! {} is set on fire!", asteroid.getClass()
|
||||
.getSimpleName(),
|
||||
this.getClass().getSimpleName(), this.getClass().getSimpleName(), this.getClass()
|
||||
.getSimpleName());
|
||||
LOGGER.info(
|
||||
AppConstants.HITS + " {} is damaged! {} is set on fire!",
|
||||
asteroid.getClass().getSimpleName(),
|
||||
this.getClass().getSimpleName(),
|
||||
this.getClass().getSimpleName(),
|
||||
this.getClass().getSimpleName());
|
||||
setDamaged(true);
|
||||
setOnFire(true);
|
||||
}
|
||||
@@ -71,7 +71,11 @@ public class SpaceStationMir extends GameObject {
|
||||
}
|
||||
|
||||
private void logHits(GameObject gameObject) {
|
||||
LOGGER.info(AppConstants.HITS, " {} is damaged!", gameObject.getClass().getSimpleName(),
|
||||
this.getClass().getSimpleName(), this.getClass().getSimpleName());
|
||||
LOGGER.info(
|
||||
AppConstants.HITS,
|
||||
" {} is damaged!",
|
||||
gameObject.getClass().getSimpleName(),
|
||||
this.getClass().getSimpleName(),
|
||||
this.getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -24,9 +24,7 @@
|
||||
*/
|
||||
package com.iluwatar.doubledispatch.constants;
|
||||
|
||||
/**
|
||||
* Constants class to define all constants.
|
||||
*/
|
||||
/** Constants class to define all constants. */
|
||||
public class AppConstants {
|
||||
|
||||
public static final String HITS = "{} hits {}.";
|
||||
|
||||
@@ -24,24 +24,19 @@
|
||||
*/
|
||||
package com.iluwatar.doubledispatch;
|
||||
|
||||
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#main(String[])}
|
||||
* throws an exception.
|
||||
* 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#main(String[])} throws an exception.
|
||||
*/
|
||||
|
||||
|
||||
@Test
|
||||
void shouldExecuteApplicationWithoutException() {
|
||||
assertDoesNotThrow(() -> App.main(new String[]{}));
|
||||
assertDoesNotThrow(() -> App.main(new String[] {}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,14 +46,18 @@ public abstract class CollisionTest<O extends GameObject> {
|
||||
* Collide the tested item with the other given item and verify if the damage and fire state is as
|
||||
* expected
|
||||
*
|
||||
* @param other The other object we have to collide with
|
||||
* @param other The other object we have to collide with
|
||||
* @param otherDamaged Indicates if the other object should be damaged after the collision
|
||||
* @param otherOnFire Indicates if the other object should be burning after the collision
|
||||
* @param thisDamaged Indicates if the test object should be damaged after the collision
|
||||
* @param thisOnFire Indicates if the other object should be burning after the collision
|
||||
* @param otherOnFire Indicates if the other object should be burning after the collision
|
||||
* @param thisDamaged Indicates if the test object should be damaged after the collision
|
||||
* @param thisOnFire Indicates if the other object should be burning after the collision
|
||||
*/
|
||||
void testCollision(final GameObject other, final boolean otherDamaged, final boolean otherOnFire,
|
||||
final boolean thisDamaged, final boolean thisOnFire) {
|
||||
void testCollision(
|
||||
final GameObject other,
|
||||
final boolean otherDamaged,
|
||||
final boolean otherOnFire,
|
||||
final boolean thisDamaged,
|
||||
final boolean thisOnFire) {
|
||||
|
||||
Objects.requireNonNull(other);
|
||||
Objects.requireNonNull(getTestedObject());
|
||||
@@ -67,24 +71,33 @@ public abstract class CollisionTest<O extends GameObject> {
|
||||
|
||||
testOnFire(tested, other, thisOnFire);
|
||||
testDamaged(tested, other, thisDamaged);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the fire state of the target matches the expected state after colliding with the given
|
||||
* object
|
||||
*
|
||||
* @param target The target object
|
||||
* @param other The other object
|
||||
* @param target The target object
|
||||
* @param other The other object
|
||||
* @param expectTargetOnFire The expected state of fire on the target object
|
||||
*/
|
||||
private void testOnFire(final GameObject target, final GameObject other, final boolean expectTargetOnFire) {
|
||||
private void testOnFire(
|
||||
final GameObject target, final GameObject other, final boolean expectTargetOnFire) {
|
||||
final var targetName = target.getClass().getSimpleName();
|
||||
final var otherName = other.getClass().getSimpleName();
|
||||
|
||||
final var errorMessage = expectTargetOnFire
|
||||
? "Expected [" + targetName + "] to be on fire after colliding with [" + otherName + "] but it was not!"
|
||||
: "Expected [" + targetName + "] not to be on fire after colliding with [" + otherName + "] but it was!";
|
||||
final var errorMessage =
|
||||
expectTargetOnFire
|
||||
? "Expected ["
|
||||
+ targetName
|
||||
+ "] to be on fire after colliding with ["
|
||||
+ otherName
|
||||
+ "] but it was not!"
|
||||
: "Expected ["
|
||||
+ targetName
|
||||
+ "] not to be on fire after colliding with ["
|
||||
+ otherName
|
||||
+ "] but it was!";
|
||||
|
||||
assertEquals(expectTargetOnFire, target.isOnFire(), errorMessage);
|
||||
}
|
||||
@@ -93,19 +106,28 @@ public abstract class CollisionTest<O extends GameObject> {
|
||||
* Test if the damage state of the target matches the expected state after colliding with the
|
||||
* given object
|
||||
*
|
||||
* @param target The target object
|
||||
* @param other The other object
|
||||
* @param target The target object
|
||||
* @param other The other object
|
||||
* @param expectedDamage The expected state of damage on the target object
|
||||
*/
|
||||
private void testDamaged(final GameObject target, final GameObject other, final boolean expectedDamage) {
|
||||
private void testDamaged(
|
||||
final GameObject target, final GameObject other, final boolean expectedDamage) {
|
||||
final var targetName = target.getClass().getSimpleName();
|
||||
final var otherName = other.getClass().getSimpleName();
|
||||
|
||||
final var errorMessage = expectedDamage
|
||||
? "Expected [" + targetName + "] to be damaged after colliding with [" + otherName + "] but it was not!"
|
||||
: "Expected [" + targetName + "] not to be damaged after colliding with [" + otherName + "] but it was!";
|
||||
final var errorMessage =
|
||||
expectedDamage
|
||||
? "Expected ["
|
||||
+ targetName
|
||||
+ "] to be damaged after colliding with ["
|
||||
+ otherName
|
||||
+ "] but it was not!"
|
||||
: "Expected ["
|
||||
+ targetName
|
||||
+ "] not to be damaged after colliding with ["
|
||||
+ otherName
|
||||
+ "] but it was!";
|
||||
|
||||
assertEquals(expectedDamage, target.isDamaged(), errorMessage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+11
-41
@@ -30,10 +30,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* FlamingAsteroidTest
|
||||
*
|
||||
*/
|
||||
/** FlamingAsteroidTest */
|
||||
class FlamingAsteroidTest extends CollisionTest<FlamingAsteroid> {
|
||||
|
||||
@Override
|
||||
@@ -41,9 +38,7 @@ class FlamingAsteroidTest extends CollisionTest<FlamingAsteroid> {
|
||||
return new FlamingAsteroid(1, 2, 3, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the constructor parameters
|
||||
*/
|
||||
/** Test the constructor parameters */
|
||||
@Test
|
||||
void testConstructor() {
|
||||
final var asteroid = new FlamingAsteroid(1, 2, 3, 4);
|
||||
@@ -56,52 +51,27 @@ class FlamingAsteroidTest extends CollisionTest<FlamingAsteroid> {
|
||||
assertEquals("FlamingAsteroid at [1,2,3,4] damaged=false onFire=true", asteroid.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test what happens we collide with an asteroid
|
||||
*/
|
||||
/** Test what happens we collide with an asteroid */
|
||||
@Test
|
||||
void testCollideFlamingAsteroid() {
|
||||
testCollision(
|
||||
new FlamingAsteroid(1, 2, 3, 4),
|
||||
false, true,
|
||||
false, true
|
||||
);
|
||||
testCollision(new FlamingAsteroid(1, 2, 3, 4), false, true, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test what happens we collide with an meteoroid
|
||||
*/
|
||||
/** Test what happens we collide with an meteoroid */
|
||||
@Test
|
||||
void testCollideMeteoroid() {
|
||||
testCollision(
|
||||
new Meteoroid(1, 1, 3, 4),
|
||||
false, false,
|
||||
false, true
|
||||
);
|
||||
testCollision(new Meteoroid(1, 1, 3, 4), false, false, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test what happens we collide with ISS
|
||||
*/
|
||||
/** Test what happens we collide with ISS */
|
||||
@Test
|
||||
void testCollideSpaceStationIss() {
|
||||
testCollision(
|
||||
new SpaceStationIss(1, 1, 3, 4),
|
||||
true, true,
|
||||
false, true
|
||||
);
|
||||
testCollision(new SpaceStationIss(1, 1, 3, 4), true, true, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test what happens we collide with MIR
|
||||
*/
|
||||
/** Test what happens we collide with MIR */
|
||||
@Test
|
||||
void testCollideSpaceStationMir() {
|
||||
testCollision(
|
||||
new SpaceStationMir(1, 1, 3, 4),
|
||||
true, true,
|
||||
false, true
|
||||
);
|
||||
testCollision(new SpaceStationMir(1, 1, 3, 4), true, true, false, true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,10 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* MeteoroidTest
|
||||
*
|
||||
*/
|
||||
/** MeteoroidTest */
|
||||
class MeteoroidTest extends CollisionTest<Meteoroid> {
|
||||
|
||||
@Override
|
||||
@@ -40,9 +37,7 @@ class MeteoroidTest extends CollisionTest<Meteoroid> {
|
||||
return new Meteoroid(1, 2, 3, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the constructor parameters
|
||||
*/
|
||||
/** Test the constructor parameters */
|
||||
@Test
|
||||
void testConstructor() {
|
||||
final var meteoroid = new Meteoroid(1, 2, 3, 4);
|
||||
@@ -55,52 +50,27 @@ class MeteoroidTest extends CollisionTest<Meteoroid> {
|
||||
assertEquals("Meteoroid at [1,2,3,4] damaged=false onFire=false", meteoroid.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test what happens we collide with an asteroid
|
||||
*/
|
||||
/** Test what happens we collide with an asteroid */
|
||||
@Test
|
||||
void testCollideFlamingAsteroid() {
|
||||
testCollision(
|
||||
new FlamingAsteroid(1, 1, 3, 4),
|
||||
false, true,
|
||||
false, false
|
||||
);
|
||||
testCollision(new FlamingAsteroid(1, 1, 3, 4), false, true, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test what happens we collide with an meteoroid
|
||||
*/
|
||||
/** Test what happens we collide with an meteoroid */
|
||||
@Test
|
||||
void testCollideMeteoroid() {
|
||||
testCollision(
|
||||
new Meteoroid(1, 1, 3, 4),
|
||||
false, false,
|
||||
false, false
|
||||
);
|
||||
testCollision(new Meteoroid(1, 1, 3, 4), false, false, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test what happens we collide with ISS
|
||||
*/
|
||||
/** Test what happens we collide with ISS */
|
||||
@Test
|
||||
void testCollideSpaceStationIss() {
|
||||
testCollision(
|
||||
new SpaceStationIss(1, 1, 3, 4),
|
||||
true, false,
|
||||
false, false
|
||||
);
|
||||
testCollision(new SpaceStationIss(1, 1, 3, 4), true, false, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test what happens we collide with MIR
|
||||
*/
|
||||
/** Test what happens we collide with MIR */
|
||||
@Test
|
||||
void testCollideSpaceStationMir() {
|
||||
testCollision(
|
||||
new SpaceStationMir(1, 1, 3, 4),
|
||||
true, false,
|
||||
false, false
|
||||
);
|
||||
testCollision(new SpaceStationMir(1, 1, 3, 4), true, false, false, false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,9 +30,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit test for Rectangle
|
||||
*/
|
||||
/** Unit test for Rectangle */
|
||||
class RectangleTest {
|
||||
|
||||
/**
|
||||
@@ -48,8 +46,7 @@ class RectangleTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the values passed through the constructor matches the values in the {@link
|
||||
* #toString()}
|
||||
* Test if the values passed through the constructor matches the values in the {@link #toString()}
|
||||
*/
|
||||
@Test
|
||||
void testToString() {
|
||||
@@ -57,9 +54,7 @@ class RectangleTest {
|
||||
assertEquals("[1,2,3,4]", rectangle.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the {@link Rectangle} class can detect if it intersects with another rectangle.
|
||||
*/
|
||||
/** Test if the {@link Rectangle} class can detect if it intersects with another rectangle. */
|
||||
@Test
|
||||
void testIntersection() {
|
||||
assertTrue(new Rectangle(0, 0, 1, 1).intersectsWith(new Rectangle(0, 0, 1, 1)));
|
||||
@@ -67,5 +62,4 @@ class RectangleTest {
|
||||
assertFalse(new Rectangle(0, 0, 1, 1).intersectsWith(new Rectangle(2, 2, 3, 3)));
|
||||
assertFalse(new Rectangle(0, 0, 1, 1).intersectsWith(new Rectangle(-2, -2, -1, -1)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+11
-41
@@ -29,10 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* SpaceStationIssTest
|
||||
*
|
||||
*/
|
||||
/** SpaceStationIssTest */
|
||||
class SpaceStationIssTest extends CollisionTest<SpaceStationIss> {
|
||||
|
||||
@Override
|
||||
@@ -40,9 +37,7 @@ class SpaceStationIssTest extends CollisionTest<SpaceStationIss> {
|
||||
return new SpaceStationIss(1, 2, 3, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the constructor parameters
|
||||
*/
|
||||
/** Test the constructor parameters */
|
||||
@Test
|
||||
void testConstructor() {
|
||||
final var iss = new SpaceStationIss(1, 2, 3, 4);
|
||||
@@ -55,52 +50,27 @@ class SpaceStationIssTest extends CollisionTest<SpaceStationIss> {
|
||||
assertEquals("SpaceStationIss at [1,2,3,4] damaged=false onFire=false", iss.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test what happens we collide with an asteroid
|
||||
*/
|
||||
/** Test what happens we collide with an asteroid */
|
||||
@Test
|
||||
void testCollideFlamingAsteroid() {
|
||||
testCollision(
|
||||
new FlamingAsteroid(1, 1, 3, 4),
|
||||
false, true,
|
||||
false, false
|
||||
);
|
||||
testCollision(new FlamingAsteroid(1, 1, 3, 4), false, true, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test what happens we collide with an meteoroid
|
||||
*/
|
||||
/** Test what happens we collide with an meteoroid */
|
||||
@Test
|
||||
void testCollideMeteoroid() {
|
||||
testCollision(
|
||||
new Meteoroid(1, 1, 3, 4),
|
||||
false, false,
|
||||
false, false
|
||||
);
|
||||
testCollision(new Meteoroid(1, 1, 3, 4), false, false, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test what happens we collide with ISS
|
||||
*/
|
||||
/** Test what happens we collide with ISS */
|
||||
@Test
|
||||
void testCollideSpaceStationIss() {
|
||||
testCollision(
|
||||
new SpaceStationIss(1, 1, 3, 4),
|
||||
true, false,
|
||||
false, false
|
||||
);
|
||||
testCollision(new SpaceStationIss(1, 1, 3, 4), true, false, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test what happens we collide with MIR
|
||||
*/
|
||||
/** Test what happens we collide with MIR */
|
||||
@Test
|
||||
void testCollideSpaceStationMir() {
|
||||
testCollision(
|
||||
new SpaceStationMir(1, 1, 3, 4),
|
||||
true, false,
|
||||
false, false
|
||||
);
|
||||
testCollision(new SpaceStationMir(1, 1, 3, 4), true, false, false, false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+11
-41
@@ -29,10 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* SpaceStationMirTest
|
||||
*
|
||||
*/
|
||||
/** SpaceStationMirTest */
|
||||
class SpaceStationMirTest extends CollisionTest<SpaceStationMir> {
|
||||
|
||||
@Override
|
||||
@@ -40,9 +37,7 @@ class SpaceStationMirTest extends CollisionTest<SpaceStationMir> {
|
||||
return new SpaceStationMir(1, 2, 3, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the constructor parameters
|
||||
*/
|
||||
/** Test the constructor parameters */
|
||||
@Test
|
||||
void testConstructor() {
|
||||
final var mir = new SpaceStationMir(1, 2, 3, 4);
|
||||
@@ -55,52 +50,27 @@ class SpaceStationMirTest extends CollisionTest<SpaceStationMir> {
|
||||
assertEquals("SpaceStationMir at [1,2,3,4] damaged=false onFire=false", mir.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test what happens we collide with an asteroid
|
||||
*/
|
||||
/** Test what happens we collide with an asteroid */
|
||||
@Test
|
||||
void testCollideFlamingAsteroid() {
|
||||
testCollision(
|
||||
new FlamingAsteroid(1, 1, 3, 4),
|
||||
false, true,
|
||||
false, false
|
||||
);
|
||||
testCollision(new FlamingAsteroid(1, 1, 3, 4), false, true, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test what happens we collide with an meteoroid
|
||||
*/
|
||||
/** Test what happens we collide with an meteoroid */
|
||||
@Test
|
||||
void testCollideMeteoroid() {
|
||||
testCollision(
|
||||
new Meteoroid(1, 1, 3, 4),
|
||||
false, false,
|
||||
false, false
|
||||
);
|
||||
testCollision(new Meteoroid(1, 1, 3, 4), false, false, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test what happens we collide with ISS
|
||||
*/
|
||||
/** Test what happens we collide with ISS */
|
||||
@Test
|
||||
void testCollideSpaceStationIss() {
|
||||
testCollision(
|
||||
new SpaceStationIss(1, 1, 3, 4),
|
||||
true, false,
|
||||
false, false
|
||||
);
|
||||
testCollision(new SpaceStationIss(1, 1, 3, 4), true, false, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test what happens we collide with MIR
|
||||
*/
|
||||
/** Test what happens we collide with MIR */
|
||||
@Test
|
||||
void testCollideSpaceStationMir() {
|
||||
testCollision(
|
||||
new SpaceStationMir(1, 1, 3, 4),
|
||||
true, false,
|
||||
false, false
|
||||
);
|
||||
testCollision(new SpaceStationMir(1, 1, 3, 4), true, false, false, false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user