Git Product home page Git Product logo

Comments (7)

GoogleCodeExporter avatar GoogleCodeExporter commented on May 18, 2024
Any suggestions? Adding a flag 'test mode' is easy enough so that it won't 
actually send emails.

How would you like to perform the validations?

Original comment by b.bottema on 1 Aug 2012 at 10:38

from simple-java-mail.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 18, 2024
Consider this:

    // SmtpReceiver is a simple interface definition from simple-java-mail.
    // The interface looks similar to interface used to talk to the remove server, but perhaps at a higher level of abstraction.
    // In another words, I would like to see SmtpReceiver get the "to", "from", "headers", etc., but not actually see the "helo" handshaking, etc.
    // I'd also like to make sure that simple-java-mail still performs all of the other stuff it does like validation.
    // The SmtpReceiver is the last part of the chain.
    // Oh, I'd also like to be able to have SmtpReceiver throw IOExceptions to similate network/server failures, etc.
    SmtpReceiver aSmtpFakeReceiver = <my mock or fake smtpreceiver>

    Mailer mailer = new Mailer(... aSmtpFakeReceiver ...);

Thoughts?

Original comment by [email protected] on 1 Aug 2012 at 12:06

from simple-java-mail.

bbottema avatar bbottema commented on May 18, 2024

I've given this some thought. I think it would be a good addition as it allows me to test my own code better as well. I would probably not go with an interface, but a concrete class which allows you to override the default behavior.

Thoughts?

from simple-java-mail.

musikele avatar musikele commented on May 18, 2024

Hi @bbottema ,
in my unit tests I have succesfully used Wiser (https://github.com/voodoodyne/subethasmtp/blob/master/Wiser.md) and Wiser Assertions (https://github.com/kemitix/wiser-assertions) to test send. Maybe it could be of any help to you.

For example:

    @Before
    public void setup() {
        wiser = new Wiser();
        wiser.setPort(2500);
        wiser.start();
    }

    @Test
    public void shouldSendEmail() {
        ...
        WiserAssertions.assertReceivedMessage(wiser)
                .from("[email protected]")
                .to("[email protected]")
                .withSubject("test mail")
                .withContentContains("duke nukem");
    }

this is my first piece of "markdown" so be indulgent .

from simple-java-mail.

bbottema avatar bbottema commented on May 18, 2024

Your markdown is fine :) I edited so that it has java syntax highlighting now and you can see how easy that is.

Regarding your comment on Wiser, that's nice actually. I didn't know of it before. I will let this sink in for some time, because I can't tell if this solution is enough and if the dependency is one I'm comfortable enough with for testing emails going through Simple Java Mail.

from simple-java-mail.

bbottema avatar bbottema commented on May 18, 2024

@musikele

I've given this a lot of thought and I'm going to decline this feature, as mocking this library is not the right layer to mock.

Simple Java Mail is a simple pass-through solution translating high abstractions (Email instances) to low level Java Mail SMTP objects (MimeMessages etc.). You should test if your Email objects are being populated properly rather than if the messages being sent on low-level are populated properly. In the latter case you would simply be testing either Simple Java Mail itself or Oracle's SMTP implementation.

Simply mock a Mailer instance directly using something like EasyMock or some other library and test if mailer.sendMail(Email) is being invoked with the expected Email object.

For internal testing of Simple Java Mail, however, I might use WiserAssertions as suggested, but that is to test if Simple Java Mail works as expected and so it is unrelated to this issue here.

from simple-java-mail.

bbottema avatar bbottema commented on May 18, 2024

Simple Java Mail now uses Wiser internally to test mail sending correctness!

from simple-java-mail.

Related Issues (20)

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.