Skip to content

Commit 6d6cf72

Browse files
author
Vincent Potucek
committed
Avoid empty body warnings imposed by default activation of expandEmptyElements
1 parent 922f9f1 commit 6d6cf72

File tree

2 files changed

+177
-15
lines changed

2 files changed

+177
-15
lines changed

lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2024 DiffPlug
2+
* Copyright 2021-2025 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,39 +27,39 @@ public class SortPomCfg implements Serializable {
2727

2828
public String lineSeparator = System.getProperty("line.separator");
2929

30-
public boolean expandEmptyElements = true;
30+
public boolean expandEmptyElements;
3131

32-
public boolean spaceBeforeCloseEmptyElement = false;
32+
public boolean spaceBeforeCloseEmptyElement;
3333

3434
public boolean keepBlankLines = true;
3535

3636
public boolean endWithNewline = true;
3737

3838
public int nrOfIndentSpace = 2;
3939

40-
public boolean indentBlankLines = false;
40+
public boolean indentBlankLines;
4141

42-
public boolean indentSchemaLocation = false;
42+
public boolean indentSchemaLocation;
4343

44-
public String indentAttribute = null;
44+
public String indentAttribute;
4545

4646
public String predefinedSortOrder = "recommended_2008_06";
4747

48-
public boolean quiet = false;
48+
public boolean quiet;
4949

50-
public String sortOrderFile = null;
50+
public String sortOrderFile;
5151

52-
public String sortDependencies = null;
52+
public String sortDependencies;
5353

54-
public String sortDependencyManagement = null;
54+
public String sortDependencyManagement;
5555

56-
public String sortDependencyExclusions = null;
56+
public String sortDependencyExclusions;
5757

58-
public String sortPlugins = null;
58+
public String sortPlugins;
5959

60-
public boolean sortProperties = false;
60+
public boolean sortProperties;
6161

62-
public boolean sortModules = false;
62+
public boolean sortModules;
6363

64-
public boolean sortExecutions = false;
64+
public boolean sortExecutions;
6565
}
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
package com.diffplug.spotless.pom;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
class SortPomCfgTest {
8+
9+
@Test
10+
void testDefaultValues() {
11+
SortPomCfg cfg = new SortPomCfg();
12+
13+
// Test default values using AssertJ
14+
assertThat(cfg.version).isEqualTo("4.0.0");
15+
assertThat(cfg.encoding).isEqualTo("UTF-8");
16+
assertThat(cfg.lineSeparator).isEqualTo(System.getProperty("line.separator"));
17+
assertThat(cfg.expandEmptyElements).isFalse();
18+
assertThat(cfg.spaceBeforeCloseEmptyElement).isFalse();
19+
assertThat(cfg.keepBlankLines).isTrue();
20+
assertThat(cfg.endWithNewline).isTrue();
21+
assertThat(cfg.nrOfIndentSpace).isEqualTo(2);
22+
assertThat(cfg.indentBlankLines).isFalse();
23+
assertThat(cfg.indentSchemaLocation).isFalse();
24+
assertThat(cfg.indentAttribute).isNull();
25+
assertThat(cfg.predefinedSortOrder).isEqualTo("recommended_2008_06");
26+
assertThat(cfg.quiet).isFalse();
27+
assertThat(cfg.sortOrderFile).isNull();
28+
assertThat(cfg.sortDependencies).isNull();
29+
assertThat(cfg.sortDependencyManagement).isNull();
30+
assertThat(cfg.sortDependencyExclusions).isNull();
31+
assertThat(cfg.sortPlugins).isNull();
32+
assertThat(cfg.sortProperties).isFalse();
33+
assertThat(cfg.sortModules).isFalse();
34+
assertThat(cfg.sortExecutions).isFalse();
35+
}
36+
37+
@Test
38+
void testFieldSetters() {
39+
SortPomCfg cfg = new SortPomCfg();
40+
41+
// Set all fields
42+
cfg.version = "4.1.0";
43+
cfg.encoding = "ISO-8859-1";
44+
cfg.lineSeparator = "\n";
45+
cfg.expandEmptyElements = true;
46+
cfg.spaceBeforeCloseEmptyElement = true;
47+
cfg.keepBlankLines = false;
48+
cfg.endWithNewline = false;
49+
cfg.nrOfIndentSpace = 4;
50+
cfg.indentBlankLines = true;
51+
cfg.indentSchemaLocation = true;
52+
cfg.indentAttribute = "attribute";
53+
cfg.predefinedSortOrder = "custom";
54+
cfg.quiet = true;
55+
cfg.sortOrderFile = "sortOrder.xml";
56+
cfg.sortDependencies = "groupId,artifactId";
57+
cfg.sortDependencyManagement = "scope,groupId";
58+
cfg.sortDependencyExclusions = "artifactId";
59+
cfg.sortPlugins = "groupId";
60+
cfg.sortProperties = true;
61+
cfg.sortModules = true;
62+
cfg.sortExecutions = true;
63+
64+
// Verify all set values with AssertJ
65+
assertThat(cfg.version).isEqualTo("4.1.0");
66+
assertThat(cfg.encoding).isEqualTo("ISO-8859-1");
67+
assertThat(cfg.lineSeparator).isEqualTo("\n");
68+
assertThat(cfg.expandEmptyElements).isTrue();
69+
assertThat(cfg.spaceBeforeCloseEmptyElement).isTrue();
70+
assertThat(cfg.keepBlankLines).isFalse();
71+
assertThat(cfg.endWithNewline).isFalse();
72+
assertThat(cfg.nrOfIndentSpace).isEqualTo(4);
73+
assertThat(cfg.indentBlankLines).isTrue();
74+
assertThat(cfg.indentSchemaLocation).isTrue();
75+
assertThat(cfg.indentAttribute).isEqualTo("attribute");
76+
assertThat(cfg.predefinedSortOrder).isEqualTo("custom");
77+
assertThat(cfg.quiet).isTrue();
78+
assertThat(cfg.sortOrderFile).isEqualTo("sortOrder.xml");
79+
assertThat(cfg.sortDependencies).isEqualTo("groupId,artifactId");
80+
assertThat(cfg.sortDependencyManagement).isEqualTo("scope,groupId");
81+
assertThat(cfg.sortDependencyExclusions).isEqualTo("artifactId");
82+
assertThat(cfg.sortPlugins).isEqualTo("groupId");
83+
assertThat(cfg.sortProperties).isTrue();
84+
assertThat(cfg.sortModules).isTrue();
85+
assertThat(cfg.sortExecutions).isTrue();
86+
}
87+
88+
@Test
89+
void testNullHandling() {
90+
SortPomCfg cfg = new SortPomCfg();
91+
92+
// Set nullable fields to null
93+
cfg.version = null;
94+
cfg.encoding = null;
95+
cfg.lineSeparator = null;
96+
cfg.indentAttribute = null;
97+
cfg.predefinedSortOrder = null;
98+
cfg.sortOrderFile = null;
99+
cfg.sortDependencies = null;
100+
cfg.sortDependencyManagement = null;
101+
cfg.sortDependencyExclusions = null;
102+
cfg.sortPlugins = null;
103+
104+
// Verify null values with AssertJ
105+
assertThat(cfg.version).isNull();
106+
assertThat(cfg.encoding).isNull();
107+
assertThat(cfg.lineSeparator).isNull();
108+
assertThat(cfg.indentAttribute).isNull();
109+
assertThat(cfg.predefinedSortOrder).isNull();
110+
assertThat(cfg.sortOrderFile).isNull();
111+
assertThat(cfg.sortDependencies).isNull();
112+
assertThat(cfg.sortDependencyManagement).isNull();
113+
assertThat(cfg.sortDependencyExclusions).isNull();
114+
assertThat(cfg.sortPlugins).isNull();
115+
}
116+
117+
@Test
118+
void testBooleanFieldsEdgeCases() {
119+
SortPomCfg cfg = new SortPomCfg();
120+
121+
// Toggle all boolean fields
122+
cfg.expandEmptyElements = !cfg.expandEmptyElements;
123+
cfg.spaceBeforeCloseEmptyElement = !cfg.spaceBeforeCloseEmptyElement;
124+
cfg.keepBlankLines = !cfg.keepBlankLines;
125+
cfg.endWithNewline = !cfg.endWithNewline;
126+
cfg.indentBlankLines = !cfg.indentBlankLines;
127+
cfg.indentSchemaLocation = !cfg.indentSchemaLocation;
128+
cfg.quiet = !cfg.quiet;
129+
cfg.sortProperties = !cfg.sortProperties;
130+
cfg.sortModules = !cfg.sortModules;
131+
cfg.sortExecutions = !cfg.sortExecutions;
132+
133+
// Verify all boolean fields are toggled
134+
assertThat(cfg.expandEmptyElements).isTrue();
135+
assertThat(cfg.spaceBeforeCloseEmptyElement).isTrue();
136+
assertThat(cfg.keepBlankLines).isFalse();
137+
assertThat(cfg.endWithNewline).isFalse();
138+
assertThat(cfg.indentBlankLines).isTrue();
139+
assertThat(cfg.indentSchemaLocation).isTrue();
140+
assertThat(cfg.quiet).isTrue();
141+
assertThat(cfg.sortProperties).isTrue();
142+
assertThat(cfg.sortModules).isTrue();
143+
assertThat(cfg.sortExecutions).isTrue();
144+
}
145+
146+
@Test
147+
void testNumericFieldEdgeCases() {
148+
SortPomCfg cfg = new SortPomCfg();
149+
150+
// Test minimum value
151+
cfg.nrOfIndentSpace = 0;
152+
assertThat(cfg.nrOfIndentSpace).isZero();
153+
154+
// Test negative value
155+
cfg.nrOfIndentSpace = -1;
156+
assertThat(cfg.nrOfIndentSpace).isNegative();
157+
158+
// Test large value
159+
cfg.nrOfIndentSpace = Integer.MAX_VALUE;
160+
assertThat(cfg.nrOfIndentSpace).isEqualTo(Integer.MAX_VALUE);
161+
}
162+
}

0 commit comments

Comments
 (0)