@@ -171,6 +171,46 @@ public void testDisableInAppMessagingPreventsMessageDisplay() throws Exception {
171
171
assertFalse (OneSignalPackagePrivateHelper .isInAppMessageShowing ());
172
172
}
173
173
174
+ @ Test
175
+ public void testMessagesDoNotDisplayPastEndTime () throws Exception {
176
+ final OSTestInAppMessage message = InAppMessagingHelpers .buildTestMessageWithEndTime (OSTriggerKind .CUSTOM , "test_key" , OSTestTrigger .OSTriggerOperator .EQUAL_TO .toString (), 3 , true );
177
+ setMockRegistrationResponseWithMessages (new ArrayList <OSTestInAppMessage >() {{
178
+ add (message );
179
+ }});
180
+
181
+ // the SDK should read the message from registration JSON, set up a timer, and once
182
+ // the timer fires the message should get shown.
183
+ OneSignalInit ();
184
+ threadAndTaskWait ();
185
+
186
+ // We will set the trigger. However, since the end time is in the past the message should not be shown
187
+ OneSignal .addTrigger ("test_key" , 3 );
188
+ // Make no IAMs are in the display queue
189
+ assertEquals (0 , OneSignalPackagePrivateHelper .getInAppMessageDisplayQueue ().size ());
190
+ // Make sure no IAM is showing
191
+ assertFalse (OneSignalPackagePrivateHelper .isInAppMessageShowing ());
192
+ }
193
+
194
+ @ Test
195
+ public void testMessagesDoDisplayBeforeEndTime () throws Exception {
196
+ final OSTestInAppMessage message = InAppMessagingHelpers .buildTestMessageWithEndTime (OSTriggerKind .CUSTOM , "test_key" , OSTestTrigger .OSTriggerOperator .EQUAL_TO .toString (), 3 , false );
197
+ setMockRegistrationResponseWithMessages (new ArrayList <OSTestInAppMessage >() {{
198
+ add (message );
199
+ }});
200
+
201
+ // the SDK should read the message from registration JSON, set up a timer, and once
202
+ // the timer fires the message should get shown.
203
+ OneSignalInit ();
204
+ threadAndTaskWait ();
205
+
206
+ // We will set the trigger. However, since the end time is in the past the message should not be shown
207
+ OneSignal .addTrigger ("test_key" , 3 );
208
+ // Make no IAMs are in the display queue
209
+ assertEquals (1 , OneSignalPackagePrivateHelper .getInAppMessageDisplayQueue ().size ());
210
+ // Make sure no IAM is showing
211
+ assertTrue (OneSignalPackagePrivateHelper .isInAppMessageShowing ());
212
+ }
213
+
174
214
/**
175
215
* Since it is possible for multiple in-app messages to be valid at the same time, we've implemented
176
216
* a queue so that the SDK does not try to display both messages at the same time.
@@ -307,7 +347,12 @@ public void testTimedMessageIsDisplayedOncePerSession() throws Exception {
307
347
Awaitility .await ()
308
348
.atMost (new Duration (150 , TimeUnit .MILLISECONDS ))
309
349
.pollInterval (new Duration (10 , TimeUnit .MILLISECONDS ))
310
- .until (() -> OneSignalPackagePrivateHelper .getInAppMessageDisplayQueue ().size () == 1 );
350
+ .until (new Callable <Boolean >() {
351
+ @ Override
352
+ public Boolean call () throws Exception {
353
+ return OneSignalPackagePrivateHelper .getInAppMessageDisplayQueue ().size () == 1 ;
354
+ }
355
+ });
311
356
312
357
OneSignalPackagePrivateHelper .dismissCurrentMessage ();
313
358
0 commit comments