File tree Expand file tree Collapse file tree 2 files changed +35
-7
lines changed
src/mooc/test/tv/codely/mooc/students Expand file tree Collapse file tree 2 files changed +35
-7
lines changed Original file line number Diff line number Diff line change 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 number Diff line number Diff line change 11package tv .codely .mooc .students .application .register ;
22
3+ import org .junit .jupiter .api .BeforeEach ;
34import org .junit .jupiter .api .Test ;
5+ import tv .codely .mooc .students .StudentsModuleUnitTestCase ;
46import tv .codely .mooc .students .domain .Student ;
57import 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}
You can’t perform that action at this time.
0 commit comments