|
|
@@ -1,21 +1,28 @@
|
|
|
package cn.qinys.learn.creational.factory;
|
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
+import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
|
|
-import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
-
|
|
|
-class FruitFactoryTest {
|
|
|
+public class FruitFactoryTest {
|
|
|
|
|
|
@Test
|
|
|
- void createFruit() {
|
|
|
- Fruit apple = FruitFactory.createFruit(Apple.class);
|
|
|
- assertEquals("apple", apple.name());
|
|
|
+ public void testCreateApple() {
|
|
|
+ Fruit fruit = FruitFactory.createFruit("apple");
|
|
|
+ assertTrue(fruit instanceof Apple);
|
|
|
+ fruit.grow(); // Should print "Apple is growing"
|
|
|
+ }
|
|
|
|
|
|
- Fruit banana = FruitFactory.createFruit(Banana.class);
|
|
|
- assertEquals("banana", banana.name());
|
|
|
+ @Test
|
|
|
+ public void testCreateBanana() {
|
|
|
+ Fruit fruit = FruitFactory.createFruit("banana");
|
|
|
+ assertTrue(fruit instanceof Banana);
|
|
|
+ fruit.grow(); // Should print "Banana is growing"
|
|
|
+ }
|
|
|
|
|
|
-// assertThrows(IllegalArgumentException.class, () -> {
|
|
|
-// FruitFactory.createFruit("orange");
|
|
|
-// });
|
|
|
+ @Test
|
|
|
+ public void testCreateUnknownFruit() {
|
|
|
+ assertThrows(IllegalArgumentException.class, () -> {
|
|
|
+ FruitFactory.createFruit("orange");
|
|
|
+ });
|
|
|
}
|
|
|
-}
|
|
|
+}
|