lundi 4 septembre 2017

java - calling a boolean timeout function in a if statement so it doesn't send email

first of all - here is part of my Code:

    public void run() {



            try {

            _conn = new SmtpConnection(this, _socket);
            _state = new SmtpState(_workspace);
            _quitting = false;


            sendGreetings();


                while (!_quitting)
                handleCommand();

        } catch (SocketTimeoutException ste) {
            _conn.send("421 Service shutting down and closing transmission channel");

        } catch (Exception e) {
            // Closing socket on blocked read


            if (!_quitting) {
                log.error("Unexpected error handling connection, quitting=", e);
                throw new IllegalStateException(e);
            }
        } finally {
            if (null != _state) {
                _state.clearMessage();
            }
        }

    }

and I have also one function in another class, which is called timeoutonemail

    public boolean timeoutOnNextEmail()
{

    boolean timeout = true;
    return timeout;
}

I have a unittest, which should try to send E-Mail, but when i call timeoutfuntion, test should pass - so it should not send an email

/*    @Test(expected = MailException.class)
public void sendEmailFail() throws MailException {

    greenMail.timeoutOnNextEmail();

    try {
        app.sendMail("to", "from", "subject", "body");
    } catch (final MailException e) {
        throw new MailException(e.toString());
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    assertEquals(0, greenMail.getReceivedMessagesForDomain("to").length);
}*/

How can I tell my run funtion, that if I'm calling timeoutfuntion in my unittest, so that it should stop doing that and let my thread sleep.. I tried something like

*/*                    if(timeout && !_quitting){
                greenMail.timeoutOnNextEmail();
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            else
            {
                handleCommand();
            }*/*

and several different Options, but i just don't have idea how to call it correctly..

Aucun commentaire:

Enregistrer un commentaire