Skip to content

Commit 8b68f3c

Browse files
committed
Add ShowInForeground to serialization tests
1 parent 450c8e7 commit 8b68f3c

File tree

1 file changed

+36
-20
lines changed

1 file changed

+36
-20
lines changed

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

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,31 +76,39 @@ public void SetNotificationRepeatInterval_TimeIsConvertedToUnixTimeAndBack()
7676
Assert.AreEqual(repeatInterval, n.RepeatInterval);
7777
}
7878

79+
AndroidNotification CreateNotificationWithAllParameters()
80+
{
81+
var notification = new AndroidNotification();
82+
notification.Title = "title";
83+
notification.Text = "text";
84+
notification.SmallIcon = "small_icon";
85+
notification.FireTime = DateTime.Now;
86+
notification.RepeatInterval = new TimeSpan(0, 0, 5);
87+
notification.LargeIcon = "large_icon";
88+
notification.Style = NotificationStyle.BigTextStyle;
89+
notification.Color = new Color(0.2f, 0.4f, 0.6f, 1.0f);
90+
notification.Number = 15;
91+
notification.ShouldAutoCancel = true;
92+
notification.UsesStopwatch = true;
93+
notification.Group = "group";
94+
notification.GroupSummary = true;
95+
notification.GroupAlertBehaviour = GroupAlertBehaviours.GroupAlertChildren;
96+
notification.SortKey = "sorting";
97+
notification.IntentData = "string for intent";
98+
notification.ShowTimestamp = true;
99+
notification.ShowInForeground = false; // this one defaults to true
100+
notification.CustomTimestamp = new DateTime(2018, 5, 24, 12, 41, 30, 122);
101+
102+
return notification;
103+
}
104+
79105
[Test]
80106
[UnityPlatform(RuntimePlatform.Android)]
81107
public void BasicSerializeDeserializeNotification_AllParameters()
82108
{
83109
const int notificationId = 123;
84110

85-
var original = new AndroidNotification();
86-
original.Title = "title";
87-
original.Text = "text";
88-
original.SmallIcon = "small_icon";
89-
original.FireTime = DateTime.Now;
90-
original.RepeatInterval = new TimeSpan(0, 0, 5);
91-
original.LargeIcon = "large_icon";
92-
original.Style = NotificationStyle.BigTextStyle;
93-
original.Color = new Color(0.2f, 0.4f, 0.6f, 1.0f);
94-
original.Number = 15;
95-
original.ShouldAutoCancel = true;
96-
original.UsesStopwatch = true;
97-
original.Group = "group";
98-
original.GroupSummary = true;
99-
original.GroupAlertBehaviour = GroupAlertBehaviours.GroupAlertChildren;
100-
original.SortKey = "sorting";
101-
original.IntentData = "string for intent";
102-
original.ShowTimestamp = true;
103-
original.CustomTimestamp = new DateTime(2018, 5, 24, 12, 41, 30, 122);
111+
var original = CreateNotificationWithAllParameters();
104112

105113
var deserializedData = SerializeDeserializeNotification(original, notificationId);
106114

@@ -118,14 +126,19 @@ AndroidNotificationIntentData SerializeDeserializeNotification(AndroidNotificati
118126
}
119127

120128
AndroidNotificationIntentData SerializeDeserializeNotification(AndroidJavaObject builder)
129+
{
130+
return SerializeDeserializeNotification(builder, "serializeNotificationCustom");
131+
}
132+
133+
AndroidNotificationIntentData SerializeDeserializeNotification(AndroidJavaObject builder, string serializeMethod)
121134
{
122135
var javaNotif = builder.Call<AndroidJavaObject>("build");
123136
var utilsClass = new AndroidJavaClass("com.unity.androidnotifications.UnityNotificationUtilities");
124137
AndroidJavaObject serializedBytes; // use java object, since we don't need the bytes, so don't waste time on marshalling
125138
using (var byteStream = new AndroidJavaObject("java.io.ByteArrayOutputStream"))
126139
{
127140
var dataStream = new AndroidJavaObject("java.io.DataOutputStream", byteStream);
128-
var didSerialize = utilsClass.CallStatic<bool>("serializeNotificationCustom", javaNotif, dataStream);
141+
var didSerialize = utilsClass.CallStatic<bool>(serializeMethod, javaNotif, dataStream);
129142
Assert.IsTrue(didSerialize);
130143
dataStream.Call("close");
131144
serializedBytes = byteStream.Call<AndroidJavaObject>("toByteArray");
@@ -165,6 +178,7 @@ void CheckNotificationsMatch(AndroidNotification original, AndroidNotification o
165178
Assert.AreEqual(original.SortKey, other.SortKey);
166179
Assert.AreEqual(original.IntentData, other.IntentData);
167180
Assert.AreEqual(original.ShowTimestamp, other.ShowTimestamp);
181+
Assert.AreEqual(original.ShowInForeground, other.ShowInForeground);
168182
Assert.AreEqual(original.CustomTimestamp, other.CustomTimestamp);
169183
}
170184

@@ -296,6 +310,7 @@ public void NotificationSerialization_NotificationWithBinderObject()
296310

297311
var original = new AndroidNotification();
298312
original.FireTime = DateTime.Now.AddSeconds(2);
313+
original.ShowInForeground = false; // non default value
299314

300315
var builder = AndroidNotificationCenter.CreateNotificationBuilder(notificationId, original, kChannelId);
301316
var extras = builder.Call<AndroidJavaObject>("getExtras");
@@ -306,6 +321,7 @@ public void NotificationSerialization_NotificationWithBinderObject()
306321
var deserializedData = SerializeDeserializeNotification(builder);
307322

308323
Assert.AreEqual(original.FireTime.ToString(), deserializedData.Notification.FireTime.ToString());
324+
Assert.IsFalse(deserializedData.Notification.ShowInForeground);
309325
var deserializedExtras = deserializedData.NativeNotification.Get<AndroidJavaObject>("extras");
310326
var bitmapAfterSerialization = deserializedExtras.Call<AndroidJavaObject>("getParcelable", "binder_item");
311327
// bitmap is binder object and can't be parcelled, while our fallback custom serialization only preserves our stuff

0 commit comments

Comments
 (0)