// Path: core/src/main/java/net/javacrumbs/mocksocket/MockSocketException.java
// public class MockSocketException extends RuntimeException {
// 	private static final long serialVersionUID = -6476984055059688027L;
// 
// 	public MockSocketException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 
// 	public MockSocketException(String message) {
// 		super(message);
// 	}
// 
// 	public MockSocketException(Throwable cause) {
// 		super(cause);
// 	}
// 
// 
// }
// 
// Path: core/src/main/java/net/javacrumbs/mocksocket/connection/AbstractMockConnectionFactory.java
// public abstract class AbstractMockConnectionFactory implements RequestRecorder, ConnectionFactory {
// 
// 	private final List<OutputSocketData> requestData = new ArrayList<OutputSocketData>();
// 	private int actualConnection = -1;
// 	
// 	public synchronized Connection createConnection(String address) {
// 		actualConnection++;
// 		requestData.add(createRequestSocket(address));
// 		
// 		return new DefaultConnection(createInputStream(), getRequestSocketData().getOutputStream());
// 	}
// 
// 	protected OutputSocketData createRequestSocket(String address) {
// 		return new OutputSocketData(address);
// 	}
// 
// 	protected abstract InputStream createInputStream();
// 
// 	protected synchronized OutputSocketData getRequestSocketData() {
// 		return requestData.get(actualConnection);
// 	}
// 	
// 	public synchronized List<RequestSocketData> requestData() {
// 		return new ArrayList<RequestSocketData>(requestData);
// 	}
// 
// 	protected synchronized int getActualConnection() {
// 		return actualConnection;
// 	}
// }
// 
// Path: core/src/main/java/net/javacrumbs/mocksocket/connection/RequestRecorder.java
// public interface RequestRecorder {
// 	public List<RequestSocketData> requestData();
// }
// 
// Path: core/src/main/java/net/javacrumbs/mocksocket/connection/data/SocketData.java
// public interface SocketData {
// 
// 	public InputStream getData();
// }


import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import net.javacrumbs.mocksocket.MockSocketException;
import net.javacrumbs.mocksocket.connection.AbstractMockConnectionFactory;
import net.javacrumbs.mocksocket.connection.RequestRecorder;
import net.javacrumbs.mocksocket.connection.data.SocketData;
/**
 * Copyright 2009-2011 the original author or authors.
 *
 * 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 net.javacrumbs.mocksocket.connection.sequential;



/**
 * Mock connection. Can simulate multiple requests to the same address.
 * @author Lukas Krecan
 *
 */
public class SequentialMockConnectionFactory extends AbstractMockConnectionFactory implements RequestRecorder, SequentialMockRecorder{
	private final List<SocketData> responseData = new ArrayList<SocketData>();
	public SequentialMockConnectionFactory() {
	}

	public SequentialMockRecorder andReturn(SocketData data) {
		this.responseData.add(data);
		return this;
	}
	
	protected InputStream createInputStream() {
		int actualConnection = getActualConnection();
		if (responseData.size()>actualConnection )
		{
			return responseData.get(actualConnection).getData();
		}
		else
		{
// Path: core/src/main/java/net/javacrumbs/mocksocket/MockSocketException.java
// public class MockSocketException extends RuntimeException {
// 	private static final long serialVersionUID = -6476984055059688027L;
// 
// 	public MockSocketException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 
// 	public MockSocketException(String message) {
// 		super(message);
// 	}
// 
// 	public MockSocketException(Throwable cause) {
// 		super(cause);
// 	}
// 
// 
// }
// 
// Path: core/src/main/java/net/javacrumbs/mocksocket/connection/AbstractMockConnectionFactory.java
// public abstract class AbstractMockConnectionFactory implements RequestRecorder, ConnectionFactory {
// 
// 	private final List<OutputSocketData> requestData = new ArrayList<OutputSocketData>();
// 	private int actualConnection = -1;
// 	
// 	public synchronized Connection createConnection(String address) {
// 		actualConnection++;
// 		requestData.add(createRequestSocket(address));
// 		
// 		return new DefaultConnection(createInputStream(), getRequestSocketData().getOutputStream());
// 	}
// 
// 	protected OutputSocketData createRequestSocket(String address) {
// 		return new OutputSocketData(address);
// 	}
// 
// 	protected abstract InputStream createInputStream();
// 
// 	protected synchronized OutputSocketData getRequestSocketData() {
// 		return requestData.get(actualConnection);
// 	}
// 	
// 	public synchronized List<RequestSocketData> requestData() {
// 		return new ArrayList<RequestSocketData>(requestData);
// 	}
// 
// 	protected synchronized int getActualConnection() {
// 		return actualConnection;
// 	}
// }
// 
// Path: core/src/main/java/net/javacrumbs/mocksocket/connection/RequestRecorder.java
// public interface RequestRecorder {
// 	public List<RequestSocketData> requestData();
// }
// 
// Path: core/src/main/java/net/javacrumbs/mocksocket/connection/data/SocketData.java
// public interface SocketData {
// 
// 	public InputStream getData();
// }


// Path: core/src/main/java/net/javacrumbs/mocksocket/connection/sequential/SequentialMockConnectionFactory.java
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import net.javacrumbs.mocksocket.MockSocketException;
import net.javacrumbs.mocksocket.connection.AbstractMockConnectionFactory;
import net.javacrumbs.mocksocket.connection.RequestRecorder;
import net.javacrumbs.mocksocket.connection.data.SocketData;

/**
 * Copyright 2009-2011 the original author or authors.
 *
 * 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 net.javacrumbs.mocksocket.connection.sequential;



/**
 * Mock connection. Can simulate multiple requests to the same address.
 * @author Lukas Krecan
 *
 */
public class SequentialMockConnectionFactory extends AbstractMockConnectionFactory implements RequestRecorder, SequentialMockRecorder{
	private final List<SocketData> responseData = new ArrayList<SocketData>();
	public SequentialMockConnectionFactory() {
	}

	public SequentialMockRecorder andReturn(SocketData data) {
		this.responseData.add(data);
		return this;
	}
	
	protected InputStream createInputStream() {
		int actualConnection = getActualConnection();
		if (responseData.size()>actualConnection )
		{
			return responseData.get(actualConnection).getData();
		}
		else
		{
			throw new MockSocketException("No more connections expected. Requests recorded so far are: "+requestData());