Add getPackageName functionality to ShadowVoiceInteractor
PiperOrigin-RevId: 480463812
diff --git a/robolectric/src/test/java/org/robolectric/shadows/ShadowVoiceInteractorTest.java b/robolectric/src/test/java/org/robolectric/shadows/ShadowVoiceInteractorTest.java
index 793f084..7b4daae 100644
--- a/robolectric/src/test/java/org/robolectric/shadows/ShadowVoiceInteractorTest.java
+++ b/robolectric/src/test/java/org/robolectric/shadows/ShadowVoiceInteractorTest.java
@@ -1,6 +1,6 @@
package org.robolectric.shadows;
-import static android.os.Build.VERSION_CODES.Q;
+import static android.os.Build.VERSION_CODES.TIRAMISU;
import static com.google.common.truth.ExpectFailure.expectFailure;
import static com.google.common.truth.Truth.assertThat;
import static org.robolectric.Robolectric.buildActivity;
@@ -24,7 +24,7 @@
/** Tests for {@link ShadowVoiceInteractor}. */
@RunWith(AndroidJUnit4.class)
-@Config(sdk = Q)
+@Config(sdk = TIRAMISU)
public final class ShadowVoiceInteractorTest {
private static final String PROMPT_MESSAGE_1 = "Message_1";
@@ -124,6 +124,19 @@
assertThat(testActivity.getVoiceInteractor().submitRequest(confirmationRequest)).isTrue();
}
+ @Test
+ public void getPackageName_returnsDefaultPackageName() {
+ assertThat(testActivity.getVoiceInteractor().getPackageName())
+ .isEqualTo(shadowVoiceInteractor.getPackageName());
+ }
+
+ @Test
+ public void getPackageName_returnsModifiedPackageName() {
+ shadowVoiceInteractor.setPackageName("random_voice_interactor");
+ assertThat(testActivity.getVoiceInteractor().getPackageName())
+ .isEqualTo("random_voice_interactor");
+ }
+
private void assertValues(List<String> promptMessage) {
assertThat(shadowVoiceInteractor.getVoiceInteractions().size()).isEqualTo(promptMessage.size());
assertThat(shadowVoiceInteractor.getVoiceInteractions()).isEqualTo(promptMessage);
diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowVoiceInteractor.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowVoiceInteractor.java
index 77d5e86..79bc05d 100644
--- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowVoiceInteractor.java
+++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowVoiceInteractor.java
@@ -2,6 +2,7 @@
import static android.os.Build.VERSION_CODES.M;
import static android.os.Build.VERSION_CODES.Q;
+import static android.os.Build.VERSION_CODES.TIRAMISU;
import static org.robolectric.util.reflector.Reflector.reflector;
import android.app.VoiceInteractor;
@@ -25,6 +26,16 @@
private int directActionsInvalidationCount = 0;
private final List<String> voiceInteractions = new CopyOnWriteArrayList<>();
+ public static String assistantPackageName = "test_package";
+
+ @Implementation(minSdk = TIRAMISU)
+ protected String getPackageName() {
+ return assistantPackageName;
+ }
+
+ public void setPackageName(String packageName) {
+ assistantPackageName = packageName;
+ }
@Implementation(minSdk = Q)
protected void notifyDirectActionsChanged() {