Skip to content

Commit 4532dcb

Browse files
committed
add junit and test code
1 parent 937ad97 commit 4532dcb

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
</properties>
1515

1616
<dependencies>
17+
<dependency>
18+
<groupId>org.junit.jupiter</groupId>
19+
<artifactId>junit-jupiter-engine</artifactId>
20+
<version>5.8.1</version>
21+
<scope>test</scope>
22+
</dependency>
23+
1724
<dependency>
1825
<groupId>org.reflections</groupId>
1926
<artifactId>reflections</artifactId>

src/main/java/creational/factory/exercise/PersonFactory.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,4 @@ public class PersonFactory {
1010
public Person createPerson(String name) {
1111
return new Person(numOfPerson++, name);
1212
}
13-
}
14-
15-
class ExerciseDemo {
16-
public static void main(String[] args) {
17-
final PersonFactory pf = new PersonFactory();
18-
19-
Stream.of("Tommy", "Sunguck", "Meow").forEach(n -> System.out.println(pf.createPerson(n)));
20-
}
2113
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package creational.factory.exercise;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import java.util.stream.Stream;
6+
7+
import static org.junit.jupiter.api.Assertions.*;
8+
9+
class PersonFactoryTest {
10+
11+
@Test
12+
void createPerson() {
13+
// given
14+
final PersonFactory pf = new PersonFactory();
15+
final String[] names = new String[] {"Marcel", "Tony", "Jinhoon"};
16+
17+
for (int i = 0; i < names.length; i++) {
18+
// when
19+
final Person p = pf.createPerson(names[i]);
20+
21+
// then
22+
assertEquals(i, p.id());
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)