### Question:
UsersMimeMessageFactory extends AbstractIteratorMimeMessageFactory { @Override public Iterator<MimeMessage> createMessage(Object userReferencesObject, Map<String, Object> parameters) throws MessagingException { List<DocumentReference> userReferences = getTypedSource(userReferencesObject, List.class); validateParameters(parameters, HINT, SOURCE); String factoryHint = (String) parameters.get(HINT); MimeMessageFactory factory = getInternalMimeMessageFactory(factoryHint); UsersMimeMessageIterator iterator = new UsersMimeMessageIterator(userReferences, factory, parameters, this.componentManagerProvider.get()); return iterator; }  @Override Iterator<MimeMessage> createMessage(Object userReferencesObject, Map<String, Object> parameters);  }### Answer:
@Test public void createMessageWhenNullParametersPassed() throws Exception { DocumentReference userReference = new DocumentReference("wiki", "space", "page"); try { this.mocker.getComponentUnderTest().createMessage(Arrays.asList(userReference), null); fail("Should have thrown an exception"); } catch (MessagingException expected) { assertEquals("You must pass parameters for this Mime Message Factory to work!", expected.getMessage()); } }
@Test public void createMessageWhenNoHintParameterPassed() throws Exception { DocumentReference userReference = new DocumentReference("wiki", "space", "page"); try { this.mocker.getComponentUnderTest().createMessage(Arrays.asList(userReference), Collections.emptyMap()); fail("Should have thrown an exception"); } catch (MessagingException expected) { assertEquals("The parameter [hint] is mandatory.", expected.getMessage()); } }
@Test public void createMessageWhenNoSourceParameterPassed() throws Exception { DocumentReference userReference = new DocumentReference("wiki", "space", "page"); try { this.mocker.getComponentUnderTest().createMessage(Arrays.asList(userReference), Collections.singletonMap("hint", "factoryHint")); fail("Should have thrown an exception"); } catch (MessagingException expected) { assertEquals("The parameter [source] is mandatory.", expected.getMessage()); } }
@Test public void createMessageWhenNotExistingMimeMessageFactory() throws Exception { DocumentReference userReference = new DocumentReference("wiki", "space", "page"); Map<String, Object> parameters = new HashMap<>(); parameters.put("hint", "factoryHint"); parameters.put("source", "factoryHint"); Provider<ComponentManager> componentManagerProvider = this.mocker.registerMockComponent( new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context"); when(componentManagerProvider.get()).thenReturn(this.mocker); try { this.mocker.getComponentUnderTest().createMessage(Arrays.asList(userReference), parameters); fail("Should have thrown an exception"); } catch (MessagingException expected) { assertEquals("Failed to find a [MimeMessageFactory<MimeMessage>] for hint [factoryHint]", expected.getMessage()); } }