/***********************************************************************
 * Copyright (c) 2006 The Apache Software Foundation.                  *
 * All rights reserved.                                                *
 * ------------------------------------------------------------------- *
 * Licensed under the Apache License, Version 2.0 (the "License"); you *
 * may not use this file except in compliance with the License. You    *
 * may obtain a copy of the License at:                                *
 *                                                                     *
 *     http://www.apache.org/licenses/LICENSE-2.0                      *
 *                                                                     *
 * Unless required by applicable law or agreed to in writing, software *
 * distributed under the License is distributed on an "AS IS" BASIS,   *
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
 * implied.  See the License for the specific language governing       *
 * permissions and limitations under the License.                      *
 ***********************************************************************/

package org.apache.james.transport.matchers;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.ParseException;

import junit.framework.TestCase;

import org.apache.james.Constants;
import org.apache.james.services.DNSServer;
import org.apache.james.test.mock.avalon.MockServiceManager;
import org.apache.james.test.mock.mailet.MockMailContext;
import org.apache.james.test.mock.mailet.MockMatcherConfig;
import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;

public abstract class AbstractRemoteAddrInNetworkTest extends TestCase {

    protected Mail mockedMail;

    protected AbstractNetworkMatcher matcher;

    private String remoteAddr;

    private DNSServer dnsServer;

    private MockServiceManager m_serviceManager;

    public AbstractRemoteAddrInNetworkTest(String arg0)
            throws UnsupportedEncodingException {
        super(arg0);
    }

    protected void setRemoteAddr(String remoteAddr) {
        this.remoteAddr = remoteAddr;
    }

    protected void setupMockedMail() {
        mockedMail = new Mail() {

            private static final long serialVersionUID = 1L;

            public String getName() {
                throw new UnsupportedOperationException(
                        "Unimplemented mock service");
            }

            public void setName(String newName) {
                throw new UnsupportedOperationException(
                        "Unimplemented mock service");
            }

            public MimeMessage getMessage() throws MessagingException {
                throw new UnsupportedOperationException(
                        "Unimplemented mock service");
            }

            public Collection getRecipients() {
                ArrayList r = new ArrayList();
                try {
                    r = new ArrayList(Arrays
                            .asList(new MailAddress[] { new MailAddress(
                                    "test@james.apache.org") }));
                } catch (ParseException e) {
                }
                return r;
            }

            public void setRecipients(Collection recipients) {
                throw new UnsupportedOperationException(
                        "Unimplemented mock service");
            }

            public MailAddress getSender() {
                throw new UnsupportedOperationException(
                        "Unimplemented mock service");
            }

            public String getState() {
                throw new UnsupportedOperationException(
                        "Unimplemented mock service");
            }

            public String getRemoteHost() {
                throw new UnsupportedOperationException(
                        "Unimplemented mock service");
            }

            public String getRemoteAddr() {
                return remoteAddr;
            }

            public String getErrorMessage() {
                throw new UnsupportedOperationException(
                        "Unimplemented mock service");
            }

            public void setErrorMessage(String msg) {
                throw new UnsupportedOperationException(
                        "Unimplemented mock service");
            }

            public void setMessage(MimeMessage message) {
                throw new UnsupportedOperationException(
                        "Unimplemented mock service");
            }

            public void setState(String state) {
                throw new UnsupportedOperationException(
                        "Unimplemented mock service");
            }

            public Serializable getAttribute(String name) {
                throw new UnsupportedOperationException(
                        "Unimplemented mock service");
            }

            public Iterator getAttributeNames() {
                throw new UnsupportedOperationException(
                        "Unimplemented mock service");
            }

            public boolean hasAttributes() {
                throw new UnsupportedOperationException(
                        "Unimplemented mock service");
            }

            public Serializable removeAttribute(String name) {
                throw new UnsupportedOperationException(
                        "Unimplemented mock service");
            }

            public void removeAllAttributes() {
                throw new UnsupportedOperationException(
                        "Unimplemented mock service");
            }

            public Serializable setAttribute(String name, Serializable object) {
                throw new UnsupportedOperationException(
                        "Unimplemented mock service");
            }

            public long getMessageSize() throws MessagingException {
                throw new UnsupportedOperationException(
                        "Unimplemented mock service");
            }

            public Date getLastUpdated() {
                throw new UnsupportedOperationException(
                        "Unimplemented mock service");
            }

            public void setLastUpdated(Date lastUpdated) {
                throw new UnsupportedOperationException(
                        "Unimplemented mock service");
            }

        };

    }

    protected void setupDNSServer() {
        dnsServer = new DNSServer() {

            public Collection findMXRecords(String hostname) {
                // TODO Auto-generated method stub
                return null;
            }

            public Collection findTXTRecords(String hostname) {
                // TODO Auto-generated method stub
                return null;
            }

            public Iterator getSMTPHostAddresses(String domainName) {
                // TODO Auto-generated method stub
                return null;
            }

            public InetAddress[] getAllByName(String host)
                    throws UnknownHostException {
                // TODO Auto-generated method stub
                return null;
            }

            public InetAddress getByName(String host)
                    throws UnknownHostException {
                // TODO Auto-generated method stub
                return InetAddress.getByName(host);
            }

        };
    }

    protected void setupMatcher() throws MessagingException {
        m_serviceManager = new MockServiceManager();
        m_serviceManager.put(DNSServer.ROLE, dnsServer);

        MockMailContext mmc = new MockMailContext();
        mmc.setAttribute(Constants.AVALON_COMPONENT_MANAGER, m_serviceManager);
        matcher = createMatcher();
        MockMatcherConfig mci = new MockMatcherConfig(getConfigOption()
                + getAllowedNetworks(), mmc);
        matcher.init(mci);
    }

    protected void setupAll() throws MessagingException {
        setupDNSServer();
        setupMockedMail();
        setupMatcher();
    }

    protected abstract String getConfigOption();

    protected abstract String getAllowedNetworks();

    protected abstract AbstractNetworkMatcher createMatcher();
}

@@ -6899,70 +6899,102 @@
     
-// TODO Auto-generated method stub%0A                return null
+throw new UnsupportedOperationException(%0A                        %22Unimplemented mock service%22)
 ;%0A  
@@ -7090,70 +7090,102 @@
     
-// TODO Auto-generated method stub%0A                return null
+throw new UnsupportedOperationException(%0A                        %22Unimplemented mock service%22)
 ;%0A  
@@ -7287,70 +7287,102 @@
     
-// TODO Auto-generated method stub%0A                return null
+throw new UnsupportedOperationException(%0A                        %22Unimplemented mock service%22)
 ;%0A  
@@ -7523,70 +7523,102 @@
     
-// TODO Auto-generated method stub%0A                return null
+throw new UnsupportedOperationException(%0A                        %22Unimplemented mock service%22)
 ;%0A  
@@ -7738,59 +7738,8 @@
 n %7B%0A
-                // TODO Auto-generated method stub%0A
     

Replace the null returns with throwing exceptions.. forget this before :-/