Java 11 migrate 7 remaining f (#1115)

* Moves facade to Java 11

* Moves factory-kit to Java 11

* Moves factory-method to Java 11

* Moves feature-toggle to Java 11

* Moves fluentinterface to Java 11

* Moves flux to Java 11

* Moves flyweight to Java 11

* Moves front-controller to Java 11

* Uses stream properly

* Resolves issues with ci
This commit is contained in:
Anurag Agarwal
2019-12-22 18:11:19 +05:30
committed by Ilkka Seppälä
parent f835d3d516
commit 670c4e43f3
55 changed files with 377 additions and 429 deletions

View File

@@ -55,7 +55,7 @@ public class OrcBlacksmith implements Blacksmith {
Now as the customers come the correct type of blacksmith is summoned and requested weapons are manufactured
```java
Blacksmith blacksmith = new ElfBlacksmith();
var blacksmith = new ElfBlacksmith();
blacksmith.manufactureWeapon(WeaponType.SPEAR);
blacksmith.manufactureWeapon(WeaponType.AXE);
// Elvish weapons are created

View File

@@ -64,7 +64,7 @@ public class App {
*/
public static void main(String[] args) {
// Lets go to war with Orc weapons
App app = new App(new OrcBlacksmith());
var app = new App(new OrcBlacksmith());
app.manufactureWeapons();
// Lets go to war with Elf weapons
@@ -73,8 +73,7 @@ public class App {
}
private void manufactureWeapons() {
Weapon weapon;
weapon = blacksmith.manufactureWeapon(WeaponType.SPEAR);
var weapon = blacksmith.manufactureWeapon(WeaponType.SPEAR);
LOGGER.info(weapon.toString());
weapon = blacksmith.manufactureWeapon(WeaponType.AXE);
LOGGER.info(weapon.toString());

View File

@@ -23,6 +23,7 @@
package com.iluwatar.factory.method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -35,14 +36,12 @@ public class ElfBlacksmith implements Blacksmith {
static {
ELFARSENAL = new HashMap<>(WeaponType.values().length);
for (WeaponType type : WeaponType.values()) {
ELFARSENAL.put(type, new ElfWeapon(type));
}
Arrays.stream(WeaponType.values()).forEach(type -> ELFARSENAL.put(type, new ElfWeapon(type)));
}
@Override
public Weapon manufactureWeapon(WeaponType weaponType) {
return ELFARSENAL.get(weaponType);
}
}

View File

@@ -23,6 +23,7 @@
package com.iluwatar.factory.method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -35,9 +36,7 @@ public class OrcBlacksmith implements Blacksmith {
static {
ORCARSENAL = new HashMap<>(WeaponType.values().length);
for (WeaponType type : WeaponType.values()) {
ORCARSENAL.put(type, new OrcWeapon(type));
}
Arrays.stream(WeaponType.values()).forEach(type -> ORCARSENAL.put(type, new OrcWeapon(type)));
}
@Override

View File

@@ -25,15 +25,12 @@ package com.iluwatar.factory.method;
import org.junit.jupiter.api.Test;
import java.io.IOException;
/**
* Tests that Factory Method example runs without errors.
*/
public class AppTest {
@Test
public void test() throws IOException {
String[] args = {};
App.main(args);
public void test() {
App.main(new String[]{});
}
}

View File

@@ -23,79 +23,80 @@
package com.iluwatar.factory.method;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
/**
* The Factory Method is a creational design pattern which uses factory methods to deal with the
* problem of creating objects without specifying the exact class of object that will be created.
* This is done by creating objects via calling a factory method either specified in an interface
* and implemented by child classes, or implemented in a base class and optionally overridden by
* derived classes—rather than by calling a constructor.
*
* <p>Factory produces the object of its liking.
* The weapon {@link Weapon} manufactured by the
* blacksmith depends on the kind of factory implementation it is referring to.
*
* <p>Factory produces the object of its liking.
* The weapon {@link Weapon} manufactured by the blacksmith depends on the kind of factory
* implementation it is referring to.
* </p>
*/
public class FactoryMethodTest {
/**
* Testing {@link OrcBlacksmith} to produce a SPEAR asserting that the Weapon is an instance
* of {@link OrcWeapon}.
* Testing {@link OrcBlacksmith} to produce a SPEAR asserting that the Weapon is an instance of
* {@link OrcWeapon}.
*/
@Test
public void testOrcBlacksmithWithSpear() {
Blacksmith blacksmith = new OrcBlacksmith();
Weapon weapon = blacksmith.manufactureWeapon(WeaponType.SPEAR);
var blacksmith = new OrcBlacksmith();
var weapon = blacksmith.manufactureWeapon(WeaponType.SPEAR);
verifyWeapon(weapon, WeaponType.SPEAR, OrcWeapon.class);
}
/**
* Testing {@link OrcBlacksmith} to produce an AXE asserting that the Weapon is an instance
* of {@link OrcWeapon}.
* Testing {@link OrcBlacksmith} to produce an AXE asserting that the Weapon is an instance of
* {@link OrcWeapon}.
*/
@Test
public void testOrcBlacksmithWithAxe() {
Blacksmith blacksmith = new OrcBlacksmith();
Weapon weapon = blacksmith.manufactureWeapon(WeaponType.AXE);
var blacksmith = new OrcBlacksmith();
var weapon = blacksmith.manufactureWeapon(WeaponType.AXE);
verifyWeapon(weapon, WeaponType.AXE, OrcWeapon.class);
}
/**
* Testing {@link ElfBlacksmith} to produce a SHORT_SWORD asserting that the Weapon is an
* instance of {@link ElfWeapon}.
* Testing {@link ElfBlacksmith} to produce a SHORT_SWORD asserting that the Weapon is an instance
* of {@link ElfWeapon}.
*/
@Test
public void testElfBlacksmithWithShortSword() {
Blacksmith blacksmith = new ElfBlacksmith();
Weapon weapon = blacksmith.manufactureWeapon(WeaponType.SHORT_SWORD);
var blacksmith = new ElfBlacksmith();
var weapon = blacksmith.manufactureWeapon(WeaponType.SHORT_SWORD);
verifyWeapon(weapon, WeaponType.SHORT_SWORD, ElfWeapon.class);
}
/**
* Testing {@link ElfBlacksmith} to produce a SPEAR asserting that the Weapon is an instance
* of {@link ElfWeapon}.
* Testing {@link ElfBlacksmith} to produce a SPEAR asserting that the Weapon is an instance of
* {@link ElfWeapon}.
*/
@Test
public void testElfBlacksmithWithSpear() {
Blacksmith blacksmith = new ElfBlacksmith();
Weapon weapon = blacksmith.manufactureWeapon(WeaponType.SPEAR);
var blacksmith = new ElfBlacksmith();
var weapon = blacksmith.manufactureWeapon(WeaponType.SPEAR);
verifyWeapon(weapon, WeaponType.SPEAR, ElfWeapon.class);
}
/**
* This method asserts that the weapon object that is passed is an instance of the clazz and the
* weapon is of type expectedWeaponType.
*
* @param weapon weapon object which is to be verified
*
* @param weapon weapon object which is to be verified
* @param expectedWeaponType expected WeaponType of the weapon
* @param clazz expected class of the weapon
* @param clazz expected class of the weapon
*/
private void verifyWeapon(Weapon weapon, WeaponType expectedWeaponType, Class<?> clazz) {
assertTrue(clazz.isInstance(weapon), "Weapon must be an object of: " + clazz.getName());
assertEquals(expectedWeaponType, weapon.getWeaponType(), "Weapon must be of weaponType: " + expectedWeaponType);
assertEquals(expectedWeaponType, weapon
.getWeaponType(), "Weapon must be of weaponType: " + expectedWeaponType);
}
}