@@ -0,0 +1,3835 @@
+/***********************************************************************%0A * Copyright (c) 2006 The Apache Software Foundation.                  *%0A * All rights reserved.                                                *%0A * ------------------------------------------------------------------- *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22); you *%0A * may not use this file except in compliance with the License. You    *%0A * may obtain a copy of the License at:                                *%0A *                                                                     *%0A *     http://www.apache.org/licenses/LICENSE-2.0                      *%0A *                                                                     *%0A * Unless required by applicable law or agreed to in writing, software *%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,   *%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *%0A * implied.  See the License for the specific language governing       *%0A * permissions and limitations under the License.                      *%0A ***********************************************************************/%0A%0Apackage org.apache.james.transport.mailets;%0A%0Aimport org.apache.james.test.mock.mailet.MockMail;%0Aimport org.apache.james.test.mock.mailet.MockMailContext;%0Aimport org.apache.james.test.mock.mailet.MockMailetConfig;%0Aimport org.apache.mailet.Mail;%0Aimport org.apache.mailet.MailAddress;%0Aimport org.apache.mailet.Mailet;%0A%0Aimport javax.mail.MessagingException;%0Aimport javax.mail.internet.MimeMessage;%0Aimport javax.mail.internet.ParseException;%0A%0Aimport java.io.UnsupportedEncodingException;%0Aimport java.util.Arrays;%0A%0Aimport junit.framework.TestCase;%0A%0Apublic class ToProcessorTest extends TestCase %7B%0A%0A    private MimeMessage mockedMimeMessage;%0A%0A    private Mail mockedMail;%0A%0A    private Mailet mailet;%0A%0A    private String processor = null;%0A%0A    private String notice = null;%0A%0A    public ToProcessorTest(String arg0) throws UnsupportedEncodingException %7B%0A        super(arg0);%0A    %7D%0A%0A    private void setProcessor(String processor) %7B%0A        this.processor = processor;%0A    %7D%0A%0A    private void setNotice(String notice) %7B%0A        this.notice = notice;%0A    %7D%0A%0A    private void setupMockedMail(MimeMessage m) throws ParseException %7B%0A        mockedMail = new MockMail();%0A        mockedMail.setMessage(m);%0A        mockedMail.setRecipients(Arrays.asList(new MailAddress%5B%5D %7B%0A                new MailAddress(%22test@james.apache.org%22),%0A                new MailAddress(%22test2@james.apache.org%22) %7D));%0A%0A    %7D%0A%0A    private void setupMailet() throws MessagingException %7B%0A        mailet = new ToProcessor();%0A        MockMailetConfig mci = new MockMailetConfig(%22Test%22,%0A                new MockMailContext());%0A        if (processor != null) %7B%0A            mci.setProperty(%22processor%22, processor);%0A        %7D%0A        if (notice != null) %7B%0A            mci.setProperty(%22notice%22, notice);%0A        %7D%0A        mailet.init(mci);%0A    %7D%0A%0A    // test if ToProcessor works%0A    public void testValidToProcessor() throws MessagingException %7B%0A        setProcessor(%22error%22);%0A        setNotice(%22error in message%22);%0A        setupMockedMail(mockedMimeMessage);%0A        setupMailet();%0A%0A        mailet.service(mockedMail);%0A%0A        assertEquals(processor, mockedMail.getState());%0A        assertEquals(notice, mockedMail.getErrorMessage());%0A%0A    %7D%0A%0A    // test if exception was thrown%0A    public void testExceptionThrown() throws MessagingException %7B%0A        boolean exceptionThrown = false;%0A        setProcessor(null);%0A        setNotice(%22error in message%22);%0A        setupMockedMail(mockedMimeMessage);%0A%0A        try %7B%0A            setupMailet();%0A            mailet.service(mockedMail);%0A        %7D catch (MessagingException m) %7B%0A            exceptionThrown = true;%0A        %7D%0A        assertTrue(exceptionThrown);%0A    %7D%0A%0A%7D%0A

Copy ToProcessor junit test