@Test public void whenOtherEventTypesIsEnabled() throws Exception { NotificationPreference pref = mock(NotificationPreference.class); when(pref.isNotificationEnabled()).thenReturn(true); Map<NotificationPreferenceProperty, Object> properties = new HashMap<>(); properties.put(NotificationPreferenceProperty.EVENT_TYPE, "blog"); when(pref.getProperties()).thenReturn(properties); when(notificationPreferenceManager.getAllPreferences(eq(currentUser))).thenReturn(Arrays.asList(pref)); doAnswer(invocationOnMock -> { List<NotificationPreference> preferencesToSave = invocationOnMock.getArgument(0); assertEquals(8, preferencesToSave.size()); return null; }).when(notificationPreferenceManager).savePreferences(anyList()); mocker.getComponentUnderTest().ensureXWikiNotificationsAreEnabled(currentUser); verify(notificationPreferenceManager).savePreferences(anyList()); }
public void ensureXWikiNotificationsAreEnabled(DocumentReference user) throws NotificationException { if (isNotificationDisabled(user)) { TargetableNotificationPreferenceBuilder builder = targetableNotificationPreferenceBuilderProvider.get(); List<NotificationPreference> preferencesToCreate = new ArrayList<>(); Date now = new Date(); for (String eventType : XWIKI_EVENT_TYPES) { for (NotificationFormat format : NotificationFormat.values()) { preferencesToCreate.add(createNotificationPreference(user, builder, eventType, format, now)); } } notificationPreferenceManager.savePreferences(preferencesToCreate); } }
XWikiEventTypesEnabler { public void ensureXWikiNotificationsAreEnabled(DocumentReference user) throws NotificationException { if (isNotificationDisabled(user)) { TargetableNotificationPreferenceBuilder builder = targetableNotificationPreferenceBuilderProvider.get(); List<NotificationPreference> preferencesToCreate = new ArrayList<>(); Date now = new Date(); for (String eventType : XWIKI_EVENT_TYPES) { for (NotificationFormat format : NotificationFormat.values()) { preferencesToCreate.add(createNotificationPreference(user, builder, eventType, format, now)); } } notificationPreferenceManager.savePreferences(preferencesToCreate); } } }
XWikiEventTypesEnabler { public void ensureXWikiNotificationsAreEnabled(DocumentReference user) throws NotificationException { if (isNotificationDisabled(user)) { TargetableNotificationPreferenceBuilder builder = targetableNotificationPreferenceBuilderProvider.get(); List<NotificationPreference> preferencesToCreate = new ArrayList<>(); Date now = new Date(); for (String eventType : XWIKI_EVENT_TYPES) { for (NotificationFormat format : NotificationFormat.values()) { preferencesToCreate.add(createNotificationPreference(user, builder, eventType, format, now)); } } notificationPreferenceManager.savePreferences(preferencesToCreate); } }  }
XWikiEventTypesEnabler { public void ensureXWikiNotificationsAreEnabled(DocumentReference user) throws NotificationException { if (isNotificationDisabled(user)) { TargetableNotificationPreferenceBuilder builder = targetableNotificationPreferenceBuilderProvider.get(); List<NotificationPreference> preferencesToCreate = new ArrayList<>(); Date now = new Date(); for (String eventType : XWIKI_EVENT_TYPES) { for (NotificationFormat format : NotificationFormat.values()) { preferencesToCreate.add(createNotificationPreference(user, builder, eventType, format, now)); } } notificationPreferenceManager.savePreferences(preferencesToCreate); } }  void ensureXWikiNotificationsAreEnabled(DocumentReference user); boolean isNotificationDisabled(DocumentReference user); }
XWikiEventTypesEnabler { public void ensureXWikiNotificationsAreEnabled(DocumentReference user) throws NotificationException { if (isNotificationDisabled(user)) { TargetableNotificationPreferenceBuilder builder = targetableNotificationPreferenceBuilderProvider.get(); List<NotificationPreference> preferencesToCreate = new ArrayList<>(); Date now = new Date(); for (String eventType : XWIKI_EVENT_TYPES) { for (NotificationFormat format : NotificationFormat.values()) { preferencesToCreate.add(createNotificationPreference(user, builder, eventType, format, now)); } } notificationPreferenceManager.savePreferences(preferencesToCreate); } }  void ensureXWikiNotificationsAreEnabled(DocumentReference user); boolean isNotificationDisabled(DocumentReference user);  }