Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Android Studio java gradle migrator null check #125728

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More generally should the code in migrate be surrounded by a try catch?

Expand Up @@ -101,7 +101,7 @@ class AndroidStudioJavaGradleConflictMigration extends ProjectMigrator {
return;
}

if (_androidStudio == null) {
if (_androidStudio == null || _androidStudio!.version == null) {
logger.printTrace(androidStudioNotFound);
return;
} else if (_androidStudio!.version!.major < androidStudioFlamingo.major) {
Expand Down
Expand Up @@ -168,6 +168,24 @@ tasks.register("clean", Delete) {
gradleWrapperToMigrate);
});

testWithoutContext('skipped if android studio version is null', () {
final AndroidStudioJavaGradleConflictMigration migration = AndroidStudioJavaGradleConflictMigration(
bufferLogger,
project: project,
androidStudio: FakeAndroidStudio(version: null),
fileSystem: FakeFileSystem(),
processUtils: FakeProcessUtils(),
platform: FakePlatform(),
os: FakeOperatingSystemUtils(),
androidSdk: FakeAndroidSdk(javaVersion: '17'),
);
gradleWrapperPropertiesFile.writeAsStringSync(gradleWrapperToMigrate);
migration.migrate();
expect(bufferLogger.traceText, contains(androidStudioNotFound));
expect(gradleWrapperPropertiesFile.readAsStringSync(),
gradleWrapperToMigrate);
});

testWithoutContext('skipped if android studio version is less than flamingo', () {
final AndroidStudioJavaGradleConflictMigration migration = AndroidStudioJavaGradleConflictMigration(
bufferLogger,
Expand Down Expand Up @@ -267,14 +285,14 @@ class FakeAndroidProject extends Fake implements AndroidProject {
}

class FakeAndroidStudio extends Fake implements AndroidStudio {
FakeAndroidStudio({required Version version}) {
FakeAndroidStudio({required Version? version}) {
_version = version;
}

late Version _version;
late Version? _version;

@override
Version get version => _version;
Version? get version => _version;
}

class FakeAndroidSdk extends Fake implements AndroidSdk {
Expand Down