Skip to content

Commit aab00a0

Browse files
committed
Use ObjectMother for Student fields
1 parent b1582b2 commit aab00a0

File tree

6 files changed

+90
-12
lines changed

6 files changed

+90
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package tv.codely.mooc.students.application.register;
2+
3+
import tv.codely.mooc.students.domain.*;
4+
5+
public class RegisterStudentRequestMother {
6+
public static RegisterStudentRequest create(StudentId id, StudentName name, StudentSurname surname, StudentEmail email) {
7+
return new RegisterStudentRequest(id.value(), name.value(), surname.value(), email.value());
8+
}
9+
10+
public static RegisterStudentRequest random() {
11+
return create(
12+
StudentIdMother.random(),
13+
StudentNameMother.random(),
14+
StudentSurnameMother.random(),
15+
StudentEmailMother.random()
16+
);
17+
}
18+
}

src/mooc/test/tv/codely/mooc/students/application/register/StudentRegistrarTestShould.java

+5-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package tv.codely.mooc.students.application.register;
22

33
import org.junit.jupiter.api.Test;
4-
import tv.codely.mooc.students.domain.*;
5-
import tv.codely.shared.domain.UuidMother;
4+
import tv.codely.mooc.students.domain.Student;
5+
import tv.codely.mooc.students.domain.StudentMother;
6+
import tv.codely.mooc.students.domain.StudentRepository;
67

78
import static org.mockito.Mockito.*;
89

@@ -12,16 +13,8 @@ void register_a_valid_student() {
1213
StudentRepository repository = mock(StudentRepository.class);
1314
StudentRegistrar registrar = new StudentRegistrar(repository);
1415

15-
StudentId id = new StudentId(UuidMother.random());
16-
StudentName name = new StudentName("name");
17-
StudentSurname surname = new StudentSurname("surname");
18-
StudentEmail email = new StudentEmail("[email protected]");
19-
20-
RegisterStudentRequest request = new RegisterStudentRequest(
21-
id.value(), name.value(), surname.value(), email.value()
22-
);
23-
24-
Student student = new Student(id, name, surname, email);
16+
RegisterStudentRequest request = RegisterStudentRequestMother.random();
17+
Student student = StudentMother.fromRequest(request);
2518

2619
registrar.register(request);
2720

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package tv.codely.mooc.students.domain;
2+
3+
import tv.codely.shared.domain.EmailMother;
4+
5+
public final class StudentEmailMother {
6+
public static StudentEmail create(String value) {
7+
return new StudentEmail(value);
8+
}
9+
10+
public static StudentEmail random() {
11+
return create(EmailMother.random());
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package tv.codely.mooc.students.domain;
2+
3+
import tv.codely.mooc.students.application.register.RegisterStudentRequest;
4+
5+
public class StudentMother {
6+
public static Student create(StudentId id, StudentName name, StudentSurname surname, StudentEmail email) {
7+
return new Student(id, name, surname, email);
8+
}
9+
10+
public static Student fromRequest(RegisterStudentRequest request) {
11+
return create(
12+
StudentIdMother.create(request.id()),
13+
StudentNameMother.create(request.name()),
14+
StudentSurnameMother.create(request.surname()),
15+
StudentEmailMother.create(request.email())
16+
);
17+
}
18+
19+
public static Student random() {
20+
return create(
21+
StudentIdMother.random(),
22+
StudentNameMother.random(),
23+
StudentSurnameMother.random(),
24+
StudentEmailMother.random()
25+
);
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package tv.codely.mooc.students.domain;
2+
3+
import tv.codely.mooc.courses.domain.CourseName;
4+
import tv.codely.shared.domain.WordMother;
5+
6+
public final class StudentNameMother {
7+
public static StudentName create(String value) {
8+
return new StudentName(value);
9+
}
10+
11+
public static StudentName random() {
12+
return create(WordMother.random());
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package tv.codely.mooc.students.domain;
2+
3+
import tv.codely.shared.domain.WordMother;
4+
5+
public final class StudentSurnameMother {
6+
public static StudentSurname create(String value) {
7+
return new StudentSurname(value);
8+
}
9+
10+
public static StudentSurname random() {
11+
return create(WordMother.random());
12+
}
13+
}

0 commit comments

Comments
 (0)