-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TEST] 출석 관련 단위 테스트 추가 및 행사 출석 로직 수정 #254
Changes from 6 commits
ffa2c20
8f67dca
ef9cff4
246e287
939e385
9ecbe65
7b90765
8abf1d4
e25492f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,13 @@ public class Attendance { | |
@OneToMany(mappedBy = "attendance") | ||
private final List<SubAttendance> subAttendances = new ArrayList<>(); | ||
|
||
protected Attendance(Long id, Member member, Lecture lecture, AttendanceStatus status) { | ||
this.id = id; | ||
setMember(member); | ||
setLecture(lecture); | ||
this.status = status; | ||
} | ||
|
||
Comment on lines
+51
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @yummygyudon |
||
public Attendance(Member member, Lecture lecture) { | ||
setMember(member); | ||
setLecture(lecture); | ||
|
@@ -103,7 +110,7 @@ public float getScore() { | |
yield 0f; | ||
} | ||
} | ||
case EVENT -> this.status.equals(ATTENDANCE) ? 0.5f : 0f; | ||
case EVENT -> this.status.equals(ABSENT) ? 0f : 0.5f; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 제가 행사 점수 연산 방식을 전달 드리기 전에 올리신 PR인 것 같습니다! Score 조회 메서드는 원용씨가 하신대로 가면될 듯 하구 현재는 2차 출석값만 확인하는 로직인 듯 합니다!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
return switch (this.lecture.getAttribute()) {
case SEMINAR -> {
if (first.getStatus().equals(ATTENDANCE) && second.getStatus().equals(ATTENDANCE)) {
yield ATTENDANCE;
}
yield first.getStatus().equals(ABSENT) && second.getStatus().equals(ABSENT) ? ABSENT : TARDY;
}
case EVENT -> second.getStatus().equals(ATTENDANCE) ? ATTENDANCE : ABSENT;
case ETC -> second.getStatus().equals(ATTENDANCE) ? PARTICIPATE : NOT_PARTICIPATE;
};
return switch (this.lecture.getAttribute()) {
case SEMINAR -> {
if (first.getStatus().equals(ATTENDANCE) && second.getStatus().equals(ATTENDANCE)) {
yield ATTENDANCE;
}
yield first.getStatus().equals(ABSENT) && second.getStatus().equals(ABSENT) ? ABSENT : TARDY;
}
case EVENT -> {
if (first.getStatus().equals(ATTENDANCE) && second.getStatus().equals(ATTENDANCE)) {
yield ATTENDANCE;
}
yield first.getStatus().equals(ABSENT) && second.getStatus().equals(ABSENT) ? ABSENT : TARDY;
case ETC -> second.getStatus().equals(ATTENDANCE) ? PARTICIPATE : NOT_PARTICIPATE;
}; 메서드 길이가 길어지는 문제와 함께 중복되는 코드가 발생하는 문제가 존재할 것 같은데 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @yummygyudon There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 행사도 연산 점수 로직 바뀐거 확인했습니다 ! 동규님 꼼꼼하게 체크해주시고 바로 반영해준 원용님 감사합니다 ~! |
||
default -> 0f; | ||
}; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package org.sopt.makers.operation.attendance.domain; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.sopt.makers.operation.common.domain.Part; | ||
import org.sopt.makers.operation.dummy.AttendanceDummy; | ||
import org.sopt.makers.operation.dummy.LectureDummy; | ||
import org.sopt.makers.operation.dummy.MemberDummy; | ||
import org.sopt.makers.operation.lecture.domain.Attribute; | ||
import org.sopt.makers.operation.lecture.domain.Lecture; | ||
import org.sopt.makers.operation.lecture.domain.LectureStatus; | ||
import org.sopt.makers.operation.member.domain.Member; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
public class AttendanceGetScoreTest { | ||
|
||
private Member member; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
member = MemberDummy.builder() | ||
.id(1L) | ||
.attendances(new ArrayList<>()) | ||
.build(); | ||
} | ||
|
||
@Nested | ||
@DisplayName("세미나 출석 관련 테스트") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 대분류(상위 클래스) 이름 ex. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @yummygyudon There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 7b90765 반영했습니다! |
||
public class SeminarTest { | ||
@Test | ||
@DisplayName("세미나에 출석을 했으면 0f를 반환한다.") | ||
public void getScoreTest() { | ||
// given | ||
Lecture lecture = new LectureDummy(1L, "서버 1차 세미나", Part.SERVER, 34, "오산역", LocalDateTime.now(), LocalDateTime.now(), Attribute.SEMINAR, LectureStatus.BEFORE); | ||
Attendance attendance = new AttendanceDummy(1L, member, lecture, AttendanceStatus.ATTENDANCE); | ||
|
||
// when | ||
float score = attendance.getScore(); | ||
|
||
// then | ||
assertThat(score).isEqualTo(0f); | ||
} | ||
|
||
@Test | ||
@DisplayName("세미나에 지각을 했으면 -0.5f를 반환한다.") | ||
public void getScoreTest2() { | ||
// given | ||
Lecture lecture = new LectureDummy(1L, "서버 1차 세미나", Part.SERVER, 34, "오산역", LocalDateTime.now(), LocalDateTime.now(), Attribute.SEMINAR, LectureStatus.BEFORE); | ||
Attendance attendance = new AttendanceDummy(1L, member, lecture, AttendanceStatus.TARDY); | ||
|
||
// when | ||
float score = attendance.getScore(); | ||
|
||
// then | ||
assertThat(score).isEqualTo(-0.5f); | ||
} | ||
|
||
@Test | ||
@DisplayName("세미나에 결석을 했으면 -1f를 반환한다.") | ||
public void getScoreTest3() { | ||
// given | ||
Lecture lecture = new LectureDummy(1L, "서버 1차 세미나", Part.SERVER, 34, "오산역", LocalDateTime.now(), LocalDateTime.now(), Attribute.SEMINAR, LectureStatus.BEFORE); | ||
Attendance attendance = new AttendanceDummy(1L, member, lecture, AttendanceStatus.ABSENT); | ||
|
||
// when | ||
float score = attendance.getScore(); | ||
|
||
// then | ||
assertThat(score).isEqualTo(-1f); | ||
} | ||
} | ||
|
||
@Nested | ||
@DisplayName("행사 출석 관련 테스트") | ||
public class EventTest { | ||
@Test | ||
@DisplayName("행사에 출석을 했으면 0.5f를 반환한다.") | ||
public void getScoreTest() { | ||
// given | ||
Lecture lecture = new LectureDummy(1L, "서버 1차 세미나", Part.SERVER, 34, "오산역", LocalDateTime.now(), LocalDateTime.now(), Attribute.EVENT, LectureStatus.BEFORE); | ||
Attendance attendance = new AttendanceDummy(1L, member, lecture, AttendanceStatus.ATTENDANCE); | ||
|
||
// when | ||
float score = attendance.getScore(); | ||
|
||
// then | ||
assertThat(score).isEqualTo(0.5f); | ||
} | ||
|
||
@Test | ||
@DisplayName("행사에 지각을 했으면 0.5f를 반환한다.") | ||
public void getScoreTest2() { | ||
// given | ||
Lecture lecture = new LectureDummy(1L, "서버 1차 세미나", Part.SERVER, 34, "오산역", LocalDateTime.now(), LocalDateTime.now(), Attribute.EVENT, LectureStatus.BEFORE); | ||
Attendance attendance = new AttendanceDummy(1L, member, lecture, AttendanceStatus.TARDY); | ||
|
||
// when | ||
float score = attendance.getScore(); | ||
|
||
// then | ||
assertThat(score).isEqualTo(0.5f); | ||
} | ||
|
||
@Test | ||
@DisplayName("행사에 결석을 했으면 0f를 반환한다.") | ||
public void getScoreTest3() { | ||
// given | ||
Lecture lecture = new LectureDummy(1L, "서버 1차 세미나", Part.SERVER, 34, "오산역", LocalDateTime.now(), LocalDateTime.now(), Attribute.EVENT, LectureStatus.BEFORE); | ||
Attendance attendance = new AttendanceDummy(1L, member, lecture, AttendanceStatus.ABSENT); | ||
|
||
// when | ||
float score = attendance.getScore(); | ||
|
||
// then | ||
assertThat(score).isEqualTo(0f); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package org.sopt.makers.operation.attendance.domain; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.sopt.makers.operation.common.domain.Part; | ||
import org.sopt.makers.operation.dummy.AttendanceDummy; | ||
import org.sopt.makers.operation.dummy.LectureDummy; | ||
import org.sopt.makers.operation.dummy.MemberDummy; | ||
import org.sopt.makers.operation.dummy.SubAttendanceDummy; | ||
import org.sopt.makers.operation.dummy.SubLectureDummy; | ||
import org.sopt.makers.operation.lecture.domain.Attribute; | ||
import org.sopt.makers.operation.lecture.domain.LectureStatus; | ||
import org.sopt.makers.operation.lecture.domain.SubLecture; | ||
import org.sopt.makers.operation.member.domain.Member; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
class AttendanceGetStatusTest { | ||
|
||
private Member member; | ||
private LectureDummy lecture; | ||
private SubLecture subLecture1; | ||
private SubLecture subLecture2; | ||
private List<SubLecture> subLectures; | ||
private List<Attendance> attendances; | ||
private Attendance attendance; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
member = MemberDummy.builder() | ||
.id(1L) | ||
.attendances(new ArrayList<>()) | ||
.build(); | ||
|
||
lecture = new LectureDummy(1L, "서버 1차 세미나", Part.SERVER, 34, "오산역", LocalDateTime.now(), LocalDateTime.now(), Attribute.SEMINAR, LectureStatus.BEFORE); | ||
|
||
subLecture1 = new SubLectureDummy(1L, lecture, 1, LocalDateTime.now(), "000001"); | ||
subLecture2 = new SubLectureDummy(2L, lecture, 2, LocalDateTime.now(), "000002"); | ||
|
||
subLectures = new ArrayList<>(); | ||
subLectures.add(subLecture1); | ||
subLectures.add(subLecture2); | ||
|
||
attendances = new ArrayList<>(); | ||
attendance = new AttendanceDummy(1L, member, lecture, AttendanceStatus.ABSENT); | ||
attendances.add(attendance); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 조금 Dummy Data를 만드는 것에 대해서는 행위를 나타내는 함수로 분리하여 추후에 특정 Dummy Data의 스펙을 수정할 때도 관리하기 용이할 것 같아요!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. List<SubLectureDummy> dummySubLectures = makeDummySubLecture(2);
List<AttendanceDummy> dummyAttendances = makeDummyAttendance(2);
private List<SubLectureDummy> makeDummySubLecture(int quantity) {
// for문 혹은 Stream 을 통해 quantity 값을 활용하여 id, round, code 등을 만들어서 반환할 수 있을 듯!
...
}
private List<AttendanceDummy> makeDummyAttendance(int quantity) {
// for문 혹은 Stream 을 통해 quantity 값을 활용하여 id 주입하고 Random 함수를 통해 AttendanceStatus를 주입할 수 있을듯!!
...
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 긴 setUp 에 머리 아팠었는데, 메서드로 분리하면 setUp 과정도 좀 더 명시적으로 변할 것 같아서 좋을 것 같습니다! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 해당 부분을 함수화 해서 변경하는 방식으로 생각해 보다가 아래 사항들이 맘에 걸려 기존 상태를 유지했습니다.
이에 대해 어떻게 생각하시는지 궁금합니다..! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
테스트 여부, 준비 동작 여부와는 상관없이 코드는 유연하고 가독성이 중요하다고 생각합니다!!
해당 테스트에 대해서만 생각한다면 본 의견에 대해 동의합니다!! 다만 첫 리뷰에서는 언급드리지 않은 내용인데 이 때, 각 테스트 클래스 내에는 동일한 코드가 반복되어 들어갈 것이라고 생각했고 해당 의견에 대한 원용이 의견도 궁금합니다!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
이 부분은 굉장히 동의합니다! 하지만 저는 각 테스트 케이스가 좀 더 독립적으로 실행되기 위해선 서로 다른 테스트 클래스에서 생성 메서드를 사용하는 것은 지양하고 싶다는 생각이 듭니다..! 왜냐하면 해당 생성 메서드를 통해서 테스트를 하려다가 추가 내용이 필요해서 메서드를 수정하려는 순간 저는 테스트 코드는 가능한 빠르게 작성 되는 것이 중요하다고 생각합니다. 이로 인해 각각의 테스트 케이스는 좀 더 독립적인 테스트 케이스를 만들 수 있지 않을까란 생각이 들기 때문에 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 독립적인 테스트 케이스 활용을 위한다는 마음으로 고려해보니 원용이의 의견에 매우 공감되는 바입니다!! |
||
|
||
lecture.setOneToMany(subLectures, attendances); | ||
} | ||
|
||
@Test | ||
@DisplayName("세미나 1차 출석을 했고, 2차 출석을 했으면 출석 처리가 된다.") | ||
void getStatusTest() { | ||
// given | ||
SubAttendance subAttendance1 = new SubAttendanceDummy(1L, attendance, subLecture1, AttendanceStatus.ATTENDANCE); | ||
SubAttendance subAttendance2 = new SubAttendanceDummy(2L, attendance, subLecture2, AttendanceStatus.ATTENDANCE); | ||
|
||
// when | ||
AttendanceStatus attendanceStatus = attendance.getStatus(); | ||
|
||
// then | ||
assertThat(attendanceStatus).isEqualTo(AttendanceStatus.ATTENDANCE); | ||
} | ||
|
||
@Test | ||
@DisplayName("세미나에서 1차 출석을 했고, 2차 출석을 결석했으면 지각 처리가 된다.") | ||
void getStatusTest2() { | ||
// given | ||
SubAttendance subAttendance1 = new SubAttendanceDummy(1L, attendance, subLecture1, AttendanceStatus.ATTENDANCE); | ||
SubAttendance subAttendance2 = new SubAttendanceDummy(2L, attendance, subLecture2, AttendanceStatus.ABSENT); | ||
|
||
// when | ||
AttendanceStatus attendanceStatus = attendance.getStatus(); | ||
|
||
// then | ||
assertThat(attendanceStatus).isEqualTo(AttendanceStatus.TARDY); | ||
} | ||
|
||
@Test | ||
@DisplayName("세미나에서 1차 출석을 결석했고, 2차 출석을 했으면 지각 처리가 된다.") | ||
void getStatusTest3() { | ||
// given | ||
SubAttendance subAttendance1 = new SubAttendanceDummy(1L, attendance, subLecture1, AttendanceStatus.ABSENT); | ||
SubAttendance subAttendance2 = new SubAttendanceDummy(2L, attendance, subLecture2, AttendanceStatus.ATTENDANCE); | ||
|
||
// when | ||
AttendanceStatus attendanceStatus = attendance.getStatus(); | ||
|
||
// then | ||
assertThat(attendanceStatus).isEqualTo(AttendanceStatus.TARDY); | ||
} | ||
|
||
@Test | ||
@DisplayName("세미나에서 1차 출석을 결석했고, 2차 출석을 결석했으면 결석 처리가 된다.") | ||
void getStatusTest4() { | ||
// given | ||
SubAttendance subAttendance1 = new SubAttendanceDummy(1L, attendance, subLecture1, AttendanceStatus.ABSENT); | ||
SubAttendance subAttendance2 = new SubAttendanceDummy(2L, attendance, subLecture2, AttendanceStatus.ABSENT); | ||
|
||
// when | ||
AttendanceStatus attendanceStatus = attendance.getStatus(); | ||
|
||
// then | ||
assertThat(attendanceStatus).isEqualTo(AttendanceStatus.ABSENT); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.sopt.makers.operation.dummy; | ||
|
||
import org.sopt.makers.operation.attendance.domain.Attendance; | ||
import org.sopt.makers.operation.attendance.domain.AttendanceStatus; | ||
import org.sopt.makers.operation.lecture.domain.Lecture; | ||
import org.sopt.makers.operation.member.domain.Member; | ||
|
||
public class AttendanceDummy extends Attendance { | ||
public AttendanceDummy(Long id, Member member, Lecture lecture, AttendanceStatus status) { | ||
super(id, member, lecture, status); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.sopt.makers.operation.dummy; | ||
|
||
import org.sopt.makers.operation.attendance.domain.Attendance; | ||
import org.sopt.makers.operation.common.domain.Part; | ||
import org.sopt.makers.operation.lecture.domain.Attribute; | ||
import org.sopt.makers.operation.lecture.domain.Lecture; | ||
import org.sopt.makers.operation.lecture.domain.LectureStatus; | ||
import org.sopt.makers.operation.lecture.domain.SubLecture; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
public class LectureDummy extends Lecture { | ||
|
||
public LectureDummy(Long id, String name, Part part, int generation, String place, LocalDateTime startDate, LocalDateTime endDate, Attribute attribute, LectureStatus lectureStatus) { | ||
super(id, name, part, generation, place, startDate, endDate, attribute, lectureStatus); | ||
} | ||
|
||
public void setOneToMany(List<SubLecture> subLectures, List<Attendance> attendances) { | ||
super.setOneToMany(subLectures, attendances); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
우와 진짜 메이커스에서 테스트하는 것 감격...!!