summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamiul Islam <samiul@google.com>2023-09-21 13:48:30 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2023-09-21 13:48:30 +0000
commita760f47a2e108e10af84fb5b68c20d03024d2260 (patch)
tree66cccb23dbddca0c0987e1164de6c920af65e92a
parent92c17613ac482aeb9d51b7651b7cb5150725baf7 (diff)
parente2e1b3e3122aaca84dfed293d5f6b22a40946692 (diff)
downloadAdServices-a760f47a2e108e10af84fb5b68c20d03024d2260.tar.gz
Merge "Execute ListenableFuture in the test to verify they throw ISE" into udc-mainline-prod
-rw-r--r--adservices/framework/java/android/adservices/adselection/AdSelectionManager.java6
-rw-r--r--adservices/tests/cts/src/android/adservices/cts/AdSelectionTest.java8
-rw-r--r--adservices/tests/cts/src/android/adservices/cts/CustomAudienceTest.java8
3 files changed, 15 insertions, 7 deletions
diff --git a/adservices/framework/java/android/adservices/adselection/AdSelectionManager.java b/adservices/framework/java/android/adservices/adselection/AdSelectionManager.java
index 2de51c35b1..627a912609 100644
--- a/adservices/framework/java/android/adservices/adselection/AdSelectionManager.java
+++ b/adservices/framework/java/android/adservices/adselection/AdSelectionManager.java
@@ -179,11 +179,7 @@ public class AdSelectionManager {
@NonNull
AdSelectionService doGetService() {
- AdSelectionService service = mServiceBinder.getService();
- if (service == null) {
- throw new IllegalStateException("ad selection service is not available.");
- }
- return service;
+ return mServiceBinder.getService();
}
/**
diff --git a/adservices/tests/cts/src/android/adservices/cts/AdSelectionTest.java b/adservices/tests/cts/src/android/adservices/cts/AdSelectionTest.java
index 7df7c1905c..ffaea633f3 100644
--- a/adservices/tests/cts/src/android/adservices/cts/AdSelectionTest.java
+++ b/adservices/tests/cts/src/android/adservices/cts/AdSelectionTest.java
@@ -16,6 +16,8 @@
package android.adservices.cts;
+import static com.google.common.truth.Truth.assertThat;
+
import static org.junit.Assert.assertThrows;
import android.adservices.adselection.AdSelectionConfig;
@@ -37,6 +39,7 @@ import com.google.common.collect.ImmutableMap;
import org.junit.Rule;
import org.junit.Test;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
@@ -80,6 +83,9 @@ public final class AdSelectionTest {
.setTrustedScoringSignalsUri(Uri.parse("http://example.com"))
.build();
- assertThrows(IllegalStateException.class, () -> client.selectAds(config));
+ Exception exception =
+ assertThrows(ExecutionException.class, () -> client.selectAds(config).get());
+ assertThat(exception).hasCauseThat().isInstanceOf(IllegalStateException.class);
+ assertThat(exception).hasMessageThat().contains("Unable to find the AdSelection service");
}
}
diff --git a/adservices/tests/cts/src/android/adservices/cts/CustomAudienceTest.java b/adservices/tests/cts/src/android/adservices/cts/CustomAudienceTest.java
index 8ffdf00610..c6c87733b5 100644
--- a/adservices/tests/cts/src/android/adservices/cts/CustomAudienceTest.java
+++ b/adservices/tests/cts/src/android/adservices/cts/CustomAudienceTest.java
@@ -50,6 +50,7 @@ import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
@@ -298,6 +299,11 @@ public final class CustomAudienceTest {
.setExpirationTime(Instant.now().plus(5, ChronoUnit.DAYS))
.build();
- assertThrows(IllegalStateException.class, () -> client.joinCustomAudience(customAudience));
+ Exception exception =
+ assertThrows(
+ ExecutionException.class,
+ () -> client.joinCustomAudience(customAudience).get());
+ assertThat(exception).hasCauseThat().isInstanceOf(IllegalStateException.class);
+ assertThat(exception).hasMessageThat().contains("service is not available");
}
}