aboutsummaryrefslogtreecommitdiff
path: root/tests/carservice_unit_test/src
diff options
context:
space:
mode:
Diffstat (limited to 'tests/carservice_unit_test/src')
-rw-r--r--tests/carservice_unit_test/src/com/android/car/telemetry/publisher/ConnectivityPublisherTest.java27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/carservice_unit_test/src/com/android/car/telemetry/publisher/ConnectivityPublisherTest.java b/tests/carservice_unit_test/src/com/android/car/telemetry/publisher/ConnectivityPublisherTest.java
index 93ebc907cb..e10dd1a876 100644
--- a/tests/carservice_unit_test/src/com/android/car/telemetry/publisher/ConnectivityPublisherTest.java
+++ b/tests/carservice_unit_test/src/com/android/car/telemetry/publisher/ConnectivityPublisherTest.java
@@ -527,6 +527,21 @@ public class ConnectivityPublisherTest {
.asList().containsExactly(1000L);
}
+ @Test
+ public void testWhenQueryThrowsNullPointerExceptionIsCaught() {
+ mFakeManager.setSimulateFailedQuery(true);
+ mSessionControllerCallbackArgumentCaptor.getValue().onSessionStateChanged(
+ SESSION_ANNOTATION_BEGIN_1);
+
+ // querySummary gets called for each QueryParam combination, but throws
+ // NullPointerException each time, which is caught
+ assertThat(mFakeManager.getMethodCallCount("querySummary"))
+ .isEqualTo(BASELINE_PULL_COUNT);
+ // queryTaggedSummary not reached because of previous NullPointerException in querySummary
+ assertThat(mFakeManager.getMethodCallCount("queryTaggedSummary"))
+ .isEqualTo(0);
+ }
+
private static class FakeDataSubscriber extends DataSubscriber {
private final ArrayList<PushedData> mPushedData = new ArrayList<>();
@@ -569,6 +584,8 @@ public class ConnectivityPublisherTest {
private final ArrayList<FakeNetworkStats.CustomBucket> mBuckets = new ArrayList<>();
private final HashMap<String, Integer> mMethodCallCount = new HashMap<>();
+ private boolean mSimulateFailedQuery = false;
+
private FakeNetworkStatsManager() {
super(/* networkStatsManager= */ null);
}
@@ -623,10 +640,17 @@ public class ConnectivityPublisherTest {
return mMethodCallCount.getOrDefault(name, 0);
}
+ public void setSimulateFailedQuery(boolean simulateFailedQuery) {
+ mSimulateFailedQuery = simulateFailedQuery;
+ }
+
@Override
@NonNull
public NetworkStatsWrapper querySummary(NetworkTemplate template, long start, long end) {
increaseMethodCall("querySummary", 1);
+ if (mSimulateFailedQuery) {
+ throw new NullPointerException();
+ }
return commonQuerySummary(false, template, start, end);
}
@@ -635,6 +659,9 @@ public class ConnectivityPublisherTest {
public NetworkStatsWrapper queryTaggedSummary(
NetworkTemplate template, long start, long end) {
increaseMethodCall("queryTaggedSummary", 1);
+ if (mSimulateFailedQuery) {
+ throw new NullPointerException();
+ }
return commonQuerySummary(true, template, start, end);
}