Skip to content

Commit 98309d0

Browse files
committed
Make ForcedSender.sendBlocking do nothing, instead of throw, when given a wrong Transport type.
This will make it easier to mock Transport in tests. This method is best-effort anyway, so doing nothing instead of throwing is fine.
1 parent 31ab674 commit 98309d0

File tree

1 file changed

+3
-9
lines changed
  • transport/transport-runtime/src/main/java/com/google/android/datatransport/runtime

1 file changed

+3
-9
lines changed

transport/transport-runtime/src/main/java/com/google/android/datatransport/runtime/ForcedSender.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
package com.google.android.datatransport.runtime;
1616

17-
import android.annotation.SuppressLint;
1817
import androidx.annotation.Discouraged;
1918
import androidx.annotation.WorkerThread;
2019
import com.google.android.datatransport.Priority;
@@ -26,16 +25,11 @@
2625
public final class ForcedSender {
2726
@WorkerThread
2827
public static void sendBlocking(Transport<?> transport, Priority priority) {
29-
@SuppressLint("DiscouragedApi")
30-
TransportContext context = getTransportContextOrThrow(transport).withPriority(priority);
31-
TransportRuntime.getInstance().getUploader().logAndUpdateState(context, 1);
32-
}
33-
34-
private static TransportContext getTransportContextOrThrow(Transport<?> transport) {
3528
if (transport instanceof TransportImpl) {
36-
return ((TransportImpl<?>) transport).getTransportContext();
29+
TransportContext context =
30+
((TransportImpl<?>) transport).getTransportContext().withPriority(priority);
31+
TransportRuntime.getInstance().getUploader().logAndUpdateState(context, 1);
3732
}
38-
throw new IllegalArgumentException("Expected instance of TransportImpl.");
3933
}
4034

4135
private ForcedSender() {}

0 commit comments

Comments
 (0)