|
2 | 2 |
|
3 | 3 | import android.app.Activity;
|
4 | 4 | import android.app.Notification;
|
| 5 | +import android.app.NotificationChannel; |
5 | 6 | import android.app.NotificationManager;
|
6 | 7 | import android.content.Context;
|
7 | 8 | import android.content.Intent;
|
|
32 | 33 | import org.robolectric.Shadows;
|
33 | 34 | import org.robolectric.shadows.ShadowNotification;
|
34 | 35 |
|
35 |
| -import static com.wix.reactnativenotifications.Defs.NOTIFICATION_RECEIVED_BACKGROUND_EVENT_NAME; |
36 | 36 | import static org.junit.Assert.assertEquals;
|
37 | 37 | import static org.junit.Assert.assertNotEquals;
|
38 | 38 | import static org.mockito.ArgumentMatchers.any;
|
|
45 | 45 | import static org.mockito.Mockito.when;
|
46 | 46 | import static org.mockito.Mockito.argThat;
|
47 | 47 |
|
| 48 | +import java.util.ArrayList; |
| 49 | +import java.util.List; |
| 50 | + |
| 51 | +import edu.emory.mathcs.backport.java.util.Arrays; |
| 52 | + |
48 | 53 | @RunWith(RobolectricTestRunner.class)
|
49 | 54 | public class PushNotificationTest {
|
50 | 55 |
|
@@ -304,6 +309,24 @@ public void onPostRequest_emptyData_postNotification() throws Exception {
|
304 | 309 | verify(mNotificationManager, never()).notify(anyInt(), any(Notification.class));
|
305 | 310 | }
|
306 | 311 |
|
| 312 | + @Test |
| 313 | + public void onCreate_noExistingChannel_createDefaultChannel() throws Exception { |
| 314 | + createUUT(); |
| 315 | + |
| 316 | + verify(mNotificationManager).createNotificationChannel(any(NotificationChannel.class)); |
| 317 | + } |
| 318 | + |
| 319 | + @Test |
| 320 | + public void onCreate_existingChannel_notCreateDefaultChannel() throws Exception { |
| 321 | + List<NotificationChannel> existingChannel = new ArrayList<>(); |
| 322 | + existingChannel.add(new NotificationChannel("id", "name", 1)); |
| 323 | + when(mNotificationManager.getNotificationChannels()).thenReturn(existingChannel); |
| 324 | + |
| 325 | + createUUT(); |
| 326 | + |
| 327 | + verify(mNotificationManager, never()).createNotificationChannel(any(NotificationChannel.class)); |
| 328 | + } |
| 329 | + |
307 | 330 | protected PushNotification createUUT() {
|
308 | 331 | return createUUT(mNotificationBundle);
|
309 | 332 | }
|
|
0 commit comments