Giter Site home page Giter Site logo

florentbo / javamail-mock2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from salyh/javamail-mock2

0.0 1.0 0.0 736 KB

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

License: Apache License 2.0

Java 100.00%

javamail-mock2's Introduction

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)

javamail-mock2's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.