Java 11 migrate c-d (remaining) (#1111)
* Moves converter pattern to Java 11 * Moves cqrs pattern to Java 11 * Moves dao pattern to Java 11 * Moves data-bus pattern to Java 11 * Moves data-locality pattern to Java 11 * Moves data-mapper pattern to Java 11 * Moves data-transfer-object pattern to Java 11 * Moves decorator pattern to Java 11 * Moves delegation pattern to Java 11 * Moves dependency-injection to Java 11 * Moves dirty-flag to Java 11 * Moves double-buffer to Java 11 * Moves double-checked-locking to Java 11 * Moves double-dispatch to Java 11 * Corrects with changes thats breaking test cases
This commit is contained in:
committed by
Ilkka Seppälä
parent
5681684157
commit
ea57934db6
@ -57,16 +57,17 @@ public class App {
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// initialize game objects and print their status
|
||||
List<GameObject> objects = List.of(
|
||||
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.stream().forEach(o -> LOGGER.info(o.toString()));
|
||||
new SpaceStationIss(12, 12, 14, 14)
|
||||
);
|
||||
objects.forEach(o -> LOGGER.info(o.toString()));
|
||||
LOGGER.info("");
|
||||
|
||||
// collision check
|
||||
objects.stream().forEach(o1 -> objects.stream().forEach(o2 -> {
|
||||
objects.forEach(o1 -> objects.forEach(o2 -> {
|
||||
if (o1 != o2 && o1.intersectsWith(o2)) {
|
||||
o1.collision(o2);
|
||||
}
|
||||
@ -74,7 +75,7 @@ public class App {
|
||||
LOGGER.info("");
|
||||
|
||||
// output eventual object statuses
|
||||
objects.stream().forEach(o -> LOGGER.info(o.toString()));
|
||||
objects.forEach(o -> LOGGER.info(o.toString()));
|
||||
LOGGER.info("");
|
||||
}
|
||||
}
|
||||
|
@ -26,15 +26,12 @@ package com.iluwatar.doubledispatch;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* Application test
|
||||
*
|
||||
*/
|
||||
public class AppTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
String[] args = {};
|
||||
App.main(args);
|
||||
App.main(new String[]{});
|
||||
}
|
||||
}
|
||||
|
@ -23,13 +23,13 @@
|
||||
|
||||
package com.iluwatar.doubledispatch;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Date: 12/10/15 - 8:37 PM
|
||||
* Test for Collision
|
||||
* Date: 12/10/15 - 8:37 PM Test for Collision
|
||||
*
|
||||
* @param <O> Type of GameObject
|
||||
* @author Jeroen Meulemeester
|
||||
*/
|
||||
@ -51,15 +51,14 @@ public abstract class CollisionTest<O extends GameObject> {
|
||||
* @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 description The expected description of the collision
|
||||
*/
|
||||
void testCollision(final GameObject other, final boolean otherDamaged, final boolean otherOnFire,
|
||||
final boolean thisDamaged, final boolean thisOnFire, final String description) {
|
||||
final boolean thisDamaged, final boolean thisOnFire) {
|
||||
|
||||
Objects.requireNonNull(other);
|
||||
Objects.requireNonNull(getTestedObject());
|
||||
|
||||
final O tested = getTestedObject();
|
||||
final var tested = getTestedObject();
|
||||
|
||||
tested.collision(other);
|
||||
|
||||
@ -80,10 +79,10 @@ public abstract class CollisionTest<O extends GameObject> {
|
||||
* @param expectTargetOnFire The expected state of fire on the target object
|
||||
*/
|
||||
private void testOnFire(final GameObject target, final GameObject other, final boolean expectTargetOnFire) {
|
||||
final String targetName = target.getClass().getSimpleName();
|
||||
final String otherName = other.getClass().getSimpleName();
|
||||
final var targetName = target.getClass().getSimpleName();
|
||||
final var otherName = other.getClass().getSimpleName();
|
||||
|
||||
final String errorMessage = expectTargetOnFire
|
||||
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!";
|
||||
|
||||
@ -99,10 +98,10 @@ public abstract class CollisionTest<O extends GameObject> {
|
||||
* @param expectedDamage The expected state of damage on the target object
|
||||
*/
|
||||
private void testDamaged(final GameObject target, final GameObject other, final boolean expectedDamage) {
|
||||
final String targetName = target.getClass().getSimpleName();
|
||||
final String otherName = other.getClass().getSimpleName();
|
||||
final var targetName = target.getClass().getSimpleName();
|
||||
final var otherName = other.getClass().getSimpleName();
|
||||
|
||||
final String errorMessage = expectedDamage
|
||||
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!";
|
||||
|
||||
|
@ -23,12 +23,12 @@
|
||||
|
||||
package com.iluwatar.doubledispatch;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Date: 12/10/15 - 11:31 PM
|
||||
*
|
||||
@ -46,7 +46,7 @@ public class FlamingAsteroidTest extends CollisionTest<FlamingAsteroid> {
|
||||
*/
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
final FlamingAsteroid asteroid = new FlamingAsteroid(1, 2, 3, 4);
|
||||
final var asteroid = new FlamingAsteroid(1, 2, 3, 4);
|
||||
assertEquals(1, asteroid.getLeft());
|
||||
assertEquals(2, asteroid.getTop());
|
||||
assertEquals(3, asteroid.getRight());
|
||||
@ -64,8 +64,7 @@ public class FlamingAsteroidTest extends CollisionTest<FlamingAsteroid> {
|
||||
testCollision(
|
||||
new FlamingAsteroid(1, 2, 3, 4),
|
||||
false, true,
|
||||
false, true,
|
||||
"FlamingAsteroid hits FlamingAsteroid."
|
||||
false, true
|
||||
);
|
||||
}
|
||||
|
||||
@ -77,8 +76,7 @@ public class FlamingAsteroidTest extends CollisionTest<FlamingAsteroid> {
|
||||
testCollision(
|
||||
new Meteoroid(1, 1, 3, 4),
|
||||
false, false,
|
||||
false, true,
|
||||
"FlamingAsteroid hits Meteoroid."
|
||||
false, true
|
||||
);
|
||||
}
|
||||
|
||||
@ -90,8 +88,7 @@ public class FlamingAsteroidTest extends CollisionTest<FlamingAsteroid> {
|
||||
testCollision(
|
||||
new SpaceStationIss(1, 1, 3, 4),
|
||||
true, true,
|
||||
false, true,
|
||||
"FlamingAsteroid hits SpaceStationIss. SpaceStationIss is damaged! SpaceStationIss is set on fire!"
|
||||
false, true
|
||||
);
|
||||
}
|
||||
|
||||
@ -103,8 +100,7 @@ public class FlamingAsteroidTest extends CollisionTest<FlamingAsteroid> {
|
||||
testCollision(
|
||||
new SpaceStationMir(1, 1, 3, 4),
|
||||
true, true,
|
||||
false, true,
|
||||
"FlamingAsteroid hits SpaceStationMir. SpaceStationMir is damaged! SpaceStationMir is set on fire!"
|
||||
false, true
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -23,11 +23,11 @@
|
||||
|
||||
package com.iluwatar.doubledispatch;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Date: 12/10/15 - 11:31 PM
|
||||
*
|
||||
@ -45,7 +45,7 @@ public class MeteoroidTest extends CollisionTest<Meteoroid> {
|
||||
*/
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
final Meteoroid meteoroid = new Meteoroid(1, 2, 3, 4);
|
||||
final var meteoroid = new Meteoroid(1, 2, 3, 4);
|
||||
assertEquals(1, meteoroid.getLeft());
|
||||
assertEquals(2, meteoroid.getTop());
|
||||
assertEquals(3, meteoroid.getRight());
|
||||
@ -63,8 +63,7 @@ public class MeteoroidTest extends CollisionTest<Meteoroid> {
|
||||
testCollision(
|
||||
new FlamingAsteroid(1, 1, 3, 4),
|
||||
false, true,
|
||||
false, false,
|
||||
"Meteoroid hits FlamingAsteroid."
|
||||
false, false
|
||||
);
|
||||
}
|
||||
|
||||
@ -76,8 +75,7 @@ public class MeteoroidTest extends CollisionTest<Meteoroid> {
|
||||
testCollision(
|
||||
new Meteoroid(1, 1, 3, 4),
|
||||
false, false,
|
||||
false, false,
|
||||
"Meteoroid hits Meteoroid."
|
||||
false, false
|
||||
);
|
||||
}
|
||||
|
||||
@ -89,8 +87,7 @@ public class MeteoroidTest extends CollisionTest<Meteoroid> {
|
||||
testCollision(
|
||||
new SpaceStationIss(1, 1, 3, 4),
|
||||
true, false,
|
||||
false, false,
|
||||
"Meteoroid hits SpaceStationIss. SpaceStationIss is damaged!"
|
||||
false, false
|
||||
);
|
||||
}
|
||||
|
||||
@ -102,8 +99,7 @@ public class MeteoroidTest extends CollisionTest<Meteoroid> {
|
||||
testCollision(
|
||||
new SpaceStationMir(1, 1, 3, 4),
|
||||
true, false,
|
||||
false, false,
|
||||
"Meteoroid hits SpaceStationMir. SpaceStationMir is damaged!"
|
||||
false, false
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -23,12 +23,12 @@
|
||||
|
||||
package com.iluwatar.doubledispatch;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit test for Rectangle
|
||||
*/
|
||||
@ -39,7 +39,7 @@ public class RectangleTest {
|
||||
*/
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
final Rectangle rectangle = new Rectangle(1, 2, 3, 4);
|
||||
final var rectangle = new Rectangle(1, 2, 3, 4);
|
||||
assertEquals(1, rectangle.getLeft());
|
||||
assertEquals(2, rectangle.getTop());
|
||||
assertEquals(3, rectangle.getRight());
|
||||
@ -52,7 +52,7 @@ public class RectangleTest {
|
||||
*/
|
||||
@Test
|
||||
public void testToString() throws Exception {
|
||||
final Rectangle rectangle = new Rectangle(1, 2, 3, 4);
|
||||
final var rectangle = new Rectangle(1, 2, 3, 4);
|
||||
assertEquals("[1,2,3,4]", rectangle.toString());
|
||||
}
|
||||
|
||||
|
@ -23,11 +23,11 @@
|
||||
|
||||
package com.iluwatar.doubledispatch;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Date: 12/10/15 - 11:31 PM
|
||||
*
|
||||
@ -45,7 +45,7 @@ public class SpaceStationIssTest extends CollisionTest<SpaceStationIss> {
|
||||
*/
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
final SpaceStationIss iss = new SpaceStationIss(1, 2, 3, 4);
|
||||
final var iss = new SpaceStationIss(1, 2, 3, 4);
|
||||
assertEquals(1, iss.getLeft());
|
||||
assertEquals(2, iss.getTop());
|
||||
assertEquals(3, iss.getRight());
|
||||
@ -63,8 +63,7 @@ public class SpaceStationIssTest extends CollisionTest<SpaceStationIss> {
|
||||
testCollision(
|
||||
new FlamingAsteroid(1, 1, 3, 4),
|
||||
false, true,
|
||||
false, false,
|
||||
"SpaceStationIss hits FlamingAsteroid."
|
||||
false, false
|
||||
);
|
||||
}
|
||||
|
||||
@ -76,8 +75,7 @@ public class SpaceStationIssTest extends CollisionTest<SpaceStationIss> {
|
||||
testCollision(
|
||||
new Meteoroid(1, 1, 3, 4),
|
||||
false, false,
|
||||
false, false,
|
||||
"SpaceStationIss hits Meteoroid."
|
||||
false, false
|
||||
);
|
||||
}
|
||||
|
||||
@ -89,8 +87,7 @@ public class SpaceStationIssTest extends CollisionTest<SpaceStationIss> {
|
||||
testCollision(
|
||||
new SpaceStationIss(1, 1, 3, 4),
|
||||
true, false,
|
||||
false, false,
|
||||
"SpaceStationIss hits SpaceStationIss. SpaceStationIss is damaged!"
|
||||
false, false
|
||||
);
|
||||
}
|
||||
|
||||
@ -102,8 +99,7 @@ public class SpaceStationIssTest extends CollisionTest<SpaceStationIss> {
|
||||
testCollision(
|
||||
new SpaceStationMir(1, 1, 3, 4),
|
||||
true, false,
|
||||
false, false,
|
||||
"SpaceStationIss hits SpaceStationMir. SpaceStationMir is damaged!"
|
||||
false, false
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -23,11 +23,11 @@
|
||||
|
||||
package com.iluwatar.doubledispatch;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Date: 12/10/15 - 11:31 PM
|
||||
*
|
||||
@ -45,7 +45,7 @@ public class SpaceStationMirTest extends CollisionTest<SpaceStationMir> {
|
||||
*/
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
final SpaceStationMir mir = new SpaceStationMir(1, 2, 3, 4);
|
||||
final var mir = new SpaceStationMir(1, 2, 3, 4);
|
||||
assertEquals(1, mir.getLeft());
|
||||
assertEquals(2, mir.getTop());
|
||||
assertEquals(3, mir.getRight());
|
||||
@ -63,8 +63,7 @@ public class SpaceStationMirTest extends CollisionTest<SpaceStationMir> {
|
||||
testCollision(
|
||||
new FlamingAsteroid(1, 1, 3, 4),
|
||||
false, true,
|
||||
false, false,
|
||||
"SpaceStationMir hits FlamingAsteroid."
|
||||
false, false
|
||||
);
|
||||
}
|
||||
|
||||
@ -76,8 +75,7 @@ public class SpaceStationMirTest extends CollisionTest<SpaceStationMir> {
|
||||
testCollision(
|
||||
new Meteoroid(1, 1, 3, 4),
|
||||
false, false,
|
||||
false, false,
|
||||
"SpaceStationMir hits Meteoroid."
|
||||
false, false
|
||||
);
|
||||
}
|
||||
|
||||
@ -89,8 +87,7 @@ public class SpaceStationMirTest extends CollisionTest<SpaceStationMir> {
|
||||
testCollision(
|
||||
new SpaceStationIss(1, 1, 3, 4),
|
||||
true, false,
|
||||
false, false,
|
||||
"SpaceStationMir hits SpaceStationIss. SpaceStationIss is damaged!"
|
||||
false, false
|
||||
);
|
||||
}
|
||||
|
||||
@ -102,8 +99,7 @@ public class SpaceStationMirTest extends CollisionTest<SpaceStationMir> {
|
||||
testCollision(
|
||||
new SpaceStationMir(1, 1, 3, 4),
|
||||
true, false,
|
||||
false, false,
|
||||
"SpaceStationMir hits SpaceStationMir. SpaceStationMir is damaged!"
|
||||
false, false
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user