### Question:
UsersAndGroupsMimeMessageFactory extends AbstractIteratorMimeMessageFactory { @Override public Iterator<MimeMessage> createMessage(Object sourceObject, Map<String, Object> parameters) throws MessagingException { Map<String, Object> source = getTypedSource(sourceObject, Map.class); validateParameters(parameters, HINT, SOURCE); String factoryHint = (String) parameters.get(HINT); MimeMessageFactory factory = getInternalMimeMessageFactory(factoryHint); UsersAndGroupsMimeMessageIterator iterator = new UsersAndGroupsMimeMessageIterator(source, factory, parameters, this.explicitDocumentReferenceResolver, this.execution); return iterator; }  @Override Iterator<MimeMessage> createMessage(Object sourceObject, Map<String, Object> parameters);  }### Answer:
@Test public void createMessageWhenNullParametersPassed() throws Exception { try { this.mocker.getComponentUnderTest().createMessage(Collections.<String, Object>emptyMap(), 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 { try { this.mocker.getComponentUnderTest().createMessage( Collections.<String, Object>emptyMap(), Collections.<String, Object>emptyMap()); fail("Should have thrown an exception"); } catch (MessagingException expected) { assertEquals("The parameter [hint] is mandatory.", expected.getMessage()); } }
@Test public void createMessageWhenNoSourceParameterPassed() throws Exception { try { this.mocker.getComponentUnderTest().createMessage(Collections.<String, Object>emptyMap(), Collections.<String, Object>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 { Session session = Session.getInstance(new Properties()); 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(Collections.<String, Object>emptyMap(), parameters); fail("Should have thrown an exception"); } catch (MessagingException expected) { assertEquals("Failed to find a [MimeMessageFactory<MimeMessage>] for hint [factoryHint]", expected.getMessage()); } }
@Test public void createMessage() throws Exception { DocumentReference userReference = new DocumentReference("userwiki", "userspace", "userpage"); Map<String, Object> source = Collections.<String, Object>singletonMap("users", Collections.singletonList(userReference)); Map<String, Object> parameters = new HashMap<>(); parameters.put("hint", "template"); parameters.put("source", new DocumentReference("templatewiki", "templatespace", "templatepage")); Provider<ComponentManager> componentManagerProvider = this.mocker.registerMockComponent( new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context"); when(componentManagerProvider.get()).thenReturn(this.mocker); this.mocker.registerMockComponent(new DefaultParameterizedType(null, MimeMessageFactory.class, MimeMessage.class), "template"); Execution execution = this.mocker.registerMockComponent(Execution.class); XWikiContext xwikiContext = mock(XWikiContext.class); ExecutionContext executionContext = new ExecutionContext(); executionContext.setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, xwikiContext); when(execution.getContext()).thenReturn(executionContext); Iterator<MimeMessage> iterator = this.mocker.getComponentUnderTest().createMessage(source, parameters); assertNotNull(iterator); }