|
@@ -0,0 +1,21 @@
|
|
|
|
|
+package cn.qinys.learn.creational.factory;
|
|
|
|
|
+
|
|
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
|
|
+
|
|
|
|
|
+import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
+
|
|
|
|
|
+public class FactoryTest {
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void testConcreteCreatorsProduceExpectedProducts() {
|
|
|
|
|
+ Creator a = new ConcreteCreatorA();
|
|
|
|
|
+ Creator b = new ConcreteCreatorB();
|
|
|
|
|
+
|
|
|
|
|
+ Product pa = a.factoryMethod();
|
|
|
|
|
+ Product pb = b.factoryMethod();
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals("ConcreteProductA", pa.getName());
|
|
|
|
|
+ assertEquals("ConcreteProductB", pb.getName());
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|