/**
 * Copyright (C) 2012-2014 Gist Labs, LLC. (http://gistlabs.com)
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package com.gistlabs.mechanize;

import static junit.framework.Assert.*;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpRequestBase;

import com.gistlabs.mechanize.impl.MechanizeAgent;
import com.gistlabs.mechanize.parameters.Parameters;

/**
 * @author Martin Kersten<Martin.Kersten.mk@gmail.com>
 */
public class MechanizeMock extends MechanizeAgent {

	final List<PageRequest> requests = new ArrayList<PageRequest>();

	@Deprecated
	public PageRequest addPageRequest(final String uri, final String body) {
		return addPageRequest("GET", uri, body);
	}

	@Deprecated
	public PageRequest addPageRequest(final String method, final String uri, final String body) {
		PageRequest request = new PageRequest(method, uri, body);
		requests.add(request);
		return request;
	}

	@Deprecated
	public PageRequest addPageRequest(final String method, final String uri, final InputStream body) {
		PageRequest request = new PageRequest(method, uri, body);
		requests.add(request);
		return request;
	}

	@Deprecated
	public PageRequest addPageRequest(final String method, final String uri, final Parameters parameters, final String body) {
		PageRequest request = new PageRequest(method, uri, parameters, body);
		requests.add(request);
		return request;
	}

	@Override
	protected HttpResponse execute(final HttpClient client, final HttpRequestBase request) throws Exception {
		PageRequest pageRequest = nextUnexecutedPageRequest();
		if(pageRequest != null)
			return pageRequest.consume(client, request);
		else {
			fail("No open page requests");
			return null;
		}
	}

	public PageRequest nextUnexecutedPageRequest() {
		for(PageRequest pageRequest : requests)
			if(!pageRequest.wasExecuted())
				return pageRequest;
		return null;
	}
}

@@ -345,39 +345,14 @@
 ert.
-*;%0A%0Aimport java.io.InputStream;
+fail;%0A
 %0Aimp
@@ -589,61 +589,8 @@
 ent;
-%0Aimport com.gistlabs.mechanize.parameters.Parameters;
 %0A%0A/*
@@ -650,23 +650,16 @@
 om%3E%0A */%0A
-public 
 class Me
@@ -767,833 +767,8 @@
 );%0A%0A
-%09@Deprecated%0A%09public PageRequest addPageRequest(final String uri, final String body) %7B%0A%09%09return addPageRequest(%22GET%22, uri, body);%0A%09%7D%0A%0A%09@Deprecated%0A%09public PageRequest addPageRequest(final String method, final String uri, final String body) %7B%0A%09%09PageRequest request = new PageRequest(method, uri, body);%0A%09%09requests.add(request);%0A%09%09return request;%0A%09%7D%0A%0A%09@Deprecated%0A%09public PageRequest addPageRequest(final String method, final String uri, final InputStream body) %7B%0A%09%09PageRequest request = new PageRequest(method, uri, body);%0A%09%09requests.add(request);%0A%09%09return request;%0A%09%7D%0A%0A%09@Deprecated%0A%09public PageRequest addPageRequest(final String method, final String uri, final Parameters parameters, final String body) %7B%0A%09%09PageRequest request = new PageRequest(method, uri, parameters, body);%0A%09%09requests.add(request);%0A%09%09return request;%0A%09%7D%0A%0A
 %09@Ov

remove now deprecated methods from MechanizeMock