Java 11 migration: ambassador async-method-invocation balking bridge builder (#1076)
* Moves ambassador pattern to java 11 * Moves async-method-invocation pattern to java 11 * Moves balking pattern to java 11 * Moves bridge pattern to java 11 * Moves builder pattern to java 11
This commit is contained in:
committed by
Ilkka Seppälä
parent
f0f0143d48
commit
c4418311c6
@ -59,20 +59,22 @@ public class App {
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
Hero mage =
|
||||
new Hero.Builder(Profession.MAGE, "Riobard").withHairColor(HairColor.BLACK)
|
||||
.withWeapon(Weapon.DAGGER).build();
|
||||
var mage = new Hero.Builder(Profession.MAGE, "Riobard")
|
||||
.withHairColor(HairColor.BLACK)
|
||||
.withWeapon(Weapon.DAGGER)
|
||||
.build();
|
||||
LOGGER.info(mage.toString());
|
||||
|
||||
Hero warrior =
|
||||
new Hero.Builder(Profession.WARRIOR, "Amberjill").withHairColor(HairColor.BLOND)
|
||||
.withHairType(HairType.LONG_CURLY).withArmor(Armor.CHAIN_MAIL).withWeapon(Weapon.SWORD)
|
||||
.build();
|
||||
var warrior = new Hero.Builder(Profession.WARRIOR, "Amberjill")
|
||||
.withHairColor(HairColor.BLOND)
|
||||
.withHairType(HairType.LONG_CURLY).withArmor(Armor.CHAIN_MAIL).withWeapon(Weapon.SWORD)
|
||||
.build();
|
||||
LOGGER.info(warrior.toString());
|
||||
|
||||
Hero thief =
|
||||
new Hero.Builder(Profession.THIEF, "Desmond").withHairType(HairType.BALD)
|
||||
.withWeapon(Weapon.BOW).build();
|
||||
var thief = new Hero.Builder(Profession.THIEF, "Desmond")
|
||||
.withHairType(HairType.BALD)
|
||||
.withWeapon(Weapon.BOW)
|
||||
.build();
|
||||
LOGGER.info(thief.toString());
|
||||
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public enum Armor {
|
||||
|
||||
CLOTHES("clothes"), LEATHER("leather"), CHAIN_MAIL("chain mail"), PLATE_MAIL("plate mail");
|
||||
|
||||
private String title;
|
||||
private final String title;
|
||||
|
||||
Armor(String title) {
|
||||
this.title = title;
|
||||
|
@ -31,7 +31,7 @@ public enum HairType {
|
||||
BALD("bald"), SHORT("short"), CURLY("curly"), LONG_STRAIGHT("long straight"), LONG_CURLY(
|
||||
"long curly");
|
||||
|
||||
private String title;
|
||||
private final String title;
|
||||
|
||||
HairType(String title) {
|
||||
this.title = title;
|
||||
|
@ -71,7 +71,7 @@ public final class Hero {
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
var sb = new StringBuilder();
|
||||
sb.append("This is a ")
|
||||
.append(profession)
|
||||
.append(" named ")
|
||||
|
@ -26,15 +26,11 @@ package com.iluwatar.builder;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* Application test
|
||||
*
|
||||
*/
|
||||
public class AppTest {
|
||||
|
||||
class AppTest {
|
||||
@Test
|
||||
public void test() {
|
||||
String[] args = {};
|
||||
App.main(args);
|
||||
void test() {
|
||||
App.main(new String[]{});
|
||||
}
|
||||
}
|
||||
|
@ -23,24 +23,24 @@
|
||||
|
||||
package com.iluwatar.builder;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Date: 12/6/15 - 11:01 PM
|
||||
*
|
||||
* @author Jeroen Meulemeester
|
||||
*/
|
||||
public class HeroTest {
|
||||
class HeroTest {
|
||||
|
||||
/**
|
||||
* Test if we get the expected exception when trying to create a hero without a profession
|
||||
*/
|
||||
@Test
|
||||
public void testMissingProfession() throws Exception {
|
||||
void testMissingProfession() {
|
||||
assertThrows(IllegalArgumentException.class, () -> new Hero.Builder(null, "Sir without a job"));
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ public class HeroTest {
|
||||
* Test if we get the expected exception when trying to create a hero without a name
|
||||
*/
|
||||
@Test
|
||||
public void testMissingName() throws Exception {
|
||||
void testMissingName() {
|
||||
assertThrows(IllegalArgumentException.class, () -> new Hero.Builder(Profession.THIEF, null));
|
||||
}
|
||||
|
||||
@ -56,10 +56,10 @@ public class HeroTest {
|
||||
* Test if the hero build by the builder has the correct attributes, as requested
|
||||
*/
|
||||
@Test
|
||||
public void testBuildHero() throws Exception {
|
||||
void testBuildHero() {
|
||||
final String heroName = "Sir Lancelot";
|
||||
|
||||
final Hero hero = new Hero.Builder(Profession.WARRIOR, heroName)
|
||||
final var hero = new Hero.Builder(Profession.WARRIOR, heroName)
|
||||
.withArmor(Armor.CHAIN_MAIL)
|
||||
.withWeapon(Weapon.SWORD)
|
||||
.withHairType(HairType.LONG_CURLY)
|
||||
|
Reference in New Issue
Block a user