Improved unit tests so assertions are used.
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* The essence of the Abstract Factory pattern is a factory interface
|
||||
@ -12,26 +13,61 @@ package com.iluwatar.abstractfactory;
|
||||
*/
|
||||
public class App {
|
||||
|
||||
/**
|
||||
* Program entry point
|
||||
* @param args command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
createKingdom(new ElfKingdomFactory());
|
||||
createKingdom(new OrcKingdomFactory());
|
||||
}
|
||||
private King king;
|
||||
private Castle castle;
|
||||
private Army army;
|
||||
|
||||
/**
|
||||
* Creates kingdom
|
||||
* @param factory
|
||||
*/
|
||||
public static void createKingdom(KingdomFactory factory) {
|
||||
King king = factory.createKing();
|
||||
Castle castle = factory.createCastle();
|
||||
Army army = factory.createArmy();
|
||||
System.out.println("The kingdom was created.");
|
||||
System.out.println(king);
|
||||
System.out.println(castle);
|
||||
System.out.println(army);
|
||||
public void createKingdom(final KingdomFactory factory) {
|
||||
setKing(factory.createKing());
|
||||
setCastle(factory.createCastle());
|
||||
setArmy(factory.createArmy());
|
||||
}
|
||||
|
||||
ElfKingdomFactory getElfKingdomFactory() {
|
||||
return new ElfKingdomFactory();
|
||||
}
|
||||
|
||||
OrcKingdomFactory getOrcKingdomFactory() {
|
||||
return new OrcKingdomFactory();
|
||||
}
|
||||
|
||||
King getKing(final KingdomFactory factory) {
|
||||
return factory.createKing();
|
||||
}
|
||||
|
||||
Castle getCastle(final KingdomFactory factory) {
|
||||
return factory.createCastle();
|
||||
}
|
||||
|
||||
Army getArmy(final KingdomFactory factory) {
|
||||
return factory.createArmy();
|
||||
}
|
||||
|
||||
public King getKing() {
|
||||
return king;
|
||||
}
|
||||
|
||||
private void setKing(final King king) {
|
||||
this.king = king;
|
||||
}
|
||||
|
||||
public Castle getCastle() {
|
||||
return castle;
|
||||
}
|
||||
|
||||
private void setCastle(final Castle castle) {
|
||||
this.castle = castle;
|
||||
}
|
||||
|
||||
public Army getArmy() {
|
||||
return army;
|
||||
}
|
||||
|
||||
private void setArmy(final Army army) {
|
||||
this.army = army;
|
||||
}
|
||||
}
|
||||
|
@ -7,4 +7,5 @@ package com.iluwatar.abstractfactory;
|
||||
*/
|
||||
public interface Army {
|
||||
|
||||
String getDescription();
|
||||
}
|
||||
|
@ -7,4 +7,5 @@ package com.iluwatar.abstractfactory;
|
||||
*/
|
||||
public interface Castle {
|
||||
|
||||
String getDescription();
|
||||
}
|
||||
|
@ -7,9 +7,10 @@ package com.iluwatar.abstractfactory;
|
||||
*/
|
||||
public class ElfArmy implements Army {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "This is the Elven Army!";
|
||||
}
|
||||
static final String DESCRIPTION = "This is the Elven Army!";
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return DESCRIPTION;
|
||||
}
|
||||
}
|
||||
|
@ -7,9 +7,10 @@ package com.iluwatar.abstractfactory;
|
||||
*/
|
||||
public class ElfCastle implements Castle {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "This is the Elven castle!";
|
||||
}
|
||||
static final String DESCRIPTION = "This is the Elven castle!";
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return DESCRIPTION;
|
||||
}
|
||||
}
|
||||
|
@ -7,9 +7,10 @@ package com.iluwatar.abstractfactory;
|
||||
*/
|
||||
public class ElfKing implements King {
|
||||
|
||||
static final String DESCRIPTION = "This is the Elven king!";
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "This is the Elven king!";
|
||||
public String getDescription() {
|
||||
return DESCRIPTION;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,4 +7,5 @@ package com.iluwatar.abstractfactory;
|
||||
*/
|
||||
public interface King {
|
||||
|
||||
String getDescription();
|
||||
}
|
||||
|
@ -7,9 +7,10 @@ package com.iluwatar.abstractfactory;
|
||||
*/
|
||||
public class OrcArmy implements Army {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "This is the Orcish Army!";
|
||||
}
|
||||
static final String DESCRIPTION = "This is the Orc Army!";
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return DESCRIPTION;
|
||||
}
|
||||
}
|
||||
|
@ -7,9 +7,10 @@ package com.iluwatar.abstractfactory;
|
||||
*/
|
||||
public class OrcCastle implements Castle {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "This is the Orcish castle!";
|
||||
}
|
||||
static final String DESCRIPTION = "This is the Orc castle!";
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return DESCRIPTION;
|
||||
}
|
||||
}
|
||||
|
@ -7,9 +7,10 @@ package com.iluwatar.abstractfactory;
|
||||
*/
|
||||
public class OrcKing implements King {
|
||||
|
||||
static final String DESCRIPTION = "This is the Orc king!";
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "This is the Orc king!";
|
||||
public String getDescription() {
|
||||
return DESCRIPTION;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user