2121import java .io .IOException ;
2222import java .io .InputStreamReader ;
2323import java .io .PrintWriter ;
24+ import java .util .Collections ;
25+ import java .util .Map ;
2426import java .util .jar .JarEntry ;
2527import java .util .jar .JarFile ;
2628
@@ -76,7 +78,7 @@ void jarIncludesLegalFiles() throws IOException {
7678 }
7779
7880 @ Test
79- void testRetryIsConfigured () throws IOException {
81+ void testRetryIsConfiguredOnCI () throws IOException {
8082 try (PrintWriter out = new PrintWriter (new FileWriter (this .buildFile ))) {
8183 out .println ("plugins {" );
8284 out .println (" id 'java'" );
@@ -85,19 +87,44 @@ void testRetryIsConfigured() throws IOException {
8587 out .println ("description 'Test'" );
8688 out .println ("task retryConfig {" );
8789 out .println (" doLast {" );
90+ out .println (" println \" Retry plugin applied: ${plugins.hasPlugin('org.gradle.test-retry')}\" " );
8891 out .println (" test.retry {" );
8992 out .println (" println \" maxRetries: ${maxRetries.get()}\" " );
9093 out .println (" println \" failOnPassedAfterRetry: ${failOnPassedAfterRetry.get()}\" " );
9194 out .println (" }" );
9295 out .println (" }" );
9396 out .println ("}" );
9497 }
95- assertThat (runGradle ("retryConfig" , "--stacktrace" ).getOutput ()).contains ("maxRetries: 3" )
98+ assertThat (runGradle (Collections .singletonMap ("CI" , "true" ), "retryConfig" , "--stacktrace" ).getOutput ())
99+ .contains ("Retry plugin applied: true" ).contains ("maxRetries: 3" )
96100 .contains ("failOnPassedAfterRetry: true" );
97101 }
98102
103+ @ Test
104+ void testRetryIsNotConfiguredLocally () throws IOException {
105+ try (PrintWriter out = new PrintWriter (new FileWriter (this .buildFile ))) {
106+ out .println ("plugins {" );
107+ out .println (" id 'java'" );
108+ out .println (" id 'org.springframework.boot.conventions'" );
109+ out .println ("}" );
110+ out .println ("description 'Test'" );
111+ out .println ("task retryConfig {" );
112+ out .println (" doLast {" );
113+ out .println (" println \" Retry plugin applied: ${plugins.hasPlugin('org.gradle.test-retry')}\" " );
114+ out .println (" }" );
115+ out .println ("}" );
116+ }
117+ assertThat (runGradle (Collections .singletonMap ("CI" , "local" ), "retryConfig" , "--stacktrace" ).getOutput ())
118+ .contains ("Retry plugin applied: false" );
119+ }
120+
99121 private BuildResult runGradle (String ... args ) {
100- return GradleRunner .create ().withProjectDir (this .projectDir ).withArguments (args ).withPluginClasspath ().build ();
122+ return runGradle (Collections .emptyMap (), args );
123+ }
124+
125+ private BuildResult runGradle (Map <String , String > environment , String ... args ) {
126+ return GradleRunner .create ().withProjectDir (this .projectDir ).withEnvironment (environment ).withArguments (args )
127+ .withPluginClasspath ().build ();
101128 }
102129
103130}
0 commit comments