feat(puzzle): 更新拼图元素填充引擎执行方法参数

- 在engine.execute方法调用中增加scenicId参数
- 修改测试用例以适应新的方法签名
- 确保所有相关测试验证逻辑正确性
- 更新PuzzleGenerateServiceImplTest中的fillEngine调用参数
- 调整verify语句匹配新参数列表
- 保持原有功能逻辑不变仅扩展参数传递
This commit is contained in:
2025-11-20 11:41:22 +08:00
parent 536f2866f6
commit d1381c93b0
2 changed files with 15 additions and 14 deletions

View File

@@ -70,7 +70,7 @@ class PuzzleElementFillEngineTest {
.thenReturn(new ArrayList<>());
// When
Map<String, String> result = engine.execute(templateId, faceId);
Map<String, String> result = engine.execute(templateId, faceId, scenicId);
// Then
assertTrue(result.isEmpty());
@@ -116,7 +116,7 @@ class PuzzleElementFillEngineTest {
.thenReturn("https://oss.example.com/img4.jpg");
// When
Map<String, String> result = engine.execute(templateId, faceId);
Map<String, String> result = engine.execute(templateId, faceId, scenicId);
// Then
assertEquals(4, result.size());
@@ -133,7 +133,7 @@ class PuzzleElementFillEngineTest {
@Test
@DisplayName("缺少faceId时直接返回空结果")
void shouldReturnEmptyWhenRequiredIdsMissing() {
Map<String, String> result = engine.execute(1L, null);
Map<String, String> result = engine.execute(1L, null, 1L);
assertTrue(result.isEmpty());
verifyNoInteractions(ruleMapper, itemMapper, sourceMapper, conditionEvaluator, dataSourceResolver);
}
@@ -143,6 +143,7 @@ class PuzzleElementFillEngineTest {
void shouldContinueWhenRuleHasNoItems() {
Long templateId = 1L;
Long faceId = 123L;
Long scenicId = 1L;
PuzzleFillRuleEntity highPriorityRule = createRule(1L, "高优先级无明细", 200);
PuzzleFillRuleEntity lowPriorityRule = createRule(2L, "低优先级有效", 100);
@@ -164,7 +165,7 @@ class PuzzleElementFillEngineTest {
.thenReturn("https://oss.example.com/valid.png");
// When
Map<String, String> result = engine.execute(templateId, faceId);
Map<String, String> result = engine.execute(templateId, faceId, scenicId);
assertEquals(1, result.size());
assertEquals("https://oss.example.com/valid.png", result.get("avatar"));
@@ -206,7 +207,7 @@ class PuzzleElementFillEngineTest {
.thenReturn("https://oss.example.com/img.jpg");
// When
Map<String, String> result = engine.execute(templateId, faceId);
Map<String, String> result = engine.execute(templateId, faceId, scenicId);
// Then
assertEquals(1, result.size());
@@ -244,7 +245,7 @@ class PuzzleElementFillEngineTest {
when(conditionEvaluator.evaluate(any(), any())).thenReturn(false);
// When
Map<String, String> result = engine.execute(templateId, faceId);
Map<String, String> result = engine.execute(templateId, faceId, scenicId);
// Then
assertTrue(result.isEmpty());
@@ -280,7 +281,7 @@ class PuzzleElementFillEngineTest {
.thenReturn(null);
// When
Map<String, String> result = engine.execute(templateId, faceId);
Map<String, String> result = engine.execute(templateId, faceId, scenicId);
// Then
assertEquals(1, result.size());
@@ -315,7 +316,7 @@ class PuzzleElementFillEngineTest {
.thenReturn("https://oss.example.com/default.jpg");
// When
Map<String, String> result = engine.execute(templateId, faceId);
Map<String, String> result = engine.execute(templateId, faceId, scenicId);
// Then
assertEquals(1, result.size());
@@ -342,7 +343,7 @@ class PuzzleElementFillEngineTest {
when(itemMapper.listByRuleId(1L)).thenReturn(new ArrayList<>());
// When
Map<String, String> result = engine.execute(templateId, faceId);
Map<String, String> result = engine.execute(templateId, faceId, scenicId);
// Then
assertTrue(result.isEmpty());
@@ -360,7 +361,7 @@ class PuzzleElementFillEngineTest {
.thenThrow(new RuntimeException("Database error"));
// When
Map<String, String> result = engine.execute(templateId, faceId);
Map<String, String> result = engine.execute(templateId, faceId, scenicId);
// Then
assertTrue(result.isEmpty());
@@ -406,7 +407,7 @@ class PuzzleElementFillEngineTest {
.thenReturn("https://oss.example.com/device300.jpg");
// When
Map<String, String> result = engine.execute(templateId, faceId);
Map<String, String> result = engine.execute(templateId, faceId, scenicId);
// Then
assertEquals(2, result.size());

View File

@@ -74,7 +74,7 @@ class PuzzleGenerateServiceImplTest {
when(templateMapper.getByCode("ticket")).thenReturn(template);
when(elementMapper.getByTemplateId(template.getId())).thenReturn(List.of(element));
when(fillEngine.execute(eq(template.getId()), eq(88L)))
when(fillEngine.execute(eq(template.getId()), eq(88L), anyLong()))
.thenReturn(Map.of("faceImage", "https://images.test/a.png"));
when(imageRenderer.render(eq(template), anyList(), anyMap()))
.thenReturn(new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB));
@@ -105,7 +105,7 @@ class PuzzleGenerateServiceImplTest {
resetStorageFactory();
}
verify(fillEngine).execute(template.getId(), 88L);
verify(fillEngine).execute(template.getId(), 88L, 9L);
ArgumentCaptor<com.ycwl.basic.puzzle.entity.PuzzleGenerationRecordEntity> captor =
ArgumentCaptor.forClass(com.ycwl.basic.puzzle.entity.PuzzleGenerationRecordEntity.class);
verify(recordMapper).insert(captor.capture());
@@ -147,7 +147,7 @@ class PuzzleGenerateServiceImplTest {
resetStorageFactory();
}
verify(fillEngine, never()).execute(anyLong(), anyLong());
verify(fillEngine, never()).execute(anyLong(), anyLong(), anyLong());
}
@SuppressWarnings("unchecked")