[go: nahoru, domu]

Add CarText.toCharSequence and deprecate the methods it replaces.

getText and getSpans in CarText are deprecated since they can be replaced by toCharSequence.

Change-Id: I7bf647a8381bf31f52cd289b500bc6c817f60ac7
Bug: 177961436
Relnote: n/a
Test: ./gradlew :car:app:app:test
diff --git a/car/app/app/api/current.txt b/car/app/app/api/current.txt
index 4e393e3..e5c05ca0 100644
--- a/car/app/app/api/current.txt
+++ b/car/app/app/api/current.txt
@@ -281,10 +281,11 @@
 
   public class CarText {
     method public static androidx.car.app.model.CarText create(CharSequence);
-    method public java.util.List<androidx.car.app.model.CarText.SpanWrapper!> getSpans();
-    method public String getText();
+    method @Deprecated public java.util.List<androidx.car.app.model.CarText.SpanWrapper!> getSpans();
+    method @Deprecated public String getText();
     method public boolean isEmpty();
     method public static boolean isNullOrEmpty(androidx.car.app.model.CarText?);
+    method public CharSequence toCharSequence();
     method public static String? toShortString(androidx.car.app.model.CarText?);
   }
 
diff --git a/car/app/app/api/public_plus_experimental_current.txt b/car/app/app/api/public_plus_experimental_current.txt
index 4e393e3..e5c05ca0 100644
--- a/car/app/app/api/public_plus_experimental_current.txt
+++ b/car/app/app/api/public_plus_experimental_current.txt
@@ -281,10 +281,11 @@
 
   public class CarText {
     method public static androidx.car.app.model.CarText create(CharSequence);
-    method public java.util.List<androidx.car.app.model.CarText.SpanWrapper!> getSpans();
-    method public String getText();
+    method @Deprecated public java.util.List<androidx.car.app.model.CarText.SpanWrapper!> getSpans();
+    method @Deprecated public String getText();
     method public boolean isEmpty();
     method public static boolean isNullOrEmpty(androidx.car.app.model.CarText?);
+    method public CharSequence toCharSequence();
     method public static String? toShortString(androidx.car.app.model.CarText?);
   }
 
diff --git a/car/app/app/api/restricted_current.txt b/car/app/app/api/restricted_current.txt
index 4e393e3..e5c05ca0 100644
--- a/car/app/app/api/restricted_current.txt
+++ b/car/app/app/api/restricted_current.txt
@@ -281,10 +281,11 @@
 
   public class CarText {
     method public static androidx.car.app.model.CarText create(CharSequence);
-    method public java.util.List<androidx.car.app.model.CarText.SpanWrapper!> getSpans();
-    method public String getText();
+    method @Deprecated public java.util.List<androidx.car.app.model.CarText.SpanWrapper!> getSpans();
+    method @Deprecated public String getText();
     method public boolean isEmpty();
     method public static boolean isNullOrEmpty(androidx.car.app.model.CarText?);
+    method public CharSequence toCharSequence();
     method public static String? toShortString(androidx.car.app.model.CarText?);
   }
 
diff --git a/car/app/app/src/main/java/androidx/car/app/model/Action.java b/car/app/app/src/main/java/androidx/car/app/model/Action.java
index 35d2146..3d35fe9 100644
--- a/car/app/app/src/main/java/androidx/car/app/model/Action.java
+++ b/car/app/app/src/main/java/androidx/car/app/model/Action.java
@@ -384,7 +384,7 @@
         public Action build() {
             boolean isStandard = isStandardActionType(mType);
             if (!isStandard && mIcon == null && (mTitle == null || TextUtils.isEmpty(
-                    mTitle.getText()))) {
+                    mTitle.toString()))) {
                 throw new IllegalStateException("An action must have either an icon or a title");
             }
 
@@ -395,7 +395,7 @@
                                     + "action");
                 }
 
