@@ -117,6 +117,68 @@ void main() {
117117 FileSystem : () => memoryFileSystem,
118118 ProcessManager : () => FakeProcessManager .any (),
119119 });
120+
121+ testUsingContext ('injects the wrapper and the Gradle version is derivated from the AGP version' , () {
122+ const Map <String , String > testCases = < String , String > {
123+ // AGP version : Gradle version
124+ '1.0.0' : '2.3' ,
125+ '3.3.1' : '4.10.2' ,
126+ '3.0.0' : '4.1' ,
127+ '3.0.5' : '4.1' ,
128+ '3.0.9' : '4.1' ,
129+ '3.1.0' : '4.4' ,
130+ '3.2.0' : '4.6' ,
131+ '3.3.0' : '4.10.2' ,
132+ '3.4.0' : '5.6.2' ,
133+ '3.5.0' : '5.6.2' ,
134+ '4.0.0' : '6.7' ,
135+ '4.0.5' : '6.7' ,
136+ '4.1.0' : '6.7' ,
137+ };
138+
139+ for (final MapEntry <String , String > entry in testCases.entries) {
140+ final Directory sampleAppAndroid = globals.fs.systemTempDirectory.createTempSync ('android' );
141+ sampleAppAndroid
142+ .childFile ('build.gradle' )
143+ .writeAsStringSync ('''
144+ buildscript {
145+ dependencies {
146+ classpath 'com.android.tools.build:gradle:${entry .key }'
147+ }
148+ }
149+ ''' );
150+ gradleUtils.injectGradleWrapperIfNeeded (sampleAppAndroid);
151+
152+ expect (sampleAppAndroid.childFile ('gradlew' ).existsSync (), isTrue);
153+
154+ expect (sampleAppAndroid
155+ .childDirectory ('gradle' )
156+ .childDirectory ('wrapper' )
157+ .childFile ('gradle-wrapper.jar' )
158+ .existsSync (), isTrue);
159+
160+ expect (sampleAppAndroid
161+ .childDirectory ('gradle' )
162+ .childDirectory ('wrapper' )
163+ .childFile ('gradle-wrapper.properties' )
164+ .existsSync (), isTrue);
165+
166+ expect (sampleAppAndroid
167+ .childDirectory ('gradle' )
168+ .childDirectory ('wrapper' )
169+ .childFile ('gradle-wrapper.properties' )
170+ .readAsStringSync (),
171+ 'distributionBase=GRADLE_USER_HOME\n '
172+ 'distributionPath=wrapper/dists\n '
173+ 'zipStoreBase=GRADLE_USER_HOME\n '
174+ 'zipStorePath=wrapper/dists\n '
175+ 'distributionUrl=https\\ ://services.gradle.org/distributions/gradle-${entry .value }-all.zip\n ' );
176+ }
177+ }, overrides: < Type , Generator > {
178+ Cache : () => Cache .test (rootOverride: tempDir, fileSystem: memoryFileSystem),
179+ FileSystem : () => memoryFileSystem,
180+ ProcessManager : () => FakeProcessManager .any (),
181+ });
120182 });
121183
122184 group ('GradleUtils.getExecutable' , () {
0 commit comments