refactor: Complete updateParticipantCheckInStatus delegation to ScheduleStatusService
Phase 3 Complete: - Update MartialScheduleServiceImpl.updateParticipantCheckInStatus to delegate - Reduce method from 17 lines to 3 lines (delegation only) - Add 5 comprehensive unit tests for updateParticipantCheckInStatus - All tests passing (482 total: 477 existing + 5 new) Delegation Status: ✅ exportSchedule - FULLY DELEGATED ✅ exportScheduleTemplate2 - FULLY DELEGATED ✅ updateParticipantCheckInStatus - FULLY DELEGATED (NEW) Progress: 3/10 methods (30%) Remaining: 7 methods to delegate Next: Phase 4 - Dispatch Service methods (saveDispatch, adjustOrder, getDispatchData, moveScheduleGroup)
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+2
-15
@@ -923,21 +923,8 @@ public class MartialScheduleServiceImpl extends ServiceImpl<MartialScheduleMappe
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public boolean updateParticipantCheckInStatus(Long participantId, String status) {
|
public boolean updateParticipantCheckInStatus(Long participantId, String status) {
|
||||||
if (participantId == null || status == null) {
|
// Delegated to ScheduleStatusService
|
||||||
return false;
|
return scheduleStatusService.updateParticipantCheckInStatus(participantId, status);
|
||||||
}
|
|
||||||
|
|
||||||
MartialScheduleParticipant participant = scheduleParticipantMapper.selectById(participantId);
|
|
||||||
if (participant == null) {
|
|
||||||
log.warn("参赛者不存在, participantId: {}", participantId);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
participant.setCheckInStatus(status);
|
|
||||||
int result = scheduleParticipantMapper.updateById(participant);
|
|
||||||
|
|
||||||
log.info("更新参赛者签到状态: participantId={}, status={}, result={}", participantId, status, result);
|
|
||||||
return result > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+78
-27
@@ -21,7 +21,9 @@ import static org.mockito.Mockito.*;
|
|||||||
* MartialScheduleServiceImpl Test
|
* MartialScheduleServiceImpl Test
|
||||||
* Following Google Testing Best Practices
|
* Following Google Testing Best Practices
|
||||||
*
|
*
|
||||||
* Phase 2 Complete: exportSchedule and exportScheduleTemplate2 fully delegated
|
* Completed Phases:
|
||||||
|
* - Phase 2: Export Service (exportSchedule, exportScheduleTemplate2)
|
||||||
|
* - Phase 3: Status Service (updateParticipantCheckInStatus)
|
||||||
*/
|
*/
|
||||||
@DisplayName("MartialScheduleServiceImpl - Delegation Tests")
|
@DisplayName("MartialScheduleServiceImpl - Delegation Tests")
|
||||||
class MartialScheduleServiceImplTest {
|
class MartialScheduleServiceImplTest {
|
||||||
@@ -29,6 +31,9 @@ class MartialScheduleServiceImplTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private IScheduleExportService scheduleExportService;
|
private IScheduleExportService scheduleExportService;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private IScheduleStatusService scheduleStatusService;
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private MartialScheduleServiceImpl scheduleService;
|
private MartialScheduleServiceImpl scheduleService;
|
||||||
|
|
||||||
@@ -37,10 +42,11 @@ class MartialScheduleServiceImplTest {
|
|||||||
MockitoAnnotations.openMocks(this);
|
MockitoAnnotations.openMocks(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ========== Phase 2: Export Service Tests ==========
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Should delegate exportSchedule to ScheduleExportService")
|
@DisplayName("Should delegate exportSchedule to ScheduleExportService")
|
||||||
void shouldDelegateExportScheduleToService() {
|
void shouldDelegateExportScheduleToService() {
|
||||||
// Given
|
|
||||||
Long competitionId = 1L;
|
Long competitionId = 1L;
|
||||||
List<ScheduleExportExcel> expectedResult = Arrays.asList(
|
List<ScheduleExportExcel> expectedResult = Arrays.asList(
|
||||||
new ScheduleExportExcel(),
|
new ScheduleExportExcel(),
|
||||||
@@ -48,10 +54,8 @@ class MartialScheduleServiceImplTest {
|
|||||||
);
|
);
|
||||||
when(scheduleExportService.exportSchedule(competitionId)).thenReturn(expectedResult);
|
when(scheduleExportService.exportSchedule(competitionId)).thenReturn(expectedResult);
|
||||||
|
|
||||||
// When
|
|
||||||
List<ScheduleExportExcel> result = scheduleService.exportSchedule(competitionId);
|
List<ScheduleExportExcel> result = scheduleService.exportSchedule(competitionId);
|
||||||
|
|
||||||
// Then
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals(2, result.size());
|
assertEquals(2, result.size());
|
||||||
verify(scheduleExportService).exportSchedule(competitionId);
|
verify(scheduleExportService).exportSchedule(competitionId);
|
||||||
@@ -60,14 +64,11 @@ class MartialScheduleServiceImplTest {
|
|||||||
@Test
|
@Test
|
||||||
@DisplayName("Should handle empty export result")
|
@DisplayName("Should handle empty export result")
|
||||||
void shouldHandleEmptyExportResult() {
|
void shouldHandleEmptyExportResult() {
|
||||||
// Given
|
|
||||||
Long competitionId = 1L;
|
Long competitionId = 1L;
|
||||||
when(scheduleExportService.exportSchedule(competitionId)).thenReturn(new ArrayList<>());
|
when(scheduleExportService.exportSchedule(competitionId)).thenReturn(new ArrayList<>());
|
||||||
|
|
||||||
// When
|
|
||||||
List<ScheduleExportExcel> result = scheduleService.exportSchedule(competitionId);
|
List<ScheduleExportExcel> result = scheduleService.exportSchedule(competitionId);
|
||||||
|
|
||||||
// Then
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertTrue(result.isEmpty());
|
assertTrue(result.isEmpty());
|
||||||
verify(scheduleExportService).exportSchedule(competitionId);
|
verify(scheduleExportService).exportSchedule(competitionId);
|
||||||
@@ -76,13 +77,10 @@ class MartialScheduleServiceImplTest {
|
|||||||
@Test
|
@Test
|
||||||
@DisplayName("Should handle null competition ID")
|
@DisplayName("Should handle null competition ID")
|
||||||
void shouldHandleNullCompetitionId() {
|
void shouldHandleNullCompetitionId() {
|
||||||
// Given
|
|
||||||
when(scheduleExportService.exportSchedule(null)).thenReturn(null);
|
when(scheduleExportService.exportSchedule(null)).thenReturn(null);
|
||||||
|
|
||||||
// When
|
|
||||||
List<ScheduleExportExcel> result = scheduleService.exportSchedule(null);
|
List<ScheduleExportExcel> result = scheduleService.exportSchedule(null);
|
||||||
|
|
||||||
// Then
|
|
||||||
assertNull(result);
|
assertNull(result);
|
||||||
verify(scheduleExportService).exportSchedule(null);
|
verify(scheduleExportService).exportSchedule(null);
|
||||||
}
|
}
|
||||||
@@ -90,24 +88,18 @@ class MartialScheduleServiceImplTest {
|
|||||||
@Test
|
@Test
|
||||||
@DisplayName("Should verify exportSchedule is called exactly once")
|
@DisplayName("Should verify exportSchedule is called exactly once")
|
||||||
void shouldVerifyExportScheduleCalledOnce() {
|
void shouldVerifyExportScheduleCalledOnce() {
|
||||||
// Given
|
|
||||||
Long competitionId = 1L;
|
Long competitionId = 1L;
|
||||||
when(scheduleExportService.exportSchedule(competitionId)).thenReturn(new ArrayList<>());
|
when(scheduleExportService.exportSchedule(competitionId)).thenReturn(new ArrayList<>());
|
||||||
|
|
||||||
// When
|
|
||||||
scheduleService.exportSchedule(competitionId);
|
scheduleService.exportSchedule(competitionId);
|
||||||
|
|
||||||
// Then
|
|
||||||
verify(scheduleExportService, times(1)).exportSchedule(competitionId);
|
verify(scheduleExportService, times(1)).exportSchedule(competitionId);
|
||||||
verifyNoMoreInteractions(scheduleExportService);
|
verifyNoMoreInteractions(scheduleExportService);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========== Phase 2: exportScheduleTemplate2 Tests ==========
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Should delegate exportScheduleTemplate2 to ScheduleExportService")
|
@DisplayName("Should delegate exportScheduleTemplate2 to ScheduleExportService")
|
||||||
void shouldDelegateExportScheduleTemplate2ToService() {
|
void shouldDelegateExportScheduleTemplate2ToService() {
|
||||||
// Given
|
|
||||||
Long competitionId = 1L;
|
Long competitionId = 1L;
|
||||||
Long venueId = 2L;
|
Long venueId = 2L;
|
||||||
List<ScheduleExportExcel2> expectedResult = Arrays.asList(
|
List<ScheduleExportExcel2> expectedResult = Arrays.asList(
|
||||||
@@ -118,10 +110,8 @@ class MartialScheduleServiceImplTest {
|
|||||||
when(scheduleExportService.exportScheduleTemplate2(competitionId, venueId))
|
when(scheduleExportService.exportScheduleTemplate2(competitionId, venueId))
|
||||||
.thenReturn(expectedResult);
|
.thenReturn(expectedResult);
|
||||||
|
|
||||||
// When
|
|
||||||
List<ScheduleExportExcel2> result = scheduleService.exportScheduleTemplate2(competitionId, venueId);
|
List<ScheduleExportExcel2> result = scheduleService.exportScheduleTemplate2(competitionId, venueId);
|
||||||
|
|
||||||
// Then
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals(3, result.size());
|
assertEquals(3, result.size());
|
||||||
verify(scheduleExportService).exportScheduleTemplate2(competitionId, venueId);
|
verify(scheduleExportService).exportScheduleTemplate2(competitionId, venueId);
|
||||||
@@ -130,7 +120,6 @@ class MartialScheduleServiceImplTest {
|
|||||||
@Test
|
@Test
|
||||||
@DisplayName("Should handle null venueId in exportScheduleTemplate2")
|
@DisplayName("Should handle null venueId in exportScheduleTemplate2")
|
||||||
void shouldHandleNullVenueIdInExportScheduleTemplate2() {
|
void shouldHandleNullVenueIdInExportScheduleTemplate2() {
|
||||||
// Given
|
|
||||||
Long competitionId = 1L;
|
Long competitionId = 1L;
|
||||||
List<ScheduleExportExcel2> expectedResult = Arrays.asList(
|
List<ScheduleExportExcel2> expectedResult = Arrays.asList(
|
||||||
new ScheduleExportExcel2()
|
new ScheduleExportExcel2()
|
||||||
@@ -138,10 +127,8 @@ class MartialScheduleServiceImplTest {
|
|||||||
when(scheduleExportService.exportScheduleTemplate2(competitionId, null))
|
when(scheduleExportService.exportScheduleTemplate2(competitionId, null))
|
||||||
.thenReturn(expectedResult);
|
.thenReturn(expectedResult);
|
||||||
|
|
||||||
// When
|
|
||||||
List<ScheduleExportExcel2> result = scheduleService.exportScheduleTemplate2(competitionId, null);
|
List<ScheduleExportExcel2> result = scheduleService.exportScheduleTemplate2(competitionId, null);
|
||||||
|
|
||||||
// Then
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals(1, result.size());
|
assertEquals(1, result.size());
|
||||||
verify(scheduleExportService).exportScheduleTemplate2(competitionId, null);
|
verify(scheduleExportService).exportScheduleTemplate2(competitionId, null);
|
||||||
@@ -150,16 +137,13 @@ class MartialScheduleServiceImplTest {
|
|||||||
@Test
|
@Test
|
||||||
@DisplayName("Should handle empty result in exportScheduleTemplate2")
|
@DisplayName("Should handle empty result in exportScheduleTemplate2")
|
||||||
void shouldHandleEmptyResultInExportScheduleTemplate2() {
|
void shouldHandleEmptyResultInExportScheduleTemplate2() {
|
||||||
// Given
|
|
||||||
Long competitionId = 1L;
|
Long competitionId = 1L;
|
||||||
Long venueId = 2L;
|
Long venueId = 2L;
|
||||||
when(scheduleExportService.exportScheduleTemplate2(competitionId, venueId))
|
when(scheduleExportService.exportScheduleTemplate2(competitionId, venueId))
|
||||||
.thenReturn(new ArrayList<>());
|
.thenReturn(new ArrayList<>());
|
||||||
|
|
||||||
// When
|
|
||||||
List<ScheduleExportExcel2> result = scheduleService.exportScheduleTemplate2(competitionId, venueId);
|
List<ScheduleExportExcel2> result = scheduleService.exportScheduleTemplate2(competitionId, venueId);
|
||||||
|
|
||||||
// Then
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertTrue(result.isEmpty());
|
assertTrue(result.isEmpty());
|
||||||
verify(scheduleExportService).exportScheduleTemplate2(competitionId, venueId);
|
verify(scheduleExportService).exportScheduleTemplate2(competitionId, venueId);
|
||||||
@@ -168,17 +152,84 @@ class MartialScheduleServiceImplTest {
|
|||||||
@Test
|
@Test
|
||||||
@DisplayName("Should verify exportScheduleTemplate2 is called exactly once")
|
@DisplayName("Should verify exportScheduleTemplate2 is called exactly once")
|
||||||
void shouldVerifyExportScheduleTemplate2CalledOnce() {
|
void shouldVerifyExportScheduleTemplate2CalledOnce() {
|
||||||
// Given
|
|
||||||
Long competitionId = 1L;
|
Long competitionId = 1L;
|
||||||
Long venueId = 2L;
|
Long venueId = 2L;
|
||||||
when(scheduleExportService.exportScheduleTemplate2(competitionId, venueId))
|
when(scheduleExportService.exportScheduleTemplate2(competitionId, venueId))
|
||||||
.thenReturn(new ArrayList<>());
|
.thenReturn(new ArrayList<>());
|
||||||
|
|
||||||
// When
|
|
||||||
scheduleService.exportScheduleTemplate2(competitionId, venueId);
|
scheduleService.exportScheduleTemplate2(competitionId, venueId);
|
||||||
|
|
||||||
// Then
|
|
||||||
verify(scheduleExportService, times(1)).exportScheduleTemplate2(competitionId, venueId);
|
verify(scheduleExportService, times(1)).exportScheduleTemplate2(competitionId, venueId);
|
||||||
verifyNoMoreInteractions(scheduleExportService);
|
verifyNoMoreInteractions(scheduleExportService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ========== Phase 3: Status Service Tests ==========
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Should delegate updateParticipantCheckInStatus to ScheduleStatusService")
|
||||||
|
void shouldDelegateUpdateParticipantCheckInStatus() {
|
||||||
|
Long participantId = 1L;
|
||||||
|
String status = "CHECKED_IN";
|
||||||
|
when(scheduleStatusService.updateParticipantCheckInStatus(participantId, status))
|
||||||
|
.thenReturn(true);
|
||||||
|
|
||||||
|
boolean result = scheduleService.updateParticipantCheckInStatus(participantId, status);
|
||||||
|
|
||||||
|
assertTrue(result);
|
||||||
|
verify(scheduleStatusService).updateParticipantCheckInStatus(participantId, status);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Should handle null participantId in updateParticipantCheckInStatus")
|
||||||
|
void shouldHandleNullParticipantId() {
|
||||||
|
String status = "CHECKED_IN";
|
||||||
|
when(scheduleStatusService.updateParticipantCheckInStatus(null, status))
|
||||||
|
.thenReturn(false);
|
||||||
|
|
||||||
|
boolean result = scheduleService.updateParticipantCheckInStatus(null, status);
|
||||||
|
|
||||||
|
assertFalse(result);
|
||||||
|
verify(scheduleStatusService).updateParticipantCheckInStatus(null, status);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Should handle null status in updateParticipantCheckInStatus")
|
||||||
|
void shouldHandleNullStatus() {
|
||||||
|
Long participantId = 1L;
|
||||||
|
when(scheduleStatusService.updateParticipantCheckInStatus(participantId, null))
|
||||||
|
.thenReturn(false);
|
||||||
|
|
||||||
|
boolean result = scheduleService.updateParticipantCheckInStatus(participantId, null);
|
||||||
|
|
||||||
|
assertFalse(result);
|
||||||
|
verify(scheduleStatusService).updateParticipantCheckInStatus(participantId, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Should handle update failure in updateParticipantCheckInStatus")
|
||||||
|
void shouldHandleUpdateFailure() {
|
||||||
|
Long participantId = 999L;
|
||||||
|
String status = "CHECKED_IN";
|
||||||
|
when(scheduleStatusService.updateParticipantCheckInStatus(participantId, status))
|
||||||
|
.thenReturn(false);
|
||||||
|
|
||||||
|
boolean result = scheduleService.updateParticipantCheckInStatus(participantId, status);
|
||||||
|
|
||||||
|
assertFalse(result);
|
||||||
|
verify(scheduleStatusService).updateParticipantCheckInStatus(participantId, status);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Should verify updateParticipantCheckInStatus is called exactly once")
|
||||||
|
void shouldVerifyUpdateParticipantCheckInStatusCalledOnce() {
|
||||||
|
Long participantId = 1L;
|
||||||
|
String status = "CHECKED_IN";
|
||||||
|
when(scheduleStatusService.updateParticipantCheckInStatus(participantId, status))
|
||||||
|
.thenReturn(true);
|
||||||
|
|
||||||
|
scheduleService.updateParticipantCheckInStatus(participantId, status);
|
||||||
|
|
||||||
|
verify(scheduleStatusService, times(1)).updateParticipantCheckInStatus(participantId, status);
|
||||||
|
verifyNoMoreInteractions(scheduleStatusService);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user