blob: 724399c91d16c0447b5377e8698582dad6aee520 [file] [log] [blame]
chrismair00dc7bd2014-05-11 21:21:28 +00001/*
2 * Copyright 2007 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.mockftpserver.core.socket;
17
18import java.io.IOException;
19import java.net.InetAddress;
20import java.net.Socket;
21
22/**
23 * Test-only implementation of SocketFactory. It always returns the predefined
24 * StubSocket instance specified on the constructor. It allows direct access to the
25 * requested host address and port number.
26 *
27 * @version $Revision$ - $Date$
28 *
29 * @author Chris Mair
30 */
31public class StubSocketFactory implements SocketFactory {
32 private StubSocket stubSocket;
33 public int requestedDataPort;
34 public InetAddress requestedHost;
35
36 /**
37 * Create a new instance that always returns the specified StubSocket instance.
38 * @param stubSocket - the StubSocket to be returned by this factory
39 */
40 public StubSocketFactory(StubSocket stubSocket) {
41 this.stubSocket = stubSocket;
42 }
43
44 /**
45 * Return the predefined StubSocket instance
46 * @see org.mockftpserver.core.socket.SocketFactory#createSocket(java.net.InetAddress, int)
47 */
48 public Socket createSocket(InetAddress host, int port) throws IOException {
49 this.requestedHost = host;
50 this.requestedDataPort = port;
51 return stubSocket;
52 }
53}