Improved unit tests so assertions are used.

This commit is contained in:
Alan
2015-09-05 00:31:35 +01:00
parent db11dc42c1
commit 5956873fc9
11 changed files with 152 additions and 48 deletions

View File

@ -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;
}
}

View File

@ -7,4 +7,5 @@ package com.iluwatar.abstractfactory;
*/
public interface Army {
String getDescription();
}

View File

@ -7,4 +7,5 @@ package com.iluwatar.abstractfactory;
*/
public interface Castle {
String getDescription();
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -7,4 +7,5 @@ package com.iluwatar.abstractfactory;
*/
public interface King {
String getDescription();
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}