2323import org .junit .jupiter .api .Disabled ;
2424import org .junit .jupiter .api .Nested ;
2525import org .junit .jupiter .api .Test ;
26+ import org .junit .jupiter .api .io .TempDir ;
2627import org .openrewrite .InMemoryExecutionContext ;
2728import org .openrewrite .Issue ;
2829import org .openrewrite .Parser ;
4344
4445import static org .assertj .core .api .Assertions .assertThat ;
4546
46- @ SuppressWarnings ({"HttpUrlsUsage" , "ConstantConditions" })
47+ @ SuppressWarnings ({"HttpUrlsUsage" , "ConstantConditions" , "OptionalGetWithoutIsPresent" })
4748class MavenSettingsTest {
4849
4950 private final MavenExecutionContextView ctx = MavenExecutionContextView .view (
@@ -373,8 +374,7 @@ void serverTimeouts() {
373374 @ Issue ("https://github.com/openrewrite/rewrite/issues/1688" )
374375 class LocalRepositoryTest {
375376 @ Test
376- void parsesLocalRepositoryPathFromSettingsXml () {
377- var localRepoPath = System .getProperty ("java.io.tmpdir" );
377+ void parsesLocalRepositoryPathFromSettingsXml (@ TempDir Path localRepoPath ) {
378378 ctx .setMavenSettings (MavenSettings .parse (new Parser .Input (Paths .get ("settings.xml" ), () -> new ByteArrayInputStream (
379379 //language=xml
380380 """
@@ -387,12 +387,11 @@ void parsesLocalRepositoryPathFromSettingsXml() {
387387 )), ctx ));
388388 assertThat (ctx .getLocalRepository ().getUri ())
389389 .startsWith ("file://" )
390- .containsSubsequence (Paths . get ( localRepoPath ) .toUri ().toString ().split ("/" ));
390+ .containsSubsequence (localRepoPath .toUri ().toString ().split ("/" ));
391391 }
392392
393393 @ Test
394- void parsesLocalRepositoryUriFromSettingsXml () {
395- var localRepoPath = Paths .get (System .getProperty ("java.io.tmpdir" )).toUri ().toString ();
394+ void parsesLocalRepositoryUriFromSettingsXml (@ TempDir Path localRepoPath ) {
396395 ctx .setMavenSettings (MavenSettings .parse (new Parser .Input (Paths .get ("settings.xml" ), () -> new ByteArrayInputStream (
397396 //language=xml
398397 """
@@ -406,7 +405,7 @@ void parsesLocalRepositoryUriFromSettingsXml() {
406405
407406 assertThat (ctx .getLocalRepository ().getUri ())
408407 .startsWith ("file://" )
409- .containsSubsequence (localRepoPath .split ("/" ));
408+ .containsSubsequence (localRepoPath .toUri (). toString (). split ("/" ));
410409 }
411410
412411 @ Test
@@ -784,20 +783,20 @@ void serverHttpHeaders() {
784783 void canDeserializeSettingsCorrectly () throws IOException {
785784 Xml .Document parsed = (Xml .Document ) XmlParser .builder ().build ().parse ("""
786785 <settings>
787- <servers>
788- <server>
789- <id>maven-snapshots</id>
790- <configuration>
791- <connectTimeout>10000</connectTimeout>
792- <httpHeaders>
793- <property>
794- <name>X-JFrog-Art-Api</name>
795- <value>myApiToken</value>
796- </property>
797- </httpHeaders>
798- </configuration>
799- </server>
800- </servers>
786+ <servers>
787+ <server>
788+ <id>maven-snapshots</id>
789+ <configuration>
790+ <connectTimeout>10000</connectTimeout>
791+ <httpHeaders>
792+ <property>
793+ <name>X-JFrog-Art-Api</name>
794+ <value>myApiToken</value>
795+ </property>
796+ </httpHeaders>
797+ </configuration>
798+ </server>
799+ </servers>
801800 </settings>
802801 """ ).findFirst ().get ();
803802
@@ -817,7 +816,7 @@ void canDeserializeSettingsCorrectly() throws IOException {
817816 .isPresent ()
818817 .get (InstanceOfAssertFactories .type (Xml .Document .class ))
819818 .isNotNull ()
820- .satisfies (serialized -> assertThat (SemanticallyEqual .areEqual (parsed , serialized )).isTrue ());
821- // .satisfies(serialized -> assertThat(serialized.printAll()).isEqualTo(parsed.printAll()));
819+ .satisfies (serialized -> assertThat (SemanticallyEqual .areEqual (parsed , serialized )).isTrue ())
820+ .satisfies (serialized -> assertThat (serialized .printAll (). replace ( " \r " , "" )).isEqualTo (parsed .printAll ()));
822821 }
823822}
0 commit comments