pmd: добавить 4 правила и вычистить нарушения
- pmd-ruleset.xml: ReturnEmptyCollectionRatherThanNull (p1), AvoidLiteralsInIfCondition (p3), EmptyCatchBlock (p2), ForLoopCanBeForeach (p2) - main: split/contentOf/invokeList возвращают List.of() вместо null; литералы в условиях if вынесены в именованные константы (9 файлов chart/валидатора); индексный цикл легенды → foreach - src/test: 8 литералов в условиях if — те же именованные константы - AGENTS.md: описание ruleset'а и гейта обновлено mvn clean verify зелёный, 0 нарушений PMD.
This commit is contained in:
@@ -54,6 +54,11 @@ import java.util.List;
|
||||
*/
|
||||
public final class SampleDocxGenerator {
|
||||
|
||||
/** Первая страница нумерации (разрыв ставится со второй). */
|
||||
private static final int FIRST_PAGE = 1;
|
||||
/** Путь основной части документа в zip. */
|
||||
private static final String DOCUMENT_PART = "word/document.xml";
|
||||
|
||||
private SampleDocxGenerator() {
|
||||
}
|
||||
|
||||
@@ -280,7 +285,7 @@ public final class SampleDocxGenerator {
|
||||
|
||||
for (int page = 1; page <= 3; page++) {
|
||||
XWPFParagraph p = doc.createParagraph();
|
||||
if (page > 1) {
|
||||
if (page > FIRST_PAGE) {
|
||||
p.getCTP().addNewPPr().addNewPageBreakBefore();
|
||||
}
|
||||
run(p, "Страница " + page, "Times New Roman", false, false);
|
||||
@@ -392,7 +397,7 @@ public final class SampleDocxGenerator {
|
||||
java.util.zip.ZipEntry e;
|
||||
while ((e = zin.getNextEntry()) != null) {
|
||||
byte[] data = zin.readAllBytes();
|
||||
if ("word/document.xml".equals(e.getName())) {
|
||||
if (DOCUMENT_PART.equals(e.getName())) {
|
||||
String xml = new String(data, java.nio.charset.StandardCharsets.UTF_8);
|
||||
StringBuilder sb = new StringBuilder(xml.length() + 4096);
|
||||
int i = 0;
|
||||
|
||||
@@ -20,6 +20,11 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
*/
|
||||
class WordPdfValidatorTest {
|
||||
|
||||
/** Лимит страниц в тесте точной границы (99 разрывов проходят, 100 — нет). */
|
||||
private static final int PAGE_LIMIT = 100;
|
||||
/** Путь основной части документа в zip. */
|
||||
private static final String DOCUMENT_PART = "word/document.xml";
|
||||
|
||||
private static byte[] docxWithPageBreaks(int count) throws Exception {
|
||||
try (XWPFDocument doc = new XWPFDocument()) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
@@ -106,11 +111,11 @@ class WordPdfValidatorTest {
|
||||
void checkPageCount_limitBoundary() throws Exception {
|
||||
for (int breaks : new int[]{0, 3, 99, 100, 101}) {
|
||||
byte[] bytes = docxWithPageBreaks(breaks);
|
||||
if (breaks < 100) {
|
||||
assertDoesNotThrow(() -> WordPdfValidator.checkPageCount(bytes, 100));
|
||||
if (breaks < PAGE_LIMIT) {
|
||||
assertDoesNotThrow(() -> WordPdfValidator.checkPageCount(bytes, PAGE_LIMIT));
|
||||
} else {
|
||||
ValidationException ex = assertThrows(ValidationException.class,
|
||||
() -> WordPdfValidator.checkPageCount(bytes, 100));
|
||||
() -> WordPdfValidator.checkPageCount(bytes, PAGE_LIMIT));
|
||||
assertTrue(ex.getMessage().contains("не менее " + (1 + breaks)),
|
||||
"оценка = 1 + число разрывов: " + ex.getMessage());
|
||||
}
|
||||
@@ -169,7 +174,7 @@ class WordPdfValidatorTest {
|
||||
ZipEntry e;
|
||||
while ((e = zin.getNextEntry()) != null) {
|
||||
byte[] data = zin.readAllBytes();
|
||||
if ("word/document.xml".equals(e.getName())) {
|
||||
if (DOCUMENT_PART.equals(e.getName())) {
|
||||
String xml = new String(data, StandardCharsets.UTF_8);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String t : types) {
|
||||
|
||||
@@ -14,6 +14,9 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
*/
|
||||
class PiePainterTest {
|
||||
|
||||
/** Максимальный разброс каналов у «серого» пикселя (фон/антialiasing). */
|
||||
private static final int GRAY_MAX_SPREAD = 25;
|
||||
|
||||
/**
|
||||
* Форма торта (не масштаб — он зависит от заголовка и легенды): в эталоне
|
||||
* Word силуэт 540×316 px, т.е. h/w = 0,585 при ry/rx = 0,475 и глубине
|
||||
@@ -35,7 +38,7 @@ class PiePainterTest {
|
||||
int r = (rgb >> 16) & 0xFF;
|
||||
int g = (rgb >> 8) & 0xFF;
|
||||
int b = rgb & 0xFF;
|
||||
if (Math.max(Math.max(r, g), b) - Math.min(Math.min(r, g), b) <= 25) {
|
||||
if (Math.max(Math.max(r, g), b) - Math.min(Math.min(r, g), b) <= GRAY_MAX_SPREAD) {
|
||||
continue;
|
||||
}
|
||||
painted++;
|
||||
|
||||
+10
-3
@@ -20,6 +20,13 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
*/
|
||||
class Surface3dPainterTest {
|
||||
|
||||
/** Минимальная альфа «залитого» пикселя. */
|
||||
private static final int PAINTED_ALPHA_MIN = 200;
|
||||
/** Индекс жёлтой полосы палитры (accent4) в тесте седловой ячейки. */
|
||||
private static final int YELLOW_BAND = 3;
|
||||
/** Ограничение длины диагностической строки расхождений. */
|
||||
private static final int SEEN_LIMIT = 40;
|
||||
|
||||
@Test
|
||||
void project_perspectiveMakesFrontEdgeWider() {
|
||||
double rotX = Math.toRadians(15);
|
||||
@@ -68,7 +75,7 @@ class Surface3dPainterTest {
|
||||
for (int y = 0; y < img.getHeight(); y++) {
|
||||
for (int x = 0; x < img.getWidth(); x++) {
|
||||
int argb = img.getRGB(x, y);
|
||||
if (((argb >>> 24) & 0xFF) < 200) {
|
||||
if (((argb >>> 24) & 0xFF) < PAINTED_ALPHA_MIN) {
|
||||
continue;
|
||||
}
|
||||
Color c = new Color(argb);
|
||||
@@ -252,9 +259,9 @@ class Surface3dPainterTest {
|
||||
}
|
||||
checked++;
|
||||
int band = bandOf(new Color(img.getRGB(x, y)), palette);
|
||||
if (band == 3) {
|
||||
if (band == YELLOW_BAND) {
|
||||
yellow++;
|
||||
} else if (seen.length() < 40) {
|
||||
} else if (seen.length() < SEEN_LIMIT) {
|
||||
seen.append("x=").append(x).append(" полоса ").append(band).append("; ");
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user