Skip to content

Commit b3c1984

Browse files
committed
Add semantics to StudentRegistrar test
1 parent aab00a0 commit b3c1984

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package tv.codely.mooc.students;
2+
3+
import org.junit.jupiter.api.BeforeEach;
4+
import tv.codely.mooc.students.domain.Student;
5+
import tv.codely.mooc.students.domain.StudentRepository;
6+
import tv.codely.shared.infrastructure.UnitTestCase;
7+
8+
import static org.mockito.Mockito.*;
9+
10+
public abstract class StudentsModuleUnitTestCase extends UnitTestCase {
11+
protected StudentRepository repository;
12+
13+
@BeforeEach
14+
protected void setUp() {
15+
super.setUp();
16+
17+
repository = mock(StudentRepository.class);
18+
}
19+
20+
public void shouldHaveSaved(Student student) {
21+
verify(repository, atLeastOnce()).register(student);
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
package tv.codely.mooc.students.application.register;
22

3+
import org.junit.jupiter.api.BeforeEach;
34
import org.junit.jupiter.api.Test;
5+
import tv.codely.mooc.students.StudentsModuleUnitTestCase;
46
import tv.codely.mooc.students.domain.Student;
57
import tv.codely.mooc.students.domain.StudentMother;
6-
import tv.codely.mooc.students.domain.StudentRepository;
78

8-
import static org.mockito.Mockito.*;
9+
final class StudentRegistrarTestShould extends StudentsModuleUnitTestCase {
10+
StudentRegistrar registrar;
11+
12+
@BeforeEach
13+
protected void setUp() {
14+
super.setUp();
15+
16+
registrar = new StudentRegistrar(repository);
17+
}
918

10-
final class StudentRegistrarTestShould {
1119
@Test
1220
void register_a_valid_student() {
13-
StudentRepository repository = mock(StudentRepository.class);
14-
StudentRegistrar registrar = new StudentRegistrar(repository);
15-
1621
RegisterStudentRequest request = RegisterStudentRequestMother.random();
1722
Student student = StudentMother.fromRequest(request);
1823

1924
registrar.register(request);
2025

21-
verify(repository, atLeastOnce()).register(student);
26+
shouldHaveSaved(student);
2227
}
2328
}

0 commit comments

Comments
 (0)