NotificationTypeHandlerSelector { public NotificationTypeHandler getTypeHandlerFrom(PublisherData publisherData) { String inputPublisherDataType = publisherData.getType(); for (Iterator<NotificationTypeHandler> iterator = notificationTypeHandler.iterator(); iterator.hasNext();) { NotificationTypeHandler notificationTypeHandler = iterator.next(); if (notificationTypeHandler.getPublisherDataType().equals(inputPublisherDataType)) { return notificationTypeHandler; } } return new DummyNotificationTypeHandler(); } NotificationTypeHandlerSelector(); NotificationTypeHandler getTypeHandler(String sourceType); NotificationTypeHandler getTypeHandlerFrom(PublisherData publisherData);  }
@Test public void getTypeHandlerFrom_Forum() { PublisherData publisherData = mock(PublisherData.class); when(publisherData.getType()).thenReturn("Forum"); NotificationTypeHandler forumTypeHandler = typeHandlerSelectorTestObject.getTypeHandlerFrom(publisherData); assertNotNull("Could not found NotificationTypeHandler for 'forum'", forumTypeHandler); assertTrue("Wrong type-handler for forum", forumTypeHandler instanceof ForumNotificationTypeHandler); }
@Test public void getTypeHandlerFrom_Wiki() { PublisherData publisherData = mock(PublisherData.class); when(publisherData.getType()).thenReturn("WikiPage"); NotificationTypeHandler wikiTypeHandler = typeHandlerSelectorTestObject.getTypeHandlerFrom(publisherData); assertNotNull("Could not found NotificationTypeHandler for 'wiki'", wikiTypeHandler); assertTrue("Wrong type-handler for forum", wikiTypeHandler instanceof WikiNotificationTypeHandler); }