-                if (mIcon != null || (mTitle != null && !TextUtils.isEmpty(mTitle.getText()))) {
+                if (mIcon != null || (mTitle != null && !TextUtils.isEmpty(mTitle.toString()))) {
                     throw new IllegalStateException(
                             "An icon or title can't be set on the standard back or app-icon "
                                     + "action");
diff --git a/car/app/app/src/main/java/androidx/car/app/model/CarText.java b/car/app/app/src/main/java/androidx/car/app/model/CarText.java
index b9a11af..122e440 100644
--- a/car/app/app/src/main/java/androidx/car/app/model/CarText.java
+++ b/car/app/app/src/main/java/androidx/car/app/model/CarText.java
@@ -16,6 +16,7 @@
 
 package androidx.car.app.model;
 
+import android.text.SpannableString;
 import android.text.Spanned;
 
 import androidx.annotation.Keep;
@@ -57,7 +58,12 @@
         return new CarText(text);
     }
 
+    /**
+     * @deprecated use {@link #toString()}
+     */
     @NonNull
+    @Deprecated
+    // TODO(b/177961439): remove once host is updated to use toString.
     public String getText() {
         return mText;
     }
@@ -66,8 +72,13 @@
         return mText.isEmpty();
     }
 
-    /** Returns the optional list of spans attached to the text. */
+    /**
+     * Returns the optional list of spans attached to the text.
+     * @deprecated use {@link #toCharSequence}
+     */
+    // TODO(b/177961277): remove once host is updated to use toCharSequence.
     @NonNull
+    @Deprecated
     public List<SpanWrapper> getSpans() {
         return mSpans;
     }
@@ -75,7 +86,28 @@
     @NonNull
     @Override
     public String toString() {
-        return getText();
+        return mText;
+    }
+
+    /**
+     * Returns the {@link CharSequence} corresponding to this text.
+     *
+     * <p>Spans that are not of type {@link CarSpan} that were passed when creating the
+     * {@link CarText} instance will not be present in the returned {@link CharSequence}.
+     *
+     * @see CarText#create(CharSequence)
+     */
+    @NonNull
+    public CharSequence toCharSequence() {
+        SpannableString spannableString = new SpannableString(mText);
+        for (SpanWrapper spanWrapper : mSpans) {
+            spannableString.setSpan(
+                    spanWrapper.getCarSpan(),
+                    spanWrapper.getStart(),
+                    spanWrapper.getEnd(),
+                    spanWrapper.getFlags());
+        }
+        return spannableString;
     }
 
     /**
@@ -127,6 +159,7 @@
     /**
      * Wraps a span to send it to the host.
      */
