Merge "Remove @VisibleForTesting from Message#toBundle to make it public."

This commit is contained in:
David Krska
2023-04-04 14:41:32 +00:00
committed by Android (Google) Code Review
2 changed files with 24 additions and 1 deletions

View File

@@ -8723,9 +8723,11 @@ public class Notification implements Parcelable
}
/**
* Converts the message into a {@link Bundle}. To extract the message back,
* check {@link #getMessageFromBundle()}
* @hide
*/
@VisibleForTesting
@NonNull
public Bundle toBundle() {
Bundle bundle = new Bundle();
if (mText != null) {

View File

@@ -931,6 +931,27 @@ public class NotificationTest {
// no crash, good
}
@Test
public void testToBundle_getMessageFromBundle_returnsSameData() {
Notification.MessagingStyle.Message message =
new Notification.MessagingStyle.Message(
"a", 100, new Person.Builder().setName("hi").build());
message.setData("text", Uri.parse("http://test/uri"));
Notification.MessagingStyle.Message convertedMessage =
Notification.MessagingStyle.Message.getMessageFromBundle(message.toBundle());
assertThat(convertedMessage).isNotNull();
assertThat(message.getText()).isEqualTo(convertedMessage.getText());
assertThat(message.getTimestamp()).isEqualTo(convertedMessage.getTimestamp());
assertThat(message.getExtras().size()).isEqualTo(convertedMessage.getExtras().size());
assertThat(message.getSender()).isEqualTo(convertedMessage.getSender());
assertThat(message.getSenderPerson()).isEqualTo(convertedMessage.getSenderPerson());
assertThat(message.getDataMimeType()).isEqualTo(convertedMessage.getDataMimeType());
assertThat(message.getDataUri()).isEqualTo(convertedMessage.getDataUri());
assertThat(message.isRemoteInputHistory())
.isEqualTo(convertedMessage.isRemoteInputHistory());
}
@Test
public void testDoesNotStripsExtenders() {