test(puzzle): 更新测试用例以适配新的执行结果结构

- 移除已弃用的 DeviceCountRangeConditionStrategy 策略注册
- 修改 PuzzleElementFillEngine 执行方法调用方式,使用 getDynamicData 获取动态数据
- 在 PuzzleGenerateServiceImplTest 中引入 FillResult 类型并更新 mock 返回值结构
- 统一调整所有相关测试断言逻辑以匹配新返回的数据格式
This commit is contained in:
2025-11-20 23:10:27 +08:00
parent 8c76c85ae2
commit 27e58d36d0
3 changed files with 13 additions and 13 deletions

View File

@@ -70,7 +70,7 @@ class PuzzleElementFillEngineTest {
.thenReturn(new ArrayList<>());
// When
Map<String, String> result = engine.execute(templateId, faceId, scenicId);
Map<String, String> result = engine.execute(templateId, faceId, scenicId).getDynamicData();
// 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, scenicId);
Map<String, String> result = engine.execute(templateId, faceId, scenicId).getDynamicData();
// Then
assertEquals(4, result.size());
@@ -133,7 +133,7 @@ class PuzzleElementFillEngineTest {
@Test
@DisplayName("缺少faceId时直接返回空结果")
void shouldReturnEmptyWhenRequiredIdsMissing() {
Map<String, String> result = engine.execute(1L, null, 1L);
Map<String, String> result = engine.execute(1L, null, 1L).getDynamicData();
assertTrue(result.isEmpty());
verifyNoInteractions(ruleMapper, itemMapper, sourceMapper, conditionEvaluator, dataSourceResolver);
}
@@ -165,7 +165,7 @@ class PuzzleElementFillEngineTest {
.thenReturn("https://oss.example.com/valid.png");
// When
Map<String, String> result = engine.execute(templateId, faceId, scenicId);
Map<String, String> result = engine.execute(templateId, faceId, scenicId).getDynamicData();
assertEquals(1, result.size());
assertEquals("https://oss.example.com/valid.png", result.get("avatar"));
@@ -207,7 +207,7 @@ class PuzzleElementFillEngineTest {
.thenReturn("https://oss.example.com/img.jpg");
// When
Map<String, String> result = engine.execute(templateId, faceId, scenicId);
Map<String, String> result = engine.execute(templateId, faceId, scenicId).getDynamicData();
// Then
assertEquals(1, result.size());
@@ -245,7 +245,7 @@ class PuzzleElementFillEngineTest {
when(conditionEvaluator.evaluate(any(), any())).thenReturn(false);
// When
Map<String, String> result = engine.execute(templateId, faceId, scenicId);
Map<String, String> result = engine.execute(templateId, faceId, scenicId).getDynamicData();
// Then
assertTrue(result.isEmpty());
@@ -281,7 +281,7 @@ class PuzzleElementFillEngineTest {
.thenReturn(null);
// When
Map<String, String> result = engine.execute(templateId, faceId, scenicId);
Map<String, String> result = engine.execute(templateId, faceId, scenicId).getDynamicData();
// Then
assertEquals(1, result.size());
@@ -316,7 +316,7 @@ class PuzzleElementFillEngineTest {
.thenReturn("https://oss.example.com/default.jpg");
// When
Map<String, String> result = engine.execute(templateId, faceId, scenicId);
Map<String, String> result = engine.execute(templateId, faceId, scenicId).getDynamicData();
// Then
assertEquals(1, result.size());
@@ -343,7 +343,7 @@ class PuzzleElementFillEngineTest {
when(itemMapper.listByRuleId(1L)).thenReturn(new ArrayList<>());
// When
Map<String, String> result = engine.execute(templateId, faceId, scenicId);
Map<String, String> result = engine.execute(templateId, faceId, scenicId).getDynamicData();
// Then
assertTrue(result.isEmpty());
@@ -361,7 +361,7 @@ class PuzzleElementFillEngineTest {
.thenThrow(new RuntimeException("Database error"));
// When
Map<String, String> result = engine.execute(templateId, faceId, scenicId);
Map<String, String> result = engine.execute(templateId, faceId, scenicId).getDynamicData();
// Then
assertTrue(result.isEmpty());
@@ -407,7 +407,7 @@ class PuzzleElementFillEngineTest {
.thenReturn("https://oss.example.com/device300.jpg");
// When
Map<String, String> result = engine.execute(templateId, faceId, scenicId);
Map<String, String> result = engine.execute(templateId, faceId, scenicId).getDynamicData();
// Then
assertEquals(2, result.size());

View File

@@ -27,7 +27,6 @@ class ConditionEvaluatorTest {
// 注册所有策略
List<ConditionStrategy> strategies = Arrays.asList(
new DeviceCountConditionStrategy(),
new DeviceCountRangeConditionStrategy(),
new DeviceIdMatchConditionStrategy(),
new AlwaysConditionStrategy()
);

View File

@@ -5,6 +5,7 @@ import com.ycwl.basic.puzzle.dto.PuzzleGenerateResponse;
import com.ycwl.basic.puzzle.entity.PuzzleElementEntity;
import com.ycwl.basic.puzzle.entity.PuzzleGenerationRecordEntity;
import com.ycwl.basic.puzzle.entity.PuzzleTemplateEntity;
import com.ycwl.basic.puzzle.fill.FillResult;
import com.ycwl.basic.puzzle.fill.PuzzleElementFillEngine;
import com.ycwl.basic.puzzle.mapper.PuzzleElementMapper;
import com.ycwl.basic.puzzle.mapper.PuzzleGenerationRecordMapper;
@@ -75,7 +76,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), anyLong()))
.thenReturn(Map.of("faceImage", "https://images.test/a.png"));
.thenReturn(FillResult.matched("test-rule", Map.of("faceImage", "https://images.test/a.png"), 1));
when(imageRenderer.render(eq(template), anyList(), anyMap()))
.thenReturn(new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB));
doAnswer(invocation -> {