+    // TODO(b/178026067): Make SpanWrapper private.
     public static class SpanWrapper {
         @Keep
         private final int mStart;
diff --git a/car/app/app/src/main/java/androidx/car/app/model/ListTemplate.java b/car/app/app/src/main/java/androidx/car/app/model/ListTemplate.java
index 21d2dd2..a936e38 100644
--- a/car/app/app/src/main/java/androidx/car/app/model/ListTemplate.java
+++ b/car/app/app/src/main/java/androidx/car/app/model/ListTemplate.java
@@ -298,7 +298,7 @@
          */
         @NonNull
         public Builder addSectionedList(@NonNull SectionedItemList list) {
-            if (requireNonNull(list).getHeader().getText().length() == 0) {
+            if (requireNonNull(list).getHeader().toString().length() == 0) {
                 throw new IllegalArgumentException("Header cannot be empty");
             }
 
diff --git a/car/app/app/src/main/java/androidx/car/app/model/ModelUtils.java b/car/app/app/src/main/java/androidx/car/app/model/ModelUtils.java
index 1d790d3..9892f0c 100644
--- a/car/app/app/src/main/java/androidx/car/app/model/ModelUtils.java
+++ b/car/app/app/src/main/java/androidx/car/app/model/ModelUtils.java
@@ -18,13 +18,11 @@
 
 import static androidx.annotation.RestrictTo.Scope.LIBRARY;
 
-import static java.util.Objects.requireNonNull;
-
+import android.text.Spanned;
 import android.text.style.CharacterStyle;
 
 import androidx.annotation.NonNull;
 import androidx.annotation.RestrictTo;
-import androidx.car.app.model.CarText.SpanWrapper;
 
 import java.util.List;
 
@@ -163,15 +161,14 @@
         if (carText.isEmpty()) {
             return false;
         }
-        String text = requireNonNull(carText.getText());
-
-        List<SpanWrapper> spans = carText.getSpans();
-        for (int i = 0; i < spans.size(); i++) {
-            SpanWrapper wrapper = spans.get(i);
-            if (spanType.isInstance(wrapper.getCarSpan())
-                    && wrapper.getStart() >= 0
-                    && wrapper.getStart() != wrapper.getEnd()
-                    && wrapper.getStart() < text.length()) {
+        Spanned spanned = (Spanned) carText.toCharSequence();
+        for (Object span : spanned.getSpans(0, spanned.length(), Object.class)) {
+            int start = spanned.getSpanStart(span);
+            int end = spanned.getSpanEnd(span);
+            if (spanType.isInstance(span)
+                    && start >= 0
+                    && start != end
+                    && start < spanned.length()) {
                 return true;
             }
         }
diff --git a/car/app/app/src/test/java/androidx/car/app/model/CarTextTest.java b/car/app/app/src/test/java/androidx/car/app/model/CarTextTest.java
new file mode 100644
index 0000000..37092cb
--- /dev/null
+++ b/car/app/app/src/test/java/androidx/car/app/model/CarTextTest.java
@@ -0,0 +1,160 @@
+/*
+ * Copyright 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package androidx.car.app.model;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.text.SpannableString;
+import android.text.Spanned;
+import android.text.style.ForegroundColorSpan;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.internal.DoNotInstrument;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/** Tests for {@link CarText}. */
+@RunWith(RobolectricTestRunner.class)
+@DoNotInstrument
+public class CarTextTest {
+    @Test
+    public void toCharSequence_noSpans() {
+        String text = "";
+        CarText carText = CarText.create(text);
+        assertThat(carText.toCharSequence().toString()).isEqualTo(text);
+
+        text = "Test string";
+        carText = CarText.create(text);
+        assertThat(carText.toCharSequence().toString()).isEqualTo(text);
+    }
+
+    @Test
+    public void toCharSequence_withSpans() {
+        String text = "Part of this text is red";
+        SpannableString spannable = new SpannableString(text);
+
+        // Add a foreground car color span.
+        ForegroundCarColorSpan foregroundCarColorSpan = ForegroundCarColorSpan.create(CarColor.RED);
+        spannable.setSpan(foregroundCarColorSpan, 0, 5, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+
+        // Add a duration span
+        DurationSpan durationSpan = DurationSpan.create(46);
+        spannable.setSpan(durationSpan, 10, 12, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+
+        // Add a span that will be filtered out.
+        ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(0xffff00);
+        spannable.setSpan(foregroundColorSpan, 2, 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+
+        // Create the car text from the spannable and verify it.
+        CarText carText = CarText.create(spannable);
+
+        CharSequence charSequence = carText.toCharSequence();
+        assertThat(charSequence.toString()).isEqualTo(text);
+
+        List<CarSpanInfo> carSpans = getCarSpans(charSequence);
+        assertThat(carSpans).hasSize(2);
+
+        CarSpanInfo carSpan = carSpans.get(0);
+        assertThat(carSpan.mCarSpan instanceof ForegroundCarColorSpan).isTrue();
+        assertThat(carSpan.mCarSpan).isEqualTo(foregroundCarColorSpan);
+        assertThat(carSpan.mStart).isEqualTo(0);
+        assertThat(carSpan.mEnd).isEqualTo(5);
+        assertThat(carSpan.mFlags).isEqualTo(Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+
+        carSpan = carSpans.get(1);
+        assertThat(carSpan.mCarSpan instanceof DurationSpan).isTrue();
+        assertThat(carSpan.mCarSpan).isEqualTo(durationSpan);
+        assertThat(carSpan.mStart).isEqualTo(10);
+        assertThat(carSpan.mEnd).isEqualTo(12);
+        assertThat(carSpan.mFlags).isEqualTo(Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+    }
+
+    @Test
+    public void equals_and_hashCode() {
+        String text = "Part of this text is red";
+        SpannableString spannable = new SpannableString(text);
+        ForegroundCarColorSpan foregroundCarColorSpan = ForegroundCarColorSpan.create(CarColor.RED);
+        spannable.setSpan(foregroundCarColorSpan, 0, 5, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+        DurationSpan durationSpan = DurationSpan.create(46);
+        spannable.setSpan(durationSpan, 10, 12, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+        CarText carText1 = CarText.create(spannable);
+
+        text = "Part of this text is red";
+        spannable = new SpannableString(text);
+        foregroundCarColorSpan = ForegroundCarColorSpan.create(CarColor.RED);
+        spannable.setSpan(foregroundCarColorSpan, 0, 5, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+        durationSpan = DurationSpan.create(46);
+        spannable.setSpan(durationSpan, 10, 12, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+        CarText carText2 = CarText.create(spannable);
+
+        // Create a text where the string is different
+        text = "Part of this text is blue";
+        spannable = new SpannableString(text);
+        foregroundCarColorSpan = ForegroundCarColorSpan.create(CarColor.RED);
+        spannable.setSpan(foregroundCarColorSpan, 0, 5, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+        durationSpan = DurationSpan.create(46);
+        spannable.setSpan(durationSpan, 10, 12, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+        CarText carText3 = CarText.create(spannable);
+
+        // Create a text where the spans change
+        text = "Part of this text is red";
+        spannable = new SpannableString(text);
+        foregroundCarColorSpan = ForegroundCarColorSpan.create(CarColor.RED);
+        spannable.setSpan(foregroundCarColorSpan, 0, 5, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+        CarText carText4 = CarText.create(spannable);
+
+        assertThat(carText1).isEqualTo(carText2);
+        assertThat(carText1.hashCode()).isEqualTo(carText2.hashCode());
+
+        assertThat(carText1).isEqualTo(carText1);
+        assertThat(carText1.hashCode()).isEqualTo(carText1.hashCode());
+
+        assertThat(carText1).isNotEqualTo(carText3);
+        assertThat(carText1.hashCode()).isNotEqualTo(carText3.hashCode());
+
+        assertThat(carText2).isNotEqualTo(carText4);
+        assertThat(carText2.hashCode()).isNotEqualTo(carText4.hashCode());
+
+        assertThat(carText3).isNotEqualTo(carText4);
+        assertThat(carText3.hashCode()).isNotEqualTo(carText4.hashCode());
+    }
+
+    private static List<CarSpanInfo> getCarSpans(CharSequence charSequence) {
+        Spanned spanned = (Spanned) charSequence;
+        List<CarSpanInfo> carSpans = new ArrayList<>();
+        for (Object span : spanned.getSpans(0, charSequence.length(), Object.class)) {
+            assertThat(span instanceof CarSpan).isTrue();
+            CarSpanInfo info = new CarSpanInfo();
+            info.mCarSpan = (CarSpan) span;
+            info.mStart = spanned.getSpanStart(span);
+            info.mEnd = spanned.getSpanEnd(span);
+            info.mFlags = spanned.getSpanFlags(span);
+            carSpans.add(info);
+        }
+        return carSpans;
+    }
+
+    private static class CarSpanInfo {
+        CarSpan mCarSpan;
+        int mStart;
+        int mEnd;
+        int mFlags;
+    }
+}
diff --git a/car/app/app/src/test/java/androidx/car/app/model/ListTemplateTest.java b/car/app/app/src/test/java/androidx/car/app/model/ListTemplateTest.java
index e5879bc..0a5269d 100644
--- a/car/app/app/src/test/java/androidx/car/app/model/ListTemplateTest.java
+++ b/car/app/app/src/test/java/androidx/car/app/model/ListTemplateTest.java
@@ -141,9 +141,9 @@
         assertThat(template.getSingleList()).isNull();
         assertThat(template.getSectionedLists()).hasSize(2);
         assertThat(template.getSectionedLists().get(0).getItemList()).isEqualTo(list1);
-        assertThat(template.getSectionedLists().get(0).getHeader().getText()).isEqualTo("header1");
+        assertThat(template.getSectionedLists().get(0).getHeader().toString()).isEqualTo("header1");
         assertThat(template.getSectionedLists().get(1).getItemList()).isEqualTo(list2);
-        assertThat(template.getSectionedLists().get(1).getHeader().getText()).isEqualTo("header2");
+        assertThat(template.getSectionedLists().get(1).getHeader().toString()).isEqualTo("header2");
     }
 
     @Test
diff --git a/car/app/app/src/test/java/androidx/car/app/model/MessageTemplateTest.java b/car/app/app/src/test/java/androidx/car/app/model/MessageTemplateTest.java
index 8000014..0933f5d 100644
--- a/car/app/app/src/test/java/androidx/car/app/model/MessageTemplateTest.java
+++ b/car/app/app/src/test/java/androidx/car/app/model/MessageTemplateTest.java
@@ -80,7 +80,7 @@
     public void createDefault_valuesAreNull() {
         MessageTemplate template = new MessageTemplate.Builder(mMessage).setTitle(mTitle).build();
         assertThat(template.getMessage().toString()).isEqualTo(mMessage);
-        assertThat(template.getTitle().getText()).isEqualTo("header");
+        assertThat(template.getTitle().toString()).isEqualTo("header");
         assertThat(template.getIcon()).isNull();
         assertThat(template.getHeaderAction()).isNull();
         assertThat(template.getActionList()).isEmpty();
diff --git a/car/app/app/src/test/java/androidx/car/app/model/PlaceListMapTemplateTest.java b/car/app/app/src/test/java/androidx/car/app/model/PlaceListMapTemplateTest.java
index bbc83ca..7a1b3a9 100644
--- a/car/app/app/src/test/java/androidx/car/app/model/PlaceListMapTemplateTest.java
+++ b/car/app/app/src/test/java/androidx/car/app/model/PlaceListMapTemplateTest.java
@@ -264,7 +264,7 @@
                         .setCurrentLocationEnabled(true)
                         .build();
 
-        assertThat(template.getTitle().getText()).isEqualTo(title);
+        assertThat(template.getTitle().toString()).isEqualTo(title);
     }
 
     @Test
diff --git a/car/app/app/src/test/java/androidx/car/app/model/PlaceMarkerTest.java b/car/app/app/src/test/java/androidx/car/app/model/PlaceMarkerTest.java
index 3e9fa90..6ef9234 100644
--- a/car/app/app/src/test/java/androidx/car/app/model/PlaceMarkerTest.java
+++ b/car/app/app/src/test/java/androidx/car/app/model/PlaceMarkerTest.java
@@ -82,7 +82,7 @@
         assertThat(marker1.getIcon()).isEqualTo(icon);
         assertThat(marker1.getIconType()).isEqualTo(PlaceMarker.TYPE_ICON);
         assertThat(marker1.getColor()).isEqualTo(CarColor.SECONDARY);
-        assertThat(marker1.getLabel().getText()).isEqualTo("foo");
+        assertThat(marker1.getLabel().toString()).isEqualTo("foo");
     }
 
     @Test
diff --git a/car/app/app/src/test/java/androidx/car/app/model/RowTest.java b/car/app/app/src/test/java/androidx/car/app/model/RowTest.java
index 5334b51f..9eafc7c 100644
--- a/car/app/app/src/test/java/androidx/car/app/model/RowTest.java
+++ b/car/app/app/src/test/java/androidx/car/app/model/RowTest.java
@@ -41,7 +41,7 @@
     @Test
     public void create_defaultValues() {
         Row row = new Row.Builder().setTitle("Title").build();
-        assertThat(row.getTitle().getText()).isEqualTo("Title");
+        assertThat(row.getTitle().toString()).isEqualTo("Title");
         assertThat(row.getTexts()).isEmpty();
         assertThat(row.getImage()).isNull();
         assertThat(row.getOnClickListener()).isNull();
diff --git a/car/app/app/src/test/java/androidx/car/app/model/SectionedItemListTest.java b/car/app/app/src/test/java/androidx/car/app/model/SectionedItemListTest.java
index 61b7d7d..396bc81 100644
--- a/car/app/app/src/test/java/androidx/car/app/model/SectionedItemListTest.java
+++ b/car/app/app/src/test/java/androidx/car/app/model/SectionedItemListTest.java
@@ -34,7 +34,7 @@
         SectionedItemList sectionList = SectionedItemList.create(list, "header");
 
         assertThat(sectionList.getItemList()).isEqualTo(list);
-        assertThat(sectionList.getHeader().getText()).isEqualTo("header");
+        assertThat(sectionList.getHeader().toString()).isEqualTo("header");
     }
 
     @Test
diff --git a/car/app/app/src/test/java/androidx/car/app/navigation/model/DestinationTest.java b/car/app/app/src/test/java/androidx/car/app/navigation/model/DestinationTest.java
index 52ee4d9..13c50f2 100644
--- a/car/app/app/src/test/java/androidx/car/app/navigation/model/DestinationTest.java
+++ b/car/app/app/src/test/java/androidx/car/app/navigation/model/DestinationTest.java
@@ -44,8 +44,8 @@
         Destination destination = new Destination.Builder().setName(title).setAddress(
                 address).build();
 
-        assertThat(destination.getName().getText()).isEqualTo(title);
-        assertThat(destination.getAddress().getText()).isEqualTo(address);
+        assertThat(destination.getName().toString()).isEqualTo(title);
+        assertThat(destination.getAddress().toString()).isEqualTo(address);
         assertThat(destination.getImage()).isNull();
     }
 
@@ -59,11 +59,11 @@
     @Test
     public void emptyNameOrAddress_allowed() {
         Destination destination = new Destination.Builder().setName("name").setAddress("").build();
-        assertThat(destination.getName().getText()).isEqualTo("name");
-        assertThat(destination.getAddress().getText()).isEmpty();
+        assertThat(destination.getName().toString()).isEqualTo("name");
+        assertThat(destination.getAddress().toString()).isEmpty();
 
         destination = new Destination.Builder().setName(null).setAddress("address").build();
-        assertThat(destination.getAddress().getText()).isEqualTo("address");
+        assertThat(destination.getAddress().toString()).isEqualTo("address");
         assertThat(destination.getName()).isNull();
     }
 
diff --git a/car/app/app/src/test/java/androidx/car/app/navigation/model/MessageInfoTest.java b/car/app/app/src/test/java/androidx/car/app/navigation/model/MessageInfoTest.java
index 82efe55..1bdee55 100644
--- a/car/app/app/src/test/java/androidx/car/app/navigation/model/MessageInfoTest.java
+++ b/car/app/app/src/test/java/androidx/car/app/navigation/model/MessageInfoTest.java
@@ -52,7 +52,7 @@
     @Test
     public void createMinimalInstance() {
         MessageInfo messageInfo = new MessageInfo.Builder("Message").build();
-        assertThat(messageInfo.getTitle().getText()).isEqualTo("Message");
+        assertThat(messageInfo.getTitle().toString()).isEqualTo("Message");
         assertThat(messageInfo.getText()).isNull();
         assertThat(messageInfo.getImage()).isNull();
     }
@@ -63,8 +63,8 @@
         MessageInfo messageInfo =
                 new MessageInfo.Builder("Message").setImage(CarIcon.APP_ICON).setText(
                         "Secondary").build();
-        assertThat(messageInfo.getTitle().getText()).isEqualTo("Message");
-        assertThat(messageInfo.getText().getText()).isEqualTo("Secondary");
+        assertThat(messageInfo.getTitle().toString()).isEqualTo("Message");
+        assertThat(messageInfo.getText().toString()).isEqualTo("Secondary");
         assertThat(messageInfo.getImage()).isEqualTo(CarIcon.APP_ICON);
     }
 
diff --git a/car/app/app/src/test/java/androidx/car/app/navigation/model/PlaceListNavigationTemplateTest.java b/car/app/app/src/test/java/androidx/car/app/navigation/model/PlaceListNavigationTemplateTest.java
index bf66d31..e37a542 100644
--- a/car/app/app/src/test/java/androidx/car/app/navigation/model/PlaceListNavigationTemplateTest.java
+++ b/car/app/app/src/test/java/androidx/car/app/navigation/model/PlaceListNavigationTemplateTest.java
@@ -168,7 +168,7 @@
                         .setItemList(new ItemList.Builder().build())
                         .build();
         assertThat(template.getItemList().getItemList()).isEmpty();
-        assertThat(template.getTitle().getText()).isEqualTo("Title");
+        assertThat(template.getTitle().toString()).isEqualTo("Title");
         assertThat(template.getActionStrip()).isNull();
     }
 
@@ -185,7 +185,7 @@
                         .build();
         assertThat(template.getItemList()).isEqualTo(itemList);
         assertThat(template.getActionStrip()).isEqualTo(actionStrip);
-        assertThat(template.getTitle().getText()).isEqualTo(title);
+        assertThat(template.getTitle().toString()).isEqualTo(title);
     }
 
     @Test
diff --git a/car/app/app/src/test/java/androidx/car/app/navigation/model/RoutePreviewNavigationTemplateTest.java b/car/app/app/src/test/java/androidx/car/app/navigation/model/RoutePreviewNavigationTemplateTest.java
index 7da3e0b..9100ff0 100644
--- a/car/app/app/src/test/java/androidx/car/app/navigation/model/RoutePreviewNavigationTemplateTest.java
+++ b/car/app/app/src/test/java/androidx/car/app/navigation/model/RoutePreviewNavigationTemplateTest.java
@@ -146,7 +146,7 @@
                                 }).build())
                         .build();
         assertThat(template.getItemList()).isEqualTo(itemList);
-        assertThat(template.getTitle().getText()).isEqualTo(title);
+        assertThat(template.getTitle().toString()).isEqualTo(title);
     }
 
     @Test
diff --git a/car/app/app/src/test/java/androidx/car/app/navigation/model/StepTest.java b/car/app/app/src/test/java/androidx/car/app/navigation/model/StepTest.java
index a920cc4..95573c5 100644
--- a/car/app/app/src/test/java/androidx/car/app/navigation/model/StepTest.java
+++ b/car/app/app/src/test/java/androidx/car/app/navigation/model/StepTest.java
@@ -57,8 +57,8 @@
         assertThat(lane).isEqualTo(step.getLanes().get(0));
         assertThat(CarIcon.APP_ICON).isEqualTo(step.getLanesImage());
         assertThat(maneuver).isEqualTo(step.getManeuver());
-        assertThat(cue).isEqualTo(step.getCue().getText());
-        assertThat(road).isEqualTo(step.getRoad().getText());
+        assertThat(cue).isEqualTo(step.getCue().toString());
+        assertThat(road).isEqualTo(step.getRoad().toString());
     }
 
     @Test