Skip to content

Commit 0989c9b

Browse files
committed
Merge pull request iluwatar#240 from themoffster/master
Improved unit tests so assertions are used.
2 parents db11dc4 + 5956873 commit 0989c9b

File tree

11 files changed

+148
-44
lines changed

11 files changed

+148
-44
lines changed
Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.iluwatar.abstractfactory;
22

3+
34
/**
45
*
56
* The essence of the Abstract Factory pattern is a factory interface
@@ -12,26 +13,61 @@
1213
*/
1314
public class App {
1415

15-
/**
16-
* Program entry point
17-
* @param args command line arguments
18-
*/
19-
public static void main(String[] args) {
20-
createKingdom(new ElfKingdomFactory());
21-
createKingdom(new OrcKingdomFactory());
22-
}
16+
private King king;
17+
private Castle castle;
18+
private Army army;
2319

2420
/**
2521
* Creates kingdom
2622
* @param factory
2723
*/
28-
public static void createKingdom(KingdomFactory factory) {
29-
King king = factory.createKing();
30-
Castle castle = factory.createCastle();
31-
Army army = factory.createArmy();
32-
System.out.println("The kingdom was created.");
33-
System.out.println(king);
34-
System.out.println(castle);
35-
System.out.println(army);
24+
public void createKingdom(final KingdomFactory factory) {
25+
setKing(factory.createKing());
26+
setCastle(factory.createCastle());
27+
setArmy(factory.createArmy());
28+
}
29+
30+
ElfKingdomFactory getElfKingdomFactory() {
31+
return new ElfKingdomFactory();
32+
}
33+
34+
OrcKingdomFactory getOrcKingdomFactory() {
35+
return new OrcKingdomFactory();
36+
}
37+
38+
King getKing(final KingdomFactory factory) {
39+
return factory.createKing();
40+
}
41+
42+
Castle getCastle(final KingdomFactory factory) {
43+
return factory.createCastle();
44+
}
45+
46+
Army getArmy(final KingdomFactory factory) {
47+
return factory.createArmy();
48+
}
49+
50+
public King getKing() {
51+
return king;
52+
}
53+
54+
private void setKing(final King king) {
55+
this.king = king;
56+
}
57+
58+
public Castle getCastle() {
59+
return castle;
60+
}
61+
62+
private void setCastle(final Castle castle) {
63+
this.castle = castle;
64+
}
65+
66+
public Army getArmy() {
67+
return army;
68+
}
69+
70+
private void setArmy(final Army army) {
71+
this.army = army;
3672
}
3773
}

abstract-factory/src/main/java/com/iluwatar/abstractfactory/Army.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
*/
88
public interface Army {
99

10+
String getDescription();
1011
}

abstract-factory/src/main/java/com/iluwatar/abstractfactory/Castle.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
*/
88
public interface Castle {
99

10+
String getDescription();
1011
}

abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfArmy.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
*/
88
public class ElfArmy implements Army {
99

10+
static final String DESCRIPTION = "This is the Elven Army!";
11+
1012
@Override
11-
public String toString() {
12-
return "This is the Elven Army!";
13+
public String getDescription() {
14+
return DESCRIPTION;
1315
}
14-
1516
}

abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfCastle.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
*/
88
public class ElfCastle implements Castle {
99

10+
static final String DESCRIPTION = "This is the Elven castle!";
11+
1012
@Override
11-
public String toString() {
12-
return "This is the Elven castle!";
13+
public String getDescription() {
14+
return DESCRIPTION;
1315
}
14-
1516
}

abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfKing.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
*/
88
public class ElfKing implements King {
99

10+
static final String DESCRIPTION = "This is the Elven king!";
11+
1012
@Override
11-
public String toString() {
12-
return "This is the Elven king!";
13+
public String getDescription() {
14+
return DESCRIPTION;
1315
}
14-
1516
}

abstract-factory/src/main/java/com/iluwatar/abstractfactory/King.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
*/
88
public interface King {
99

10+
String getDescription();
1011
}

abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcArmy.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
*/
88
public class OrcArmy implements Army {
99

10+
static final String DESCRIPTION = "This is the Orc Army!";
11+
1012
@Override
11-
public String toString() {
12-
return "This is the Orcish Army!";
13+
public String getDescription() {
14+
return DESCRIPTION;
1315
}
14-
1516
}

abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcCastle.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
*/
88
public class OrcCastle implements Castle {
99

10+
static final String DESCRIPTION = "This is the Orc castle!";
11+
1012
@Override
11-
public String toString() {
12-
return "This is the Orcish castle!";
13+
public String getDescription() {
14+
return DESCRIPTION;
1315
}
14-
1516
}

abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcKing.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
*/
88
public class OrcKing implements King {
99

10+
static final String DESCRIPTION = "This is the Orc king!";
11+
1012
@Override
11-
public String toString() {
12-
return "This is the Orc king!";
13+
public String getDescription() {
14+
return DESCRIPTION;
1315
}
14-
1516
}

0 commit comments

Comments
 (0)