File tree 2 files changed +35
-7
lines changed
src/mooc/test/tv/codely/mooc/students
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 1
1
package tv .codely .mooc .students .application .register ;
2
2
3
+ import org .junit .jupiter .api .BeforeEach ;
3
4
import org .junit .jupiter .api .Test ;
5
+ import tv .codely .mooc .students .StudentsModuleUnitTestCase ;
4
6
import tv .codely .mooc .students .domain .Student ;
5
7
import tv .codely .mooc .students .domain .StudentMother ;
6
- import tv .codely .mooc .students .domain .StudentRepository ;
7
8
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
+ }
9
18
10
- final class StudentRegistrarTestShould {
11
19
@ Test
12
20
void register_a_valid_student () {
13
- StudentRepository repository = mock (StudentRepository .class );
14
- StudentRegistrar registrar = new StudentRegistrar (repository );
15
-
16
21
RegisterStudentRequest request = RegisterStudentRequestMother .random ();
17
22
Student student = StudentMother .fromRequest (request );
18
23
19
24
registrar .register (request );
20
25
21
- verify ( repository , atLeastOnce ()). register (student );
26
+ shouldHaveSaved (student );
22
27
}
23
28
}
You can’t perform that action at this time.
0 commit comments