From 798ac2c0098cce97acadbe1458b2934a41a781d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=85=E6=88=BF?= Date: Sun, 18 Jan 2026 01:38:51 +0800 Subject: [PATCH] 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 --- .../impl/ScheduleExportServiceImplTest.java | 130 ++++++++++++++++++ .../impl/ScheduleStatusServiceImplTest.java | 101 ++++++++++++++ 2 files changed, 231 insertions(+) create mode 100644 src/test/java/org/springblade/modules/martial/service/impl/ScheduleExportServiceImplTest.java create mode 100644 src/test/java/org/springblade/modules/martial/service/impl/ScheduleStatusServiceImplTest.java diff --git a/src/test/java/org/springblade/modules/martial/service/impl/ScheduleExportServiceImplTest.java b/src/test/java/org/springblade/modules/martial/service/impl/ScheduleExportServiceImplTest.java new file mode 100644 index 0000000..dcb9c28 --- /dev/null +++ b/src/test/java/org/springblade/modules/martial/service/impl/ScheduleExportServiceImplTest.java @@ -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 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 details = createMockScheduleDetails(); + + when(scheduleGroupMapper.selectScheduleGroupDetails(competitionId)).thenReturn(details); + + List 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 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 details = createMockScheduleDetails(); + + when(scheduleGroupMapper.selectScheduleGroupDetails(competitionId)).thenReturn(details); + + List 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 details = createMockScheduleDetails(); + + when(scheduleGroupMapper.selectScheduleGroupDetails(competitionId)).thenReturn(details); + + List 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 result = scheduleExportService.exportSchedule(null); + + assertNotNull(result); + assertTrue(result.isEmpty()); + } + + private List createMockScheduleDetails() { + List 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; + } +} diff --git a/src/test/java/org/springblade/modules/martial/service/impl/ScheduleStatusServiceImplTest.java b/src/test/java/org/springblade/modules/martial/service/impl/ScheduleStatusServiceImplTest.java new file mode 100644 index 0000000..e0e7aa9 --- /dev/null +++ b/src/test/java/org/springblade/modules/martial/service/impl/ScheduleStatusServiceImplTest.java @@ -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()); + } +}