|
| 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