test: add unit tests for ScheduleStatusService and ScheduleExportService
Google Testing Standards Implementation: - Add 5 unit tests for ScheduleStatusServiceImpl * Test successful status update * Test participant not found scenario * Test update failure scenario * Test different status values * Test null status validation - Add 6 unit tests for ScheduleExportServiceImpl * Test empty schedule details * Test export with participants * Test template2 with/without venue filter * Test null competition ID handling - All tests use Mockito for dependency isolation - Total tests: 454 (was 443), all passing Related to Phase 2 testing requirements
This commit is contained in:
+130
@@ -0,0 +1,130 @@
|
||||
package org.springblade.modules.martial.service.impl;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springblade.modules.martial.excel.ScheduleExportExcel;
|
||||
import org.springblade.modules.martial.excel.ScheduleExportExcel2;
|
||||
import org.springblade.modules.martial.mapper.MartialScheduleGroupMapper;
|
||||
import org.springblade.modules.martial.pojo.vo.ScheduleGroupDetailVO;
|
||||
import org.springblade.modules.martial.service.IMartialProjectService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@DisplayName("ScheduleExportService Unit Tests")
|
||||
class ScheduleExportServiceImplTest {
|
||||
|
||||
@Mock
|
||||
private MartialScheduleGroupMapper scheduleGroupMapper;
|
||||
|
||||
@Mock
|
||||
private IMartialProjectService projectService;
|
||||
|
||||
@InjectMocks
|
||||
private ScheduleExportServiceImpl scheduleExportService;
|
||||
|
||||
@Test
|
||||
@DisplayName("Should return empty list when no schedule details")
|
||||
void shouldReturnEmptyListWhenNoDetails() {
|
||||
Long competitionId = 1L;
|
||||
when(scheduleGroupMapper.selectScheduleGroupDetails(competitionId)).thenReturn(new ArrayList<>());
|
||||
|
||||
List<ScheduleExportExcel> result = scheduleExportService.exportSchedule(competitionId);
|
||||
|
||||
assertNotNull(result);
|
||||
assertTrue(result.isEmpty());
|
||||
verify(scheduleGroupMapper).selectScheduleGroupDetails(competitionId);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should export schedule with participants")
|
||||
void shouldExportScheduleWithParticipants() {
|
||||
Long competitionId = 1L;
|
||||
List<ScheduleGroupDetailVO> details = createMockScheduleDetails();
|
||||
|
||||
when(scheduleGroupMapper.selectScheduleGroupDetails(competitionId)).thenReturn(details);
|
||||
|
||||
List<ScheduleExportExcel> result = scheduleExportService.exportSchedule(competitionId);
|
||||
|
||||
assertNotNull(result);
|
||||
assertFalse(result.isEmpty());
|
||||
verify(scheduleGroupMapper).selectScheduleGroupDetails(competitionId);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should return empty list for template2 when no details")
|
||||
void shouldReturnEmptyListForTemplate2WhenNoDetails() {
|
||||
Long competitionId = 1L;
|
||||
when(scheduleGroupMapper.selectScheduleGroupDetails(competitionId)).thenReturn(new ArrayList<>());
|
||||
|
||||
List<ScheduleExportExcel2> result = scheduleExportService.exportScheduleTemplate2(competitionId, null);
|
||||
|
||||
assertNotNull(result);
|
||||
assertTrue(result.isEmpty());
|
||||
verify(scheduleGroupMapper).selectScheduleGroupDetails(competitionId);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should export template2 with venue filter")
|
||||
void shouldExportTemplate2WithVenueFilter() {
|
||||
Long competitionId = 1L;
|
||||
Long venueId = 10L;
|
||||
List<ScheduleGroupDetailVO> details = createMockScheduleDetails();
|
||||
|
||||
when(scheduleGroupMapper.selectScheduleGroupDetails(competitionId)).thenReturn(details);
|
||||
|
||||
List<ScheduleExportExcel2> result = scheduleExportService.exportScheduleTemplate2(competitionId, venueId);
|
||||
|
||||
assertNotNull(result);
|
||||
verify(scheduleGroupMapper).selectScheduleGroupDetails(competitionId);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should export template2 without venue filter")
|
||||
void shouldExportTemplate2WithoutVenueFilter() {
|
||||
Long competitionId = 1L;
|
||||
List<ScheduleGroupDetailVO> details = createMockScheduleDetails();
|
||||
|
||||
when(scheduleGroupMapper.selectScheduleGroupDetails(competitionId)).thenReturn(details);
|
||||
|
||||
List<ScheduleExportExcel2> result = scheduleExportService.exportScheduleTemplate2(competitionId, null);
|
||||
|
||||
assertNotNull(result);
|
||||
verify(scheduleGroupMapper).selectScheduleGroupDetails(competitionId);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should handle null competition ID gracefully")
|
||||
void shouldHandleNullCompetitionId() {
|
||||
when(scheduleGroupMapper.selectScheduleGroupDetails(null)).thenReturn(new ArrayList<>());
|
||||
|
||||
List<ScheduleExportExcel> result = scheduleExportService.exportSchedule(null);
|
||||
|
||||
assertNotNull(result);
|
||||
assertTrue(result.isEmpty());
|
||||
}
|
||||
|
||||
private List<ScheduleGroupDetailVO> createMockScheduleDetails() {
|
||||
List<ScheduleGroupDetailVO> details = new ArrayList<>();
|
||||
ScheduleGroupDetailVO detail = new ScheduleGroupDetailVO();
|
||||
detail.setGroupId(1L);
|
||||
detail.setGroupName("Test Group");
|
||||
detail.setVenueId(10L);
|
||||
detail.setVenueName("Test Venue");
|
||||
detail.setParticipantId(100L);
|
||||
detail.setPlayerName("Test Player");
|
||||
detail.setOrganization("Test Org");
|
||||
detail.setDisplayOrder(1);
|
||||
details.add(detail);
|
||||
return details;
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
package org.springblade.modules.martial.service.impl;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springblade.modules.martial.mapper.MartialScheduleParticipantMapper;
|
||||
import org.springblade.modules.martial.pojo.entity.MartialScheduleParticipant;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@DisplayName("ScheduleStatusService Unit Tests")
|
||||
class ScheduleStatusServiceImplTest {
|
||||
|
||||
@Mock
|
||||
private MartialScheduleParticipantMapper scheduleParticipantMapper;
|
||||
|
||||
@InjectMocks
|
||||
private ScheduleStatusServiceImpl scheduleStatusService;
|
||||
|
||||
@Test
|
||||
@DisplayName("Should update participant check-in status successfully")
|
||||
void shouldUpdateParticipantCheckInStatus() {
|
||||
Long participantId = 1L;
|
||||
String status = "已签到";
|
||||
MartialScheduleParticipant participant = new MartialScheduleParticipant();
|
||||
participant.setId(participantId);
|
||||
|
||||
when(scheduleParticipantMapper.selectById(participantId)).thenReturn(participant);
|
||||
when(scheduleParticipantMapper.updateById(any(MartialScheduleParticipant.class))).thenReturn(1);
|
||||
|
||||
boolean result = scheduleStatusService.updateParticipantCheckInStatus(participantId, status);
|
||||
|
||||
assertTrue(result);
|
||||
verify(scheduleParticipantMapper).selectById(participantId);
|
||||
verify(scheduleParticipantMapper).updateById(any(MartialScheduleParticipant.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should return false when participant not found")
|
||||
void shouldReturnFalseWhenParticipantNotFound() {
|
||||
Long participantId = 999L;
|
||||
String status = "已签到";
|
||||
|
||||
when(scheduleParticipantMapper.selectById(participantId)).thenReturn(null);
|
||||
|
||||
boolean result = scheduleStatusService.updateParticipantCheckInStatus(participantId, status);
|
||||
|
||||
assertFalse(result);
|
||||
verify(scheduleParticipantMapper).selectById(participantId);
|
||||
verify(scheduleParticipantMapper, never()).updateById(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should return false when update fails")
|
||||
void shouldReturnFalseWhenUpdateFails() {
|
||||
Long participantId = 1L;
|
||||
String status = "已签到";
|
||||
MartialScheduleParticipant participant = new MartialScheduleParticipant();
|
||||
participant.setId(participantId);
|
||||
|
||||
when(scheduleParticipantMapper.selectById(participantId)).thenReturn(participant);
|
||||
when(scheduleParticipantMapper.updateById(any(MartialScheduleParticipant.class))).thenReturn(0);
|
||||
|
||||
boolean result = scheduleStatusService.updateParticipantCheckInStatus(participantId, status);
|
||||
|
||||
assertFalse(result);
|
||||
verify(scheduleParticipantMapper).updateById(any(MartialScheduleParticipant.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should handle different status values")
|
||||
void shouldHandleDifferentStatusValues() {
|
||||
Long participantId = 1L;
|
||||
MartialScheduleParticipant participant = new MartialScheduleParticipant();
|
||||
participant.setId(participantId);
|
||||
|
||||
when(scheduleParticipantMapper.selectById(participantId)).thenReturn(participant);
|
||||
when(scheduleParticipantMapper.updateById(any(MartialScheduleParticipant.class))).thenReturn(1);
|
||||
|
||||
assertTrue(scheduleStatusService.updateParticipantCheckInStatus(participantId, "已签到"));
|
||||
assertTrue(scheduleStatusService.updateParticipantCheckInStatus(participantId, "未签到"));
|
||||
assertTrue(scheduleStatusService.updateParticipantCheckInStatus(participantId, "已完成"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should return false when status is null")
|
||||
void shouldReturnFalseWhenStatusIsNull() {
|
||||
Long participantId = 1L;
|
||||
|
||||
boolean result = scheduleStatusService.updateParticipantCheckInStatus(participantId, null);
|
||||
|
||||
assertFalse(result);
|
||||
verify(scheduleParticipantMapper, never()).selectById(any());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user