Skip to content

Commit

Permalink
Remove our own ImmutableList and use similar built-in classes. (#5484)
Browse files Browse the repository at this point in the history
We don't wish to include guava, however, this approach of implementing
our own version of ImmutableList is going to surprise most developers
who expect ImmutableList to be something else.

---------

Co-authored-by: jrothfeder <rothbutter@google.com>
  • Loading branch information
jrothfeder and jrothfeder authored Oct 30, 2023
1 parent ccc7339 commit 36b6403
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 318 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@
import com.google.firebase.crashlytics.internal.metadata.UserMetadata;
import com.google.firebase.crashlytics.internal.model.CrashlyticsReport;
import com.google.firebase.crashlytics.internal.model.CrashlyticsReport.CustomAttribute;
import com.google.firebase.crashlytics.internal.model.ImmutableList;
import com.google.firebase.crashlytics.internal.persistence.CrashlyticsReportPersistence;
import com.google.firebase.crashlytics.internal.send.DataTransportCrashlyticsReportSender;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -233,8 +231,9 @@ public void testNonFatalEvent_addsSortedKeysToEvent() {
final CustomAttribute customAttribute2 =
CustomAttribute.builder().setKey(testKey2).setValue(testValue2).build();

final ImmutableList<CustomAttribute> expectedCustomAttributes =
ImmutableList.from(customAttribute1, customAttribute2);
final List<CustomAttribute> expectedCustomAttributes = new ArrayList<>();
expectedCustomAttributes.add(customAttribute1);
expectedCustomAttributes.add(customAttribute2);

when(reportMetadata.getCustomKeys()).thenReturn(attributes);
when(reportMetadata.getInternalKeys()).thenReturn(attributes);
Expand Down Expand Up @@ -294,8 +293,9 @@ public void testFatalEvent_addsSortedCustomKeysToEvent() {
final CustomAttribute customAttribute2 =
CustomAttribute.builder().setKey(testKey2).setValue(testValue2).build();

final ImmutableList<CustomAttribute> expectedCustomAttributes =
ImmutableList.from(customAttribute1, customAttribute2);
final List<CustomAttribute> expectedCustomAttributes = new ArrayList<>();
expectedCustomAttributes.add(customAttribute1);
expectedCustomAttributes.add(customAttribute2);

when(reportMetadata.getCustomKeys()).thenReturn(attributes);

Expand Down Expand Up @@ -331,8 +331,9 @@ public void testFatalEvent_addsSortedInternalKeysToEvent() {
final CustomAttribute customAttribute2 =
CustomAttribute.builder().setKey(testKey2).setValue(testValue2).build();

final ImmutableList<CustomAttribute> expectedCustomAttributes =
ImmutableList.from(customAttribute1, customAttribute2);
final List<CustomAttribute> expectedCustomAttributes = new ArrayList<>();
expectedCustomAttributes.add(customAttribute1);
expectedCustomAttributes.add(customAttribute2);

when(reportMetadata.getInternalKeys()).thenReturn(attributes);

Expand Down Expand Up @@ -403,7 +404,8 @@ public void testFinalizeSessionWithNativeEvent_createsCrashlyticsReportWithNativ
String byteBackedSessionName = "byte";
BytesBackedNativeSessionFile byteSession =
new BytesBackedNativeSessionFile(byteBackedSessionName, "not_applicable", testBytes);
reportingCoordinator.finalizeSessionWithNativeEvent("id", Arrays.asList(byteSession), null);
reportingCoordinator.finalizeSessionWithNativeEvent(
"id", Collections.singletonList(byteSession), null);

ArgumentCaptor<CrashlyticsReport.FilesPayload> filesPayload =
ArgumentCaptor.forClass(CrashlyticsReport.FilesPayload.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import com.google.firebase.crashlytics.internal.model.CrashlyticsReport.Session.Event.Application.Execution.Signal;
import com.google.firebase.crashlytics.internal.model.CrashlyticsReport.Session.Event.Application.Execution.Thread.Frame;
import com.google.firebase.crashlytics.internal.model.CrashlyticsReport.Session.User;
import com.google.firebase.crashlytics.internal.model.ImmutableList;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -144,14 +144,6 @@ private static Application makeTestApplication(boolean useDevelopmentPlatform) {
return builder.build();
}

private static ImmutableList<Event> makeTestEvents(int numEvents) {
List<Event> events = new ArrayList<>();
for (int i = 0; i < numEvents; i++) {
events.add(makeTestEvent());
}
return ImmutableList.from(events);
}

private static Event makeTestEvent() {
return Event.builder()
.setType("type")
Expand All @@ -162,7 +154,7 @@ private static Event makeTestEvent() {
.setExecution(
Execution.builder()
.setBinaries(
ImmutableList.from(
Collections.singletonList(
Execution.BinaryImage.builder()
.setBaseAddress(0)
.setName("name")
Expand All @@ -178,7 +170,7 @@ private static Event makeTestEvent() {
.build())
.setSignal(Signal.builder().setCode("0").setName("0").setAddress(0).build())
.setThreads(
ImmutableList.from(
Collections.singletonList(
Session.Event.Application.Execution.Thread.builder()
.setName("name")
.setImportance(4)
Expand Down Expand Up @@ -209,7 +201,7 @@ private static Event makeAnrEvent(boolean withBuildIds) {
.setExecution(
Execution.builder()
.setBinaries(
ImmutableList.from(
Collections.singletonList(
Execution.BinaryImage.builder()
.setBaseAddress(0)
.setName("name")
Expand All @@ -233,44 +225,49 @@ private static Event makeAnrEvent(boolean withBuildIds) {
.build();
}

private static ImmutableList<Frame> makeTestFrames() {
return ImmutableList.from(
private static List<Frame> makeTestFrames() {
ArrayList<Frame> frames = new ArrayList<>();
frames.add(
Frame.builder()
.setPc(0)
.setSymbol("func1")
.setFile("Test.java")
.setOffset(36)
.setImportance(4)
.build(),
.build());
frames.add(
Frame.builder()
.setPc(0)
.setSymbol("func2")
.setFile("Test.java")
.setOffset(5637)
.setImportance(4)
.build(),
.build());
frames.add(
Frame.builder()
.setPc(0)
.setSymbol("func3")
.setFile("Test.java")
.setOffset(22429)
.setImportance(4)
.build(),
.build());
frames.add(
Frame.builder()
.setPc(0)
.setSymbol("func4")
.setFile("Test.java")
.setOffset(751)
.setImportance(4)
.build());
return Collections.unmodifiableList(frames);
}

private static CrashlyticsReport.ApplicationExitInfo makeAppExitInfo(boolean withBuildIds) {
ImmutableList<CrashlyticsReport.ApplicationExitInfo.BuildIdMappingForArch>
List<CrashlyticsReport.ApplicationExitInfo.BuildIdMappingForArch>
buildIdMappingForArchImmutableList = null;
if (withBuildIds) {
buildIdMappingForArchImmutableList =
ImmutableList.from(
Collections.singletonList(
CrashlyticsReport.ApplicationExitInfo.BuildIdMappingForArch.builder()
.setLibraryName("lib.so")
.setArch("x86")
Expand Down
Loading

0 comments on commit 36b6403

Please sign in to comment.