Skip to content

Commit

Permalink
Add support for testing InboxStyle notifications.
Browse files Browse the repository at this point in the history
Adding new getTextLines method in the ShadowNotification that allows to get text lines set by the `InboxStyle.addLine()`.

PiperOrigin-RevId: 590002758
  • Loading branch information
romkal authored and Copybara-Service committed Dec 12, 2023
1 parent d023d24 commit 00e219a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Expand Up @@ -247,4 +247,22 @@ public void withBigPictureStyle() {

assertThat(shadowOf(notification).getBigPicture().sameAs(bigPicture)).isTrue();
}

@Test
public void withInboxStyle() {
Notification notification =
builder
.setStyle(
new Notification.InboxStyle(builder)
.addLine("Line1")
.addLine("Line2")
.setBigContentTitle("Title")
.setSummaryText("Summary"))
.build();

assertThat(shadowOf(notification).getBigContentTitle().toString()).isEqualTo("Title");
assertThat(shadowOf(notification).getBigContentText().toString()).isEqualTo("Summary");
assertThat(shadowOf(notification).getBigPicture()).isNull();
assertThat(shadowOf(notification).getTextLines()).containsExactly("Line1", "Line2");
}
}
Expand Up @@ -14,8 +14,10 @@
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.google.common.collect.ImmutableList;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.List;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.RealObject;
Expand Down Expand Up @@ -76,6 +78,15 @@ public CharSequence getBigContentText() {
}
}

public List<CharSequence> getTextLines() {
CharSequence[] linesArray =
realNotification.extras.getCharSequenceArray(Notification.EXTRA_TEXT_LINES);
if (linesArray == null) {
return ImmutableList.of();
}
return ImmutableList.copyOf(linesArray);
}

public Bitmap getBigPicture() {
if (RuntimeEnvironment.getApiLevel() >= Build.VERSION_CODES.N) {
return realNotification.extras.getParcelable(Notification.EXTRA_PICTURE);
Expand Down

0 comments on commit 00e219a

Please sign in to comment.