Javamail Mock2 (Mode: fullmock)

Open source mock classes for mock up JavaMail (Mode: fullmock)

License

License

GroupId

GroupId

de.saly
ArtifactId

ArtifactId

javamail-mock2-fullmock
Last Version

Last Version

0.5-beta4
Release Date

Release Date

Type

Type

jar
Description

Description

Javamail Mock2 (Mode: fullmock)
Open source mock classes for mock up JavaMail (Mode: fullmock)
Project URL

Project URL

https://github.com/salyh/javamail-mock2
Source Code Management

Source Code Management

https://github.com/salyh/javamail-mock2

Download javamail-mock2-fullmock

How to add to project

<!-- https://jarcasting.com/artifacts/de.saly/javamail-mock2-fullmock/ -->
<dependency>
    <groupId>de.saly</groupId>
    <artifactId>javamail-mock2-fullmock</artifactId>
    <version>0.5-beta4</version>
</dependency>
// https://jarcasting.com/artifacts/de.saly/javamail-mock2-fullmock/
implementation 'de.saly:javamail-mock2-fullmock:0.5-beta4'
// https://jarcasting.com/artifacts/de.saly/javamail-mock2-fullmock/
implementation ("de.saly:javamail-mock2-fullmock:0.5-beta4")
'de.saly:javamail-mock2-fullmock:jar:0.5-beta4'
<dependency org="de.saly" name="javamail-mock2-fullmock" rev="0.5-beta4">
  <artifact name="javamail-mock2-fullmock" type="jar" />
</dependency>
@Grapes(
@Grab(group='de.saly', module='javamail-mock2-fullmock', version='0.5-beta4')
)
libraryDependencies += "de.saly" % "javamail-mock2-fullmock" % "0.5-beta4"
[de.saly/javamail-mock2-fullmock "0.5-beta4"]

Dependencies

compile (2)

Group / Artifact Type Version
com.sun.mail : javax.mail jar 1.5.2
org.slf4j : slf4j-api jar 1.7.7

test (2)

Group / Artifact Type Version
junit : junit jar 4.11
org.slf4j : slf4j-log4j12 jar 1.7.7

Project Modules

There are no modules declared in this project.

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

* Support imap, imaps, pop3, pop3s, smtp, smtps * Support for SMTP: Mock Transport.send() * Supported for POP3: * cast to POP3Folder * Folder.getUID(Message msg) * Supported for IMAP: * cast to IMAPFolder * cast to UIDFolder * IDLE * ID * Subfolders * Folder.getMessagesByUID(...) * delete/rename folders * append messages * Unsupported for the moment: * All IMAP extensions except IDLE and ID * casts to POP3Message/IMAPMessage * store listeners

The library come in two flavors/modes

  • Normal (or halfmock): Allows also to connect to real IMAP/POP servers. Use this if you have mixed testing setups (mockend an real server). Require a little bit of setup.
  • Fullmock: Use this if you have mocked test only. Normally no setup required.

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

Usage: Normal (= Halfmock) mode

* Include the javamail-mock2-halfmock-x.x.jar file in your unittest project (or use maven, see below) * Make sure every operation that should be mocked uses as protocol either mock_smtp, mock_imap or mock_pop3 (or mock_smtps, mock_imaps or mock_pop3s) * See unittest how to archive this * Create a mailbox and add folders/messages or use Transport.sendMail to put mails into your INBOX * Use the JavaMail API to retrieve mails via POP3 or IMAP or do whatever your application does

Usage: Fullmock mode

* Include the javamail-mock2-fullmock-x.x.jar file in your unittest project (or use maven, see below) * Create a mailbox and add folders/messages or use Transport.sendMail to put mails into your INBOX * Use the JavaMail API to retrieve mails via POP3 or IMAP or do whatever your application does

Maven: Normal (= Halfmock)

```xml de.saly javamail-mock2-halfmock 0.5-beta4 test ```

Maven: Fullmock

```xml de.saly javamail-mock2-fullmock 0.5-beta4 test ```

Examples

```java
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](https://github.com/salyh/elasticsearch-river-imap)

Versions

Version
0.5-beta4
0.5-beta3