21
21
import java .io .IOException ;
22
22
import java .io .InputStreamReader ;
23
23
import java .io .PrintWriter ;
24
+ import java .util .Collections ;
25
+ import java .util .Map ;
24
26
import java .util .jar .JarEntry ;
25
27
import java .util .jar .JarFile ;
26
28
@@ -76,7 +78,7 @@ void jarIncludesLegalFiles() throws IOException {
76
78
}
77
79
78
80
@ Test
79
- void testRetryIsConfigured () throws IOException {
81
+ void testRetryIsConfiguredOnCI () throws IOException {
80
82
try (PrintWriter out = new PrintWriter (new FileWriter (this .buildFile ))) {
81
83
out .println ("plugins {" );
82
84
out .println (" id 'java'" );
@@ -85,19 +87,44 @@ void testRetryIsConfigured() throws IOException {
85
87
out .println ("description 'Test'" );
86
88
out .println ("task retryConfig {" );
87
89
out .println (" doLast {" );
90
+ out .println (" println \" Retry plugin applied: ${plugins.hasPlugin('org.gradle.test-retry')}\" " );
88
91
out .println (" test.retry {" );
89
92
out .println (" println \" maxRetries: ${maxRetries.get()}\" " );
90
93
out .println (" println \" failOnPassedAfterRetry: ${failOnPassedAfterRetry.get()}\" " );
91
94
out .println (" }" );
92
95
out .println (" }" );
93
96
out .println ("}" );
94
97
}
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" )
96
100
.contains ("failOnPassedAfterRetry: true" );
97
101
}
98
102
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
+
99
121
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 ();
101
128
}
102
129
103
130
}
0 commit comments