Inbox { @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) void init() { if (UAStringUtil.isEmpty(user.getId())) { final User.Listener userListener = new User.Listener() { @Override public void onUserUpdated(boolean success) { if (success) { user.removeListener(this); fetchMessages(); } } }; user.addListener(userListener); } refresh(false); activityMonitor.addApplicationListener(listener); airshipChannel.addChannelListener(new AirshipChannelListener() { @Override public void onChannelCreated(@NonNull String channelId) { dispatchUpdateUserJob(true); } @Override public void onChannelUpdated(@NonNull String channelId) { } }); if (user.shouldUpdate()) { dispatchUpdateUserJob(true); } airshipChannel.addChannelRegistrationPayloadExtender(new AirshipChannel.ChannelRegistrationPayloadExtender() { @NonNull @Override public ChannelRegistrationPayload.Builder extend(@NonNull ChannelRegistrationPayload.Builder builder) { return builder.setUserId(getUser().getId()); } }); } Inbox(@NonNull Context context, @NonNull PreferenceDataStore dataStore,
                 @NonNull AirshipChannel airshipChannel); @VisibleForTesting  Inbox(@NonNull Context context, @NonNull PreferenceDataStore dataStore, @NonNull final JobDispatcher jobDispatcher,
          @NonNull User user, @NonNull MessageCenterResolver resolver, @NonNull Executor executor,
          @NonNull ActivityMonitor activityMonitor, @NonNull AirshipChannel airshipChannel); @NonNull User getUser(); void addListener(@NonNull InboxListener listener); void removeListener(@NonNull InboxListener listener); void fetchMessages(); @Nullable Cancelable fetchMessages(@Nullable FetchMessagesCallback callback); @Nullable Cancelable fetchMessages(@Nullable Looper looper, @Nullable FetchMessagesCallback callback); int getCount(); @NonNull Set<String> getMessageIds(); int getReadCount(); int getUnreadCount(); @NonNull List<Message> getMessages(@Nullable Predicate<Message> predicate); @NonNull List<Message> getMessages(); @NonNull List<Message> getUnreadMessages(@Nullable Predicate<Message> predicate); @NonNull List<Message> getUnreadMessages(); @NonNull List<Message> getReadMessages(@Nullable Predicate<Message> predicate); @NonNull List<Message> getReadMessages(); @Nullable Message getMessage(@Nullable String messageId); @Nullable Message getMessageByUrl(@Nullable String messageUrl); void markMessagesRead(@NonNull final Set<String> messageIds); void markMessagesUnread(@NonNull final Set<String> messageIds); void deleteMessages(@NonNull final Set<String> messageIds);  }
@Test public void testInitUserShouldUpdate() { when(mockUser.shouldUpdate()).thenReturn(true); inbox.init(); verify(mockDispatcher).dispatch(Mockito.argThat(new ArgumentMatcher<JobInfo>() { @Override public boolean matches(JobInfo jobInfo) { return jobInfo.getAction().equals(InboxJobHandler.ACTION_RICH_PUSH_USER_UPDATE); } })); }
@Test public void testChannelRegistrationDisabledTokenRegistration() { ArgumentCaptor<AirshipChannel.ChannelRegistrationPayloadExtender> argument = ArgumentCaptor.forClass(AirshipChannel.ChannelRegistrationPayloadExtender.class); inbox.init(); verify(mockChannel).addChannelRegistrationPayloadExtender(argument.capture()); AirshipChannel.ChannelRegistrationPayloadExtender extender = argument.getValue(); assertNotNull(extender); when(mockUser.getId()).thenReturn("cool"); ChannelRegistrationPayload.Builder builder = new ChannelRegistrationPayload.Builder(); ChannelRegistrationPayload payload = extender.extend(builder).build(); ChannelRegistrationPayload expected = new ChannelRegistrationPayload.Builder() .setUserId("cool") .build(); assertEquals(expected, payload); }
@Test public void testChannelCreateUpdatesUser() { ArgumentCaptor<AirshipChannelListener> argument = ArgumentCaptor.forClass(AirshipChannelListener.class); inbox.init(); verify(mockChannel).addChannelListener(argument.capture()); AirshipChannelListener listener = argument.getValue(); assertNotNull(listener); clearInvocations(mockDispatcher); listener.onChannelCreated("some-channel"); verify(mockDispatcher).dispatch(Mockito.argThat(new ArgumentMatcher<JobInfo>() { @Override public boolean matches(JobInfo jobInfo) { return jobInfo.getAction().equals(InboxJobHandler.ACTION_RICH_PUSH_USER_UPDATE); } })); }