77import java .nio .file .Path ;
88import java .util .stream .Stream ;
99
10- import org .assertj .core .api .SoftAssertions ;
11- import org .junit .jupiter .api .Test ;
1210import org .junit .jupiter .api .io .TempDir ;
11+ import org .junit .jupiter .params .ParameterizedTest ;
12+ import org .junit .jupiter .params .provider .MethodSource ;
1313import org .slf4j .Logger ;
1414import org .slf4j .LoggerFactory ;
15+ import org .xmlunit .assertj3 .XmlAssert ;
1516
1617import com .devonfw .tools .ide .context .AbstractIdeContextTest ;
1718import com .devonfw .tools .ide .context .IdeContext ;
@@ -21,7 +22,7 @@ class XmlMergerTest extends AbstractIdeContextTest {
2122
2223 private static Logger LOG = LoggerFactory .getLogger (XmlMergerTest .class );
2324
24- private static final Path TEST_RESOURCES = Path .of ("src" , "test" , "resources" , "xmlmerger" );
25+ private static final Path XML_TEST_RESOURCES = Path .of ("src" , "test" , "resources" , "xmlmerger" );
2526
2627 private static final String SOURCE_XML = "source.xml" ;
2728
@@ -37,28 +38,24 @@ class XmlMergerTest extends AbstractIdeContextTest {
3738 * Tests the XML merger functionality across multiple test cases. This test method iterates through all subdirectories in the test resources folder, each
3839 * representing a different test case.
3940 */
40- @ Test
41- void testMerger (@ TempDir Path tempDir ) throws Exception {
42-
43- try (Stream <Path > folders = Files .list (TEST_RESOURCES )) {
44- // arrange
45- SoftAssertions softly = new SoftAssertions ();
46- folders .forEach (folder -> {
47- LOG .info ("Testing XML merger for test-case {}" , folder .getFileName ());
48- Path sourcePath = folder .resolve (SOURCE_XML );
49- Path targetPath = tempDir .resolve (TARGET_XML );
50- Path resultPath = folder .resolve (RESULT_XML );
51- try {
52- Files .copy (folder .resolve (TARGET_XML ), targetPath , REPLACE_EXISTING );
53- // act
54- this .merger .merge (null , sourcePath , this .context .getVariables (), targetPath );
55- // assert
56- softly .assertThat (targetPath ).hasContent (Files .readString (resultPath ));
57- } catch (IOException e ) {
58- throw new IllegalStateException (e );
59- }
60- });
61- softly .assertAll ();
62- }
41+ @ ParameterizedTest
42+ @ MethodSource ("xmlMergerTestCases" )
43+ void testMerger (Path folder , @ TempDir Path tempDir ) throws Exception {
44+
45+ // arrange
46+ LOG .info ("Testing XML merger for test-case {}" , folder .getFileName ());
47+ Path sourcePath = folder .resolve (SOURCE_XML );
48+ Path targetPath = tempDir .resolve (TARGET_XML );
49+ Path resultPath = folder .resolve (RESULT_XML );
50+ Files .copy (folder .resolve (TARGET_XML ), targetPath , REPLACE_EXISTING );
51+ // act
52+ this .merger .merge (null , sourcePath , this .context .getVariables (), targetPath );
53+ // assert
54+ XmlAssert .assertThat (targetPath ).and (resultPath .toFile ()).areIdentical ();
55+ }
56+
57+ private static Stream <Path > xmlMergerTestCases () throws IOException {
58+
59+ return Files .list (XML_TEST_RESOURCES ).filter (Files ::isDirectory );
6360 }
6461}
0 commit comments