NotificationChannelRegistry { @NonNull public PendingResult<NotificationChannelCompat> getNotificationChannel(@NonNull final String id) { final PendingResult<NotificationChannelCompat> pendingResult = new PendingResult<>(); executor.execute(new Runnable() { @Override public void run() { NotificationChannelCompat result; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = notificationManager.getNotificationChannel(id); if (channel != null) { result = new NotificationChannelCompat(channel); } else { result = dataManager.getChannel(id); if (result != null) { notificationManager.createNotificationChannel(result.toNotificationChannel()); } } } else { result = dataManager.getChannel(id); } pendingResult.setResult(result); } }); return pendingResult; } @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)  NotificationChannelRegistry(@NonNull Context context, @NonNull AirshipConfigOptions configOptions); @VisibleForTesting  NotificationChannelRegistry(@NonNull Context context, @NonNull NotificationChannelRegistryDataManager dataManager, @NonNull Executor executor); @NonNull PendingResult<NotificationChannelCompat> getNotificationChannel(@NonNull final String id); @Nullable @WorkerThread NotificationChannelCompat getNotificationChannelSync(@NonNull String id); void deleteNotificationChannel(@NonNull final String id); void createNotificationChannel(@NonNull final NotificationChannelCompat channelCompat); void createDeferredNotificationChannel(@NonNull final NotificationChannelCompat channelCompat); void createNotificationChannels(@XmlRes final int resourceId); void createDeferredNotificationChannels(@XmlRes final int resourceId);  }
@Test @Config(sdk = 25) public void testGetNotificationChannelAsyncPreOreo() { when(dataManager.getChannel("test")).thenReturn(channelCompat); PendingResult<NotificationChannelCompat> result = channelRegistry.getNotificationChannel("test"); verify(dataManager).getChannel("test"); Assert.assertEquals(channelCompat, result.getResult()); }
@Test public void testGetNotificationChannelAsync() { when(notificationManager.getNotificationChannel("test")).thenReturn(channel); PendingResult<NotificationChannelCompat> result = channelRegistry.getNotificationChannel("test"); verify(notificationManager).getNotificationChannel("test"); Assert.assertEquals(channelCompat, result.getResult()); }