Skip to content

Commit ef97fbc

Browse files
committed
feat(ui): implement FontsUtil for consistent font sizing across Swing components
1 parent 526a070 commit ef97fbc

4 files changed

Lines changed: 65 additions & 1 deletion

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
name: swing-ui-test-headless-guard
3+
description: Use when adding or updating EasyPostman Swing/TestNG UI tests that may run in headless CI. Extract and reuse the shared skip logic from AbstractSwingUiTest instead of duplicating DISPLAY/headless checks in each test.
4+
---
5+
6+
# Swing UI Test Headless Guard
7+
8+
Use this skill for Swing UI tests under `easy-postman-app/src/test/java`.
9+
10+
## Default pattern
11+
12+
1. Put shared no-display skip logic in:
13+
`easy-postman-app/src/test/java/com/laker/postman/test/AbstractSwingUiTest.java`
14+
2. Make Swing/UI tests extend that base class.
15+
3. Use `@BeforeClass` + `SkipException` to skip tests when:
16+
- `GraphicsEnvironment.isHeadless()` is `true`
17+
- or Linux has neither `DISPLAY` nor `WAYLAND_DISPLAY`
18+
19+
## Guardrails
20+
21+
- Keep the base class narrow. Only put environment-skip behavior there unless multiple UI tests clearly need more.
22+
- Do not add this base class to non-UI tests.
23+
- Prefer `SkipException` over brittle per-test conditionals.
24+
- After changes, verify with:
25+
- `mvn -q -pl easy-postman-app -am -DskipTests compile`
26+
- `mvn -q -pl easy-postman-app -am -Dtest=<TestClass> -Dsurefire.failIfNoSpecifiedTests=false -Djava.awt.headless=true test`

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- swing-flatlaf-miglayout-principles: Use when modifying EasyPostman Swing forms that use FlatLaf and MigLayout, especially when layout refactors introduce clipped focus rings, dense spacing, border conflicts, or inconsistent form structure. (file: /Users/lonli2/IdeaProjects-laker/easy-postman-github/.codex/skills/swing-flatlaf-miglayout-principles/SKILL.md)
66
- fontsutil-font-usage: Use when modifying EasyPostman Swing UI fonts, especially when dialogs, labels, tables, tabs, or renderers look too large or too small, or when a change must follow the user's configured UI font size. Prefer FontsUtil.getDefaultFontWithOffset(...). (file: /Users/lonli2/IdeaProjects-laker/easy-postman-github/.codex/skills/fontsutil-font-usage/SKILL.md)
7+
- swing-ui-test-headless-guard: Use when adding or updating EasyPostman Swing/TestNG UI tests that may run in headless CI. Reuse `AbstractSwingUiTest` instead of duplicating headless or no-display skip logic. (file: /Users/lonli2/IdeaProjects-laker/easy-postman-github/.codex/skills/swing-ui-test-headless-guard/SKILL.md)
78

89
### How to use skills
910

easy-postman-app/src/test/java/com/laker/postman/panel/collections/right/request/RequestPreparationFeedbackHelperTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package com.laker.postman.panel.collections.right.request;
22

33
import com.formdev.flatlaf.FlatClientProperties;
4+
import com.laker.postman.test.AbstractSwingUiTest;
45
import org.testng.annotations.Test;
56

67
import javax.swing.*;
78

89
import static org.testng.Assert.assertEquals;
910
import static org.testng.Assert.assertNull;
1011

11-
public class RequestPreparationFeedbackHelperTest {
12+
public class RequestPreparationFeedbackHelperTest extends AbstractSwingUiTest {
1213

1314
@Test(description = "清理 URL 校验反馈时只应清除 outline,不应改动 tooltip")
1415
public void testClearUrlValidationFeedback_ShouldOnlyClearOutline() {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.laker.postman.test;
2+
3+
import org.testng.SkipException;
4+
import org.testng.annotations.BeforeClass;
5+
6+
import java.awt.*;
7+
8+
public abstract class AbstractSwingUiTest {
9+
10+
@BeforeClass
11+
public void skipWhenNoDisplayEnvironment() {
12+
if (shouldSkipForHeadlessEnvironment()) {
13+
throw new SkipException("Skipping Swing UI test in headless/no-display environment");
14+
}
15+
}
16+
17+
protected boolean shouldSkipForHeadlessEnvironment() {
18+
if (GraphicsEnvironment.isHeadless()) {
19+
return true;
20+
}
21+
22+
String osName = System.getProperty("os.name", "").toLowerCase();
23+
boolean linuxLike = osName.contains("linux");
24+
if (!linuxLike) {
25+
return false;
26+
}
27+
28+
String display = System.getenv("DISPLAY");
29+
String waylandDisplay = System.getenv("WAYLAND_DISPLAY");
30+
return isBlank(display) && isBlank(waylandDisplay);
31+
}
32+
33+
private boolean isBlank(String value) {
34+
return value == null || value.trim().isEmpty();
35+
}
36+
}

0 commit comments

Comments
 (0)