javamail-mock2

Open source mock classes for mockup JavaMail (useful especially for unittest). Supports IMAP IDLE.

Build Status

E-Mail [email protected]

Twitter @hendrikdev22

Features

The library come in two flavors/modes

See unittests for how to use the library. Maven site docu is here: http://salyh.github.io/javamail-mock2/

Usage: Normal (= Halfmock) mode

Usage: Fullmock mode

Maven: Normal (= Halfmock)

    <dependency>
        <groupId>de.saly</groupId>
        <artifactId>javamail-mock2-halfmock</artifactId>
        <version>0.5-beta4</version>
        <scope>test</scope>
    </dependency>

Maven: Fullmock

    <dependency>
        <groupId>de.saly</groupId>
        <artifactId>javamail-mock2-fullmock</artifactId>
        <version>0.5-beta4</version>
        <scope>test</scope>
    </dependency>

Examples


    final MockMailbox mb = MockMailbox.get("[email protected]");
        final MailboxFolder mf = mb.getInbox();

        final MimeMessage msg = new MimeMessage((Session) null);
        msg.setSubject("Test");
        msg.setFrom("[email protected]");
        msg.setText("Some text here ...");
        msg.setRecipient(RecipientType.TO, new InternetAddress("[email protected]"));
        mf.add(msg); // 11
        mf.add(msg); // 12
        mf.add(msg); // 13

        Session session = Session.getInstance(new Properties());
        final Store store = session.getStore("pop3s"); //or mock_pop3s for halfmock
        store.connect("[email protected]", null);
        final Folder inbox = store.getFolder("INBOX");
        inbox.open(Folder.READ_ONLY);
        Assert.assertEquals(3, inbox.getMessageCount());
        Assert.assertNotNull(inbox.getMessage(1));
        inbox.close(true);

For a real usage scenario look here: Elasticsearch IMAP River