test: Add MartialScheduleServiceImpl delegation tests

- Add 4 unit tests for exportSchedule delegation
- Test verifies delegation to ScheduleExportService
- Test covers: normal case, empty result, null input, interaction verification

IMPORTANT NOTE:
This service is only PARTIALLY refactored. Most methods still use Mappers directly.
Only exportSchedule() is fully delegated to ScheduleExportService.

Other methods (saveDraftSchedule, saveAndLockSchedule, adjustOrder, saveDispatch)
still contain business logic and Mapper calls - they need further refactoring.

Total tests: 473 (469 + 4 new tests)
All tests passing!
This commit is contained in:
2026-01-18 12:47:01 +08:00
parent a68d0200d1
commit 4e0a8bdde1
9 changed files with 110 additions and 0 deletions
@@ -0,0 +1,110 @@
package org.springblade.modules.martial.service.impl;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springblade.modules.martial.excel.ScheduleExportExcel;
import org.springblade.modules.martial.service.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
/**
* MartialScheduleServiceImpl Test
* Following Google Testing Best Practices
*
* IMPORTANT NOTE:
* This service is only PARTIALLY refactored. Most methods still use Mappers directly.
* Only exportSchedule() is fully delegated to ScheduleExportService.
*
* Other methods (saveDraftSchedule, saveAndLockSchedule, adjustOrder, saveDispatch, etc.)
* still contain business logic and Mapper calls - they need further refactoring.
*
* This test focuses on what IS delegated, not what SHOULD BE delegated.
*/
@DisplayName("MartialScheduleServiceImpl - Delegation Tests")
class MartialScheduleServiceImplTest {
@Mock
private IScheduleExportService scheduleExportService;
@InjectMocks
private MartialScheduleServiceImpl scheduleService;
@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
}
@Test
@DisplayName("Should delegate exportSchedule to ScheduleExportService")
void shouldDelegateExportScheduleToService() {
// Given
Long competitionId = 1L;
List<ScheduleExportExcel> expectedResult = Arrays.asList(
new ScheduleExportExcel(),
new ScheduleExportExcel()
);
when(scheduleExportService.exportSchedule(competitionId)).thenReturn(expectedResult);
// When
List<ScheduleExportExcel> result = scheduleService.exportSchedule(competitionId);
// Then
assertNotNull(result);
assertEquals(2, result.size());
verify(scheduleExportService).exportSchedule(competitionId);
}
@Test
@DisplayName("Should handle empty export result")
void shouldHandleEmptyExportResult() {
// Given
Long competitionId = 1L;
when(scheduleExportService.exportSchedule(competitionId)).thenReturn(new ArrayList<>());
// When
List<ScheduleExportExcel> result = scheduleService.exportSchedule(competitionId);
// Then
assertNotNull(result);
assertTrue(result.isEmpty());
verify(scheduleExportService).exportSchedule(competitionId);
}
@Test
@DisplayName("Should handle null competition ID")
void shouldHandleNullCompetitionId() {
// Given
when(scheduleExportService.exportSchedule(null)).thenReturn(null);
// When
List<ScheduleExportExcel> result = scheduleService.exportSchedule(null);
// Then
assertNull(result);
verify(scheduleExportService).exportSchedule(null);
}
@Test
@DisplayName("Should verify exportSchedule is called exactly once")
void shouldVerifyExportScheduleCalledOnce() {
// Given
Long competitionId = 1L;
when(scheduleExportService.exportSchedule(competitionId)).thenReturn(new ArrayList<>());
// When
scheduleService.exportSchedule(competitionId);
// Then
verify(scheduleExportService, times(1)).exportSchedule(competitionId);
verifyNoMoreInteractions(scheduleExportService);
}
}