Skip to content

Commit 9f98666

Browse files
committed
Add test for v1 custom serialization
1 parent 61c7d24 commit 9f98666

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

com.unity.mobile.notifications/Tests/Runtime/Android/AndroidNotificationSimpleTests.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,23 @@ static bool SerializeNotificationCustom(AndroidJavaClass utilsClass, AndroidJava
243243
}
244244

245245
static bool SerializeNotificationCustom_v0(AndroidJavaClass utilsClass, AndroidJavaObject byteStream, AndroidJavaObject javaNotif)
246+
{
247+
return SerializeNotificationCustom_old("serializeNotificationCustom_v0", byteStream, javaNotif);
248+
}
249+
250+
static bool SerializeNotificationCustom_v1(AndroidJavaClass utilsClass, AndroidJavaObject byteStream, AndroidJavaObject javaNotif)
251+
{
252+
return SerializeNotificationCustom_old("serializeNotificationCustom_v1", byteStream, javaNotif);
253+
}
254+
255+
static bool SerializeNotificationCustom_old(string method, AndroidJavaObject byteStream, AndroidJavaObject javaNotif)
246256
{
247257
using (var dataStream = new AndroidJavaObject("java.io.DataOutputStream", byteStream))
248258
{
249259
bool didSerialize;
250260
using (var testUtils = new AndroidJavaClass("com.unity.androidnotifications.UnityNotificationTestUtils"))
251261
{
252-
didSerialize = testUtils.CallStatic<bool>("serializeNotificationCustom_v0", javaNotif, dataStream);
262+
didSerialize = testUtils.CallStatic<bool>(method, javaNotif, dataStream);
253263
}
254264
dataStream.Call("close");
255265
return didSerialize;
@@ -598,4 +608,29 @@ public void CanDeserializeCustomSerializedNotification_v0()
598608
original.ShowInForeground = true; // v0 did not have this, so should default to true
599609
CheckNotificationsMatch(original, deserialized.Notification);
600610
}
611+
612+
[Test]
613+
[UnityPlatform(RuntimePlatform.Android)]
614+
public void CanDeserializeCustomSerializedNotification_v1()
615+
{
616+
const int notificationId = 255;
617+
618+
var original = CreateNotificationWithAllParameters();
619+
620+
AndroidNotificationIntentData deserialized;
621+
using (var builder = AndroidNotificationCenter.CreateNotificationBuilder(notificationId, original, kChannelId))
622+
{
623+
// put something to extrax to force completely custom serialization of them
624+
var bitmap = CreateBitmap();
625+
Assert.IsNotNull(bitmap);
626+
var extras = builder.Call<AndroidJavaObject>("getExtras");
627+
extras.Call("putParcelable", "binder_item", bitmap);
628+
629+
// Serialize like we did in version 0
630+
deserialized = SerializeDeserializeNotificationWithFunc(builder, (u, s, j) => SerializeNotificationCustom_v1(u, s, j));
631+
}
632+
633+
Assert.IsNotNull(deserialized);
634+
CheckNotificationsMatch(original, deserialized.Notification);
635+
}
601636
}

0 commit comments

Comments
 (0)