1) Removed warning from test case. 2) Made implementation of App more understandable.
This commit is contained in:
parent
57be8aa522
commit
f64ba22c64
@ -38,25 +38,40 @@ package com.iluwatar.factory.method;
|
||||
*/
|
||||
public class App {
|
||||
|
||||
private final Blacksmith blacksmith;
|
||||
|
||||
/**
|
||||
* Creates an instance of <code>App</code> which will use <code>blacksmith</code> to manufacture
|
||||
* the weapons for war.
|
||||
* <code>App</code> is unaware which concrete implementation of {@link Blacksmith} it is using.
|
||||
* The decision of which blacksmith implementation to use may depend on configuration, or
|
||||
* the type of rival in war.
|
||||
* @param blacksmith
|
||||
*/
|
||||
public App(Blacksmith blacksmith) {
|
||||
this.blacksmith = blacksmith;
|
||||
}
|
||||
|
||||
/**
|
||||
* Program entry point
|
||||
*
|
||||
* @param args command line args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
Blacksmith blacksmith;
|
||||
// Lets go to war with Orc weapons
|
||||
App app = new App(new OrcBlacksmith());
|
||||
app.manufactureWeapons();
|
||||
|
||||
// Lets go to war with Elf weapons
|
||||
app = new App(new ElfBlacksmith());
|
||||
app.manufactureWeapons();
|
||||
}
|
||||
|
||||
private void manufactureWeapons() {
|
||||
Weapon weapon;
|
||||
|
||||
blacksmith = new OrcBlacksmith();
|
||||
weapon = blacksmith.manufactureWeapon(WeaponType.SPEAR);
|
||||
System.out.println(weapon);
|
||||
weapon = blacksmith.manufactureWeapon(WeaponType.AXE);
|
||||
System.out.println(weapon);
|
||||
|
||||
blacksmith = new ElfBlacksmith();
|
||||
weapon = blacksmith.manufactureWeapon(WeaponType.SHORT_SWORD);
|
||||
System.out.println(weapon);
|
||||
weapon = blacksmith.manufactureWeapon(WeaponType.SPEAR);
|
||||
System.out.println(weapon);
|
||||
}
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ public class FactoryMethodTest {
|
||||
* @param expectedWeaponType expected WeaponType of the weapon
|
||||
* @param clazz expected class of the weapon
|
||||
*/
|
||||
private void verifyWeapon(Weapon weapon, WeaponType expectedWeaponType, Class clazz) {
|
||||
private void verifyWeapon(Weapon weapon, WeaponType expectedWeaponType, Class<?> clazz) {
|
||||
assertTrue("Weapon must be an object of: " + clazz.getName(), clazz.isInstance(weapon));
|
||||
assertEquals("Weapon must be of weaponType: " + clazz.getName(), expectedWeaponType,
|
||||
weapon.getWeaponType());
|
||||
|
Loading…
x
Reference in New Issue
Block a user