-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
src/main/java/com/dongho/df/domain/creational/factory_method/ConcreteProductA.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.dongho.df.domain.creational.factory_method; | ||
|
||
public class ConcreteProductA implements Product { | ||
|
||
@Override | ||
public String getProductName() { | ||
return "concreteProductA"; | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/dongho/df/domain/creational/factory_method/ConcreteProductACreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.dongho.df.domain.creational.factory_method; | ||
|
||
public class ConcreteProductACreator extends Creator { | ||
|
||
@Override | ||
protected Product createProduct() { | ||
return new ConcreteProductA(); | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/dongho/df/domain/creational/factory_method/ConcreteProductB.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.dongho.df.domain.creational.factory_method; | ||
|
||
public class ConcreteProductB implements Product { | ||
|
||
@Override | ||
public String getProductName() { | ||
return "concreteProductB"; | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/dongho/df/domain/creational/factory_method/ConcreteProductBCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.dongho.df.domain.creational.factory_method; | ||
|
||
public class ConcreteProductBCreator extends Creator { | ||
|
||
@Override | ||
protected Product createProduct() { | ||
return new ConcreteProductB(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/dongho/df/domain/creational/factory_method/Creator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.dongho.df.domain.creational.factory_method; | ||
|
||
public abstract class Creator { | ||
|
||
abstract protected Product createProduct(); | ||
|
||
public String foo() { | ||
Product product = createProduct(); | ||
return product.getProductName(); | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/dongho/df/domain/creational/factory_method/Product.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.dongho.df.domain.creational.factory_method; | ||
|
||
public interface Product { | ||
|
||
public String getProductName(); | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
src/test/java/com/dongho/df/domain/creational/factory_method/FactoryMethodTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.dongho.df.domain.creational.factory_method; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@RunWith(JUnit4.class) | ||
public class FactoryMethodTest { | ||
|
||
@Test | ||
public void concreteProductATest() { | ||
Creator creator; | ||
String productName; | ||
|
||
given: { | ||
creator = new ConcreteProductACreator(); | ||
} | ||
|
||
when: { | ||
productName = creator.foo(); | ||
} | ||
|
||
then: { | ||
assertThat(productName).isEqualTo("concreteProductA"); | ||
} | ||
|
||
} | ||
|
||
@Test | ||
public void concreteProductBTest() { | ||
Creator creator; | ||
String productName; | ||
|
||
given: { | ||
creator = new ConcreteProductBCreator(); | ||
} | ||
|
||
when: { | ||
productName = creator.foo(); | ||
} | ||
|
||
then: { | ||
assertThat(productName).isEqualTo("concreteProductB"); | ||
} | ||
|
||
} | ||
|
||
} |