Skip to content

Commit

Permalink
chore: review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind committed May 5, 2022
1 parent 44ddef9 commit 42c3ddf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,20 +246,13 @@ static void applyMetadata(
readString(metadata, logger, PROGUARD_UUID, options.getProguardUuid()));

SdkVersion sdkInfo = options.getSdkVersion();
if (sdkInfo != null) {
final String sdkName = readString(metadata, logger, SDK_NAME, sdkInfo.getName());
if (sdkName != null) {
sdkInfo.setName(sdkName);
}
final String sdkVersion = readString(metadata, logger, SDK_VERSION, sdkInfo.getVersion());
if (sdkVersion != null) {
sdkInfo.setVersion(sdkVersion);
}
options.setSdkVersion(sdkInfo);
} else {
// Should always be set by the Options constructor but let's error out if that changes.
Objects.requireNonNull(sdkInfo, "Property options.sdkVersion must not be null.");
if (sdkInfo == null) {
// Is already set by the Options constructor, let's use an empty default otherwise.
sdkInfo = new SdkVersion("", "");
}
sdkInfo.setName(readStringNotNull(metadata, logger, SDK_NAME, sdkInfo.getName()));
sdkInfo.setVersion(readStringNotNull(metadata, logger, SDK_VERSION, sdkInfo.getVersion()));
options.setSdkVersion(sdkInfo);
}

options
Expand Down Expand Up @@ -293,6 +286,16 @@ private static boolean readBool(
return value;
}

private static @NotNull String readStringNotNull(
final @NotNull Bundle metadata,
final @NotNull ILogger logger,
final @NotNull String key,
final @NotNull String defaultValue) {
final String value = metadata.getString(key, defaultValue);
logger.log(SentryLevel.DEBUG, "%s read: %s", key, value);
return value;
}

private static @Nullable List<String> readList(
final @NotNull Bundle metadata, final @NotNull ILogger logger, final @NotNull String key) {
final String value = metadata.getString(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,21 +563,6 @@ class ManifestMetadataReaderTest {
assertEquals(expectedValue, fixture.options.sdkVersion?.name)
}

@Test
fun `applyMetadata does not override SDK name from options`() {
// Arrange
val expectedValue = "custom.sdk"
fixture.options.sdkVersion!!.name = expectedValue
val bundle = bundleOf(ManifestMetadataReader.SDK_NAME to "foo")
val context = fixture.getContext(metaData = bundle)

// Act
ManifestMetadataReader.applyMetadata(context, fixture.options)

// Assert
assertEquals(expectedValue, fixture.options.sdkVersion?.name)
}

@Test
fun `applyMetadata reads SDK version from metadata`() {
// Arrange
Expand All @@ -593,21 +578,6 @@ class ManifestMetadataReaderTest {
assertEquals(expectedValue, fixture.options.sdkVersion?.version)
}

@Test
fun `applyMetadata does not override SDK version from options`() {
// Arrange
val expectedValue = "1.2.3-alpha.0"
fixture.options.sdkVersion!!.version = expectedValue
val bundle = bundleOf(ManifestMetadataReader.SDK_VERSION to "foo")
val context = fixture.getContext(metaData = bundle)

// Act
ManifestMetadataReader.applyMetadata(context, fixture.options)

// Assert
assertEquals(expectedValue, fixture.options.sdkVersion?.version)
}

@Test
fun `applyMetadata reads enableScopeSync to options`() {
// Arrange
Expand Down

0 comments on commit 42c3ddf

Please sign in to comment.