File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed
src/mooc/test/tv/codely/mooc/students
infrastructure/persistence Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ package tv .codely .mooc .students ;
2+
3+ import org .springframework .beans .factory .annotation .Autowired ;
4+ import tv .codely .mooc .MoocContextInfrastructureTestCase ;
5+ import tv .codely .mooc .students .domain .StudentRepository ;
6+
7+ public abstract class StudentsModuleInfrastructureTestCase extends MoocContextInfrastructureTestCase {
8+ @ Autowired
9+ protected StudentRepository mySqlStudentRepository ;
10+ }
Original file line number Diff line number Diff line change 1+ package tv .codely .mooc .students .infrastructure .persistence ;
2+
3+ import org .junit .jupiter .api .Test ;
4+ import tv .codely .mooc .students .StudentsModuleInfrastructureTestCase ;
5+ import tv .codely .mooc .students .domain .Student ;
6+ import tv .codely .mooc .students .domain .StudentMother ;
7+
8+ import javax .transaction .Transactional ;
9+ import java .util .List ;
10+
11+ import static org .junit .jupiter .api .Assertions .assertEquals ;
12+ import static org .junit .jupiter .api .Assertions .assertTrue ;
13+
14+ @ Transactional
15+ class MySqlStudentRepositoryShould extends StudentsModuleInfrastructureTestCase {
16+ @ Test
17+ void register_a_student () {
18+ Student student = StudentMother .random ();
19+
20+ mySqlStudentRepository .register (student );
21+ }
22+
23+ @ Test
24+ void return_all_existing_students () {
25+ Student student1 = StudentMother .random ();
26+ Student student2 = StudentMother .random ();
27+
28+ mySqlStudentRepository .register (student1 );
29+ mySqlStudentRepository .register (student2 );
30+
31+ List <Student > students = mySqlStudentRepository .searchAll ();
32+ assertEquals (2 , students .size ());
33+ assertEquals (student1 , students .get (0 ));
34+ assertEquals (student2 , students .get (1 ));
35+ }
36+
37+ @ Test
38+ void not_return_non_existing_students () {
39+ assertTrue (mySqlStudentRepository .searchAll ().isEmpty ());
40+ }
41+ }
You can’t perform that action at this time.
0 commit comments