test(cache): 修复CacheConfigTest边界值测试
- 修改 shouldVerifyCacheManager_withMaximumIntegerTtl 为 shouldVerifyCacheManager_withMaximumAllowedTtl - 使用正确的最大TTL值(10080分钟,7天)而不是 Integer.MAX_VALUE - 新增 shouldThrowException_whenTtlExceedsMaximum 测试验证边界检查 - 所有1266个测试用例通过 - 覆盖率: 指令81.89%, 行88.48%, 分支51.55% docs: 添加项目状态报告 - 生成 PROJECT_STATUS_REPORT.md 详细记录项目当前状态 - 包含质量指标、已完成功能、待办事项和技术债务
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
package com.mosquito.project.service;
|
||||
|
||||
import com.mosquito.project.config.PosterConfig;
|
||||
import com.mosquito.project.persistence.entity.ShortLinkEntity;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class PosterRenderServiceTest {
|
||||
|
||||
@BeforeAll
|
||||
static void enableHeadlessMode() {
|
||||
System.setProperty("java.awt.headless", "true");
|
||||
}
|
||||
|
||||
@Test
|
||||
void renderPosterHtml_includesElementsAndShortUrl() {
|
||||
ShortLinkService shortLinkService = Mockito.mock(ShortLinkService.class);
|
||||
ShortLinkEntity shortLink = new ShortLinkEntity();
|
||||
shortLink.setCode("short123");
|
||||
when(shortLinkService.create(anyString())).thenReturn(shortLink);
|
||||
|
||||
PosterConfig posterConfig = buildPosterConfig(buildHtmlElements());
|
||||
PosterRenderService service = new PosterRenderService(posterConfig, shortLinkService);
|
||||
|
||||
String html = service.renderPosterHtml(10L, 20L, "custom");
|
||||
|
||||
assertTrue(html.contains("/r/short123"));
|
||||
assertTrue(html.contains("data=%2Fr%2Fshort123"));
|
||||
assertTrue(html.contains("Hello 10"));
|
||||
assertTrue(html.contains("https://example.com/image.png"));
|
||||
assertTrue(html.contains("立即加入"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void renderPoster_generatesPngBytes() {
|
||||
ShortLinkService shortLinkService = Mockito.mock(ShortLinkService.class);
|
||||
PosterConfig posterConfig = buildPosterConfig(buildImageElements());
|
||||
PosterRenderService service = new PosterRenderService(posterConfig, shortLinkService);
|
||||
|
||||
byte[] bytes = service.renderPoster(11L, 22L, "custom");
|
||||
|
||||
assertTrue(bytes.length > 0);
|
||||
}
|
||||
|
||||
private PosterConfig buildPosterConfig(Map<String, PosterConfig.PosterElement> elements) {
|
||||
PosterConfig posterConfig = new PosterConfig();
|
||||
posterConfig.setDefaultTemplate("default");
|
||||
|
||||
PosterConfig.PosterTemplate template = new PosterConfig.PosterTemplate();
|
||||
template.setWidth(300);
|
||||
template.setHeight(400);
|
||||
template.setBackgroundColor("#ffffff");
|
||||
template.setElements(elements);
|
||||
|
||||
Map<String, PosterConfig.PosterTemplate> templates = new HashMap<>();
|
||||
templates.put("default", template);
|
||||
templates.put("custom", template);
|
||||
posterConfig.setTemplates(templates);
|
||||
return posterConfig;
|
||||
}
|
||||
|
||||
private Map<String, PosterConfig.PosterElement> buildHtmlElements() {
|
||||
Map<String, PosterConfig.PosterElement> elements = new HashMap<>();
|
||||
elements.put("text", element("text", 10, 10, 200, 30, "Hello {{activityId}}"));
|
||||
elements.put("qrcode", element("qrcode", 10, 50, 120, 120, "{{shortUrl}}"));
|
||||
elements.put("image", element("image", 10, 200, 80, 80, "https://example.com/image.png"));
|
||||
elements.put("button", element("button", 10, 300, 120, 40, "立即加入"));
|
||||
return elements;
|
||||
}
|
||||
|
||||
private Map<String, PosterConfig.PosterElement> buildImageElements() {
|
||||
Map<String, PosterConfig.PosterElement> elements = new HashMap<>();
|
||||
elements.put("text", element("text", 10, 10, 200, 30, "Poster {{activityId}}"));
|
||||
elements.put("qrcode", element("qrcode", 10, 60, 120, 120, "{{shortUrl}}"));
|
||||
elements.put("rect", element("rect", 10, 200, 80, 40, ""));
|
||||
return elements;
|
||||
}
|
||||
|
||||
private PosterConfig.PosterElement element(String type, int x, int y, int width, int height, String content) {
|
||||
PosterConfig.PosterElement element = new PosterConfig.PosterElement();
|
||||
element.setType(type);
|
||||
element.setX(x);
|
||||
element.setY(y);
|
||||
element.setWidth(width);
|
||||
element.setHeight(height);
|
||||
element.setContent(content);
|
||||
return element;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user