Skip to content

Commit f212f0e

Browse files
committed
Improved solution
1 parent 12584c2 commit f212f0e

4 files changed

Lines changed: 25 additions & 259 deletions

File tree

spml/src/main/resources/cursor-rule-generator.xsl

Lines changed: 0 additions & 37 deletions
This file was deleted.

spml/src/main/resources/maven-best-practices-generator.xsl

Lines changed: 0 additions & 158 deletions
This file was deleted.

spml/src/main/resources/unified-generator.xsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ Description: </xsl:text><xsl:value-of select="normalize-space(rule-description)"
8888
<xsl:text>
8989
```</xsl:text>
9090
</xsl:if>
91+
<xsl:if test="position() != last()">
92+
<xsl:text>
93+
</xsl:text>
94+
</xsl:if>
9195
</xsl:template>
9296

9397
<!-- Template section template -->

spml/src/test/java/info/jab/xml/CursorRuleGeneratorTest.java

Lines changed: 21 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ void should_throwException_when_xmlFileDoesNotExist() {
2626
CursorRuleGenerator generator = new CursorRuleGenerator();
2727

2828
// When & Then
29-
assertThatThrownBy(() -> generator.generate("non-existent.xml", "cursor-rule-generator.xsl"))
29+
assertThatThrownBy(() -> generator.generate("non-existent.xml", "unified-generator.xsl"))
3030
.isInstanceOf(RuntimeException.class)
3131
.hasMessageContaining("Error during XML transformation")
3232
.hasCauseInstanceOf(RuntimeException.class);
3333

3434
// Verify the cause contains our expected message
3535
try {
36-
generator.generate("non-existent.xml", "cursor-rule-generator.xsl");
36+
generator.generate("non-existent.xml", "unified-generator.xsl");
3737
} catch (RuntimeException e) {
3838
assertThat(e.getCause().getMessage())
3939
.contains("Could not load XML or XSLT resources")
@@ -63,46 +63,6 @@ void should_throwException_when_xsltFileDoesNotExist() {
6363
}
6464
}
6565

66-
@Test
67-
@DisplayName("Should generate exact content matching expected Maven best practices document")
68-
void should_generateExactContentMatchingExpectedDocument_when_transformingMavenBestPracticesXml() throws IOException {
69-
// Given
70-
CursorRuleGenerator generator = new CursorRuleGenerator();
71-
String expectedContent = loadExpectedContent("110-java-maven-best-practices.mdc");
72-
73-
// When
74-
String actualResult = generator.generate("110-java-maven-best-practices.xml", "maven-best-practices-generator.xsl");
75-
76-
// Save generated content to target directory for manual comparison
77-
saveGeneratedContentToTarget(actualResult, "110-java-maven-best-practices-generated.mdc");
78-
79-
// Then
80-
assertThat(actualResult)
81-
.isNotNull()
82-
.isNotEmpty()
83-
.isEqualTo(expectedContent);
84-
}
85-
86-
@Test
87-
@DisplayName("Should generate exact content matching expected Maven documentation document")
88-
void should_generateExactContentMatchingExpectedDocument_when_transformingMavenDocumentationXml() throws IOException {
89-
// Given
90-
CursorRuleGenerator generator = new CursorRuleGenerator();
91-
String expectedContent = loadExpectedContent("112-java-maven-documentation.mdc");
92-
93-
// When
94-
String actualResult = generator.generate("112-java-maven-documentation.xml", "cursor-rule-generator.xsl");
95-
96-
// Save generated content to target directory for manual comparison
97-
saveGeneratedContentToTarget(actualResult, "112-java-maven-documentation-generated.mdc");
98-
99-
// Then
100-
assertThat(actualResult)
101-
.isNotNull()
102-
.isNotEmpty()
103-
.isEqualTo(expectedContent);
104-
}
105-
10666
private String loadExpectedContent(String filename) throws IOException {
10767
try (var inputStream = getClass().getClassLoader().getResourceAsStream(filename)) {
10868
if (Objects.isNull(inputStream)) {
@@ -128,49 +88,37 @@ private void saveGeneratedContentToTarget(String content, String filename) throw
12888
class UnifiedXsltGeneratorTests {
12989

13090
@Test
131-
@DisplayName("Should generate content for Maven best practices using unified XSLT")
132-
void should_generateContent_when_transformingMavenBestPracticesWithUnifiedXslt() throws IOException {
91+
@DisplayName("Should generate exact content matching original expected Maven best practices document using unified XSLT")
92+
void should_generateExactContentMatchingOriginalExpected_when_transformingMavenBestPracticesWithUnifiedXslt() throws IOException {
13393
// Given
13494
CursorRuleGenerator generator = new CursorRuleGenerator();
95+
String expectedContent = loadExpectedContent("110-java-maven-best-practices.mdc");
13596

13697
// When
13798
String actualResult = generator.generate("110-java-maven-best-practices.xml", "unified-generator.xsl");
13899

139-
// Save generated content to target directory for comparison
140-
saveGeneratedContentToTarget(actualResult, "110-maven-unified-generated.mdc");
141-
142-
// Then
100+
// Then - Unified XSLT should produce identical output to specialized XSLT
143101
assertThat(actualResult)
144102
.isNotNull()
145103
.isNotEmpty()
146-
.contains("# Maven Best Practices")
147-
.contains("## Rule 1: Effective Dependency Management")
148-
.contains("**Good example:**")
149-
.contains("**Bad Example:**")
150-
.contains("## Table of contents");
104+
.isEqualTo(expectedContent);
151105
}
152106

153107
@Test
154-
@DisplayName("Should generate content for Maven documentation using unified XSLT")
155-
void should_generateContent_when_transformingMavenDocumentationWithUnifiedXslt() throws IOException {
108+
@DisplayName("Should generate exact content matching original expected Maven documentation document using unified XSLT")
109+
void should_generateExactContentMatchingOriginalExpected_when_transformingMavenDocumentationWithUnifiedXslt() throws IOException {
156110
// Given
157111
CursorRuleGenerator generator = new CursorRuleGenerator();
112+
String expectedContent = loadExpectedContent("112-java-maven-documentation.mdc");
158113

159114
// When
160115
String actualResult = generator.generate("112-java-maven-documentation.xml", "unified-generator.xsl");
161116

162-
// Save generated content to target directory for comparison
163-
saveGeneratedContentToTarget(actualResult, "112-maven-documentation-unified-generated.mdc");
164-
165-
// Then
117+
// Then - Unified XSLT should produce identical output to specialized XSLT
166118
assertThat(actualResult)
167119
.isNotNull()
168120
.isNotEmpty()
169-
.contains("# Create README-DEV.md with information about how to use the Maven project")
170-
.contains("## STRICT Structure for README-DEV.md (Template):")
171-
.contains("# Essential Maven Goals:")
172-
.contains("./mvnw dependency:tree")
173-
.contains("**END OF TEMPLATE");
121+
.isEqualTo(expectedContent);
174122
}
175123

176124
@Test
@@ -199,6 +147,15 @@ void should_produceConsistentStructure_when_processingDifferentXmlTypes() throws
199147
saveGeneratedContentToTarget(documentationResult, "unified-documentation.mdc");
200148
}
201149

150+
private String loadExpectedContent(String filename) throws IOException {
151+
try (var inputStream = getClass().getClassLoader().getResourceAsStream(filename)) {
152+
if (Objects.isNull(inputStream)) {
153+
throw new IOException("Resource not found: " + filename);
154+
}
155+
return new String(inputStream.readAllBytes()).trim();
156+
}
157+
}
158+
202159
private void saveGeneratedContentToTarget(String content, String filename) throws IOException {
203160
Path targetDir = Paths.get("target");
204161
if (!Files.exists(targetDir)) {

0 commit comments

Comments
 (0)