I am implementing tests for a service which sends a lot of emails. As a testing tool I selected GreenMail.
I'm doing like
@Rule
public GreenMailRule mail = new GreenMailRule(ServerSetupTest.SMTP);
@Autowired
MailService mailService;
@Before
public void setUp() {
mail.setUser("[email protected]", "[email protected]", "password");
mail.setUser("[email protected]", "[email protected]", "password").create();
mail.setUser("[email protected]", "[email protected]", "p").create();
mail.start();
}
@Test
public void test() {
// sends mail from [email protected] to recipient1 and recipient2 using cc
mailService.send();
mail.setUser("[email protected]", "password");
assertEquals(1, mail.getReceivedMessages().length);
}
However, I got 2 messages - for both recipients. I think that the reason is smtp based for posting not reading. However if use POP3, I receive no messages at all.
So how can I get messages for specific user?