// Path: test/com/fieldexpert/fbapi4j/common/IOUtil.java
// public static String string(File file) throws java.io.IOException {
// 	return string(new FileInputStream(file));
// }
// 
// Path: src/com/fieldexpert/fbapi4j/common/Attachment.java
// public class Attachment {
// 
// 	static {
// 		registerMimeDetector(ExtensionMimeDetector.class.getName());
// 		registerMimeDetector(MagicMimeMimeDetector.class.getName());
// 	}
// 
// 	public static String getType(File file) {
// 		Collection<?> types = getMimeTypes(file);
// 		return getMostSpecificMimeType(types).toString();
// 	}
// 
// 	public static String getType(InputStream is) {
// 		Collection<?> types = getMimeTypes(is);
// 		return getMostSpecificMimeType(types).toString();
// 	}
// 
// 	public static String getType(byte[] bytes) {
// 		Collection<?> types = getMimeTypes(bytes);
// 		return getMostSpecificMimeType(types).toString();
// 	}
// 
// 	private String filename;
// 	private String type;
// 	private InputStream content;
// 
// 	// not for you
// 	protected Attachment(String name) {
// 		this.filename = name;
// 	}
// 
// 	public Attachment(String filename, String type, byte[] content) {
// 		this(filename, type, new ByteArrayInputStream(content));
// 	}
// 
// 	public Attachment(String filename, String type, String content) {
// 		this(filename, type, content.getBytes(Charset.forName("UTF-8")));
// 	}
// 
// 	public Attachment(String filename, String type, InputStream content) {
// 		this.filename = filename;
// 		this.type = type;
// 		this.content = content;
// 	}
// 
// 	// can't chain this constructor call, because we need to try/catch
// 	public Attachment(File file) {
// 		Assert.notNull(file);
// 
// 		this.filename = file.getName();
// 		this.type = getType(file);
// 		try {
// 			this.content = new FileInputStream(file);
// 		} catch (Exception e) {
// 			throw new RuntimeException("Error reading file: '" + file.getName() + "'");
// 		}
// 	}
// 
// 	public InputStream getContent() {
// 		return content;
// 	}
// 
// 	public String getFilename() {
// 		return filename;
// 	}
// 
// 	public String getType() {
// 		return type;
// 	}
// }
// 
// Path: test/com/fieldexpert/fbapi4j/http/server/MockServer.java
// public class MockServer {
// 	private final HttpServer server;
// 
// 	public MockServer(String path) {
// 		this("127.0.0.1", 9000, path);
// 	}
// 
// 	public MockServer(int port, String path) {
// 		this("127.0.0.1", port, path);
// 	}
// 
// 	public MockServer(String host, int port, String path) {
// 		InetSocketAddress address = new InetSocketAddress(host, port);
// 		try {
// 			server = HttpServer.create(address, 0);
// 			HttpContext context = server.createContext(path, new EchoHandler());
// 			context.getFilters().add(new ParamsFilter());
// 		} catch (IOException e) {
// 			throw new RuntimeException("Unable to create server on " + host + ":" + port);
// 		}
// 	}
// 
// 	public void start() {
// 		server.start();
// 	}
// 
// 	public void stop() {
// 		if (server == null) {
// 			return;
// 		}
// 		server.stop(0);
// 	}
// 
// }


import static com.fieldexpert.fbapi4j.common.IOUtil.string;
import static java.util.Arrays.asList;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import com.fieldexpert.fbapi4j.common.Attachment;
import com.fieldexpert.fbapi4j.http.server.MockServer;
package com.fieldexpert.fbapi4j.http;





public class HttpTest {

	private static MockServer server;
	private static URL url;
	private Map<String, String> params;

	@Test
	public void get() throws IOException {
		InputStream is = Http.get(url, params);

		BufferedReader br = new BufferedReader(new InputStreamReader(is));
		Map<String, String> returnedParams = params(br.readLine());

		assertEquals(params, returnedParams);
	}

	@Test
	public void post() throws IOException {
		InputStream is = Http.post(url, params);

		BufferedReader br = new BufferedReader(new InputStreamReader(is));
		Map<String, String> returnedParams = params(br.readLine());

		assertEquals(params, returnedParams);
	}

	@Test
	public void attachment() throws IOException {
		List<Attachment> attachments = asList(new Attachment("foo.txt", "text/plain", "This is my test file."));
		InputStream is = Http.post(url, params, attachments);

// Path: test/com/fieldexpert/fbapi4j/common/IOUtil.java
// public static String string(File file) throws java.io.IOException {
// 	return string(new FileInputStream(file));
// }
// 
// Path: src/com/fieldexpert/fbapi4j/common/Attachment.java
// public class Attachment {
// 
// 	static {
// 		registerMimeDetector(ExtensionMimeDetector.class.getName());
// 		registerMimeDetector(MagicMimeMimeDetector.class.getName());
// 	}
// 
// 	public static String getType(File file) {
// 		Collection<?> types = getMimeTypes(file);
// 		return getMostSpecificMimeType(types).toString();
// 	}
// 
// 	public static String getType(InputStream is) {
// 		Collection<?> types = getMimeTypes(is);
// 		return getMostSpecificMimeType(types).toString();
// 	}
// 
// 	public static String getType(byte[] bytes) {
// 		Collection<?> types = getMimeTypes(bytes);
// 		return getMostSpecificMimeType(types).toString();
// 	}
// 
// 	private String filename;
// 	private String type;
// 	private InputStream content;
// 
// 	// not for you
// 	protected Attachment(String name) {
// 		this.filename = name;
// 	}
// 
// 	public Attachment(String filename, String type, byte[] content) {
// 		this(filename, type, new ByteArrayInputStream(content));
// 	}
// 
// 	public Attachment(String filename, String type, String content) {
// 		this(filename, type, content.getBytes(Charset.forName("UTF-8")));
// 	}
// 
// 	public Attachment(String filename, String type, InputStream content) {
// 		this.filename = filename;
// 		this.type = type;
// 		this.content = content;
// 	}
// 
// 	// can't chain this constructor call, because we need to try/catch
// 	public Attachment(File file) {
// 		Assert.notNull(file);
// 
// 		this.filename = file.getName();
// 		this.type = getType(file);
// 		try {
// 			this.content = new FileInputStream(file);
// 		} catch (Exception e) {
// 			throw new RuntimeException("Error reading file: '" + file.getName() + "'");
// 		}
// 	}
// 
// 	public InputStream getContent() {
// 		return content;
// 	}
// 
// 	public String getFilename() {
// 		return filename;
// 	}
// 
// 	public String getType() {
// 		return type;
// 	}
// }
// 
// Path: test/com/fieldexpert/fbapi4j/http/server/MockServer.java
// public class MockServer {
// 	private final HttpServer server;
// 
// 	public MockServer(String path) {
// 		this("127.0.0.1", 9000, path);
// 	}
// 
// 	public MockServer(int port, String path) {
// 		this("127.0.0.1", port, path);
// 	}
// 
// 	public MockServer(String host, int port, String path) {
// 		InetSocketAddress address = new InetSocketAddress(host, port);
// 		try {
// 			server = HttpServer.create(address, 0);
// 			HttpContext context = server.createContext(path, new EchoHandler());
// 			context.getFilters().add(new ParamsFilter());
// 		} catch (IOException e) {
// 			throw new RuntimeException("Unable to create server on " + host + ":" + port);
// 		}
// 	}
// 
// 	public void start() {
// 		server.start();
// 	}
// 
// 	public void stop() {
// 		if (server == null) {
// 			return;
// 		}
// 		server.stop(0);
// 	}
// 
// }


// Path: test/com/fieldexpert/fbapi4j/http/HttpTest.java
import static com.fieldexpert.fbapi4j.common.IOUtil.string;
import static java.util.Arrays.asList;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import com.fieldexpert.fbapi4j.common.Attachment;
import com.fieldexpert.fbapi4j.http.server.MockServer;

package com.fieldexpert.fbapi4j.http;





public class HttpTest {

	private static MockServer server;
	private static URL url;
	private Map<String, String> params;

	@Test
	public void get() throws IOException {
		InputStream is = Http.get(url, params);

		BufferedReader br = new BufferedReader(new InputStreamReader(is));
		Map<String, String> returnedParams = params(br.readLine());

		assertEquals(params, returnedParams);
	}

	@Test
	public void post() throws IOException {
		InputStream is = Http.post(url, params);

		BufferedReader br = new BufferedReader(new InputStreamReader(is));
		Map<String, String> returnedParams = params(br.readLine());

		assertEquals(params, returnedParams);
	}

	@Test
	public void attachment() throws IOException {
		List<Attachment> attachments = asList(new Attachment("foo.txt", "text/plain", "This is my test file."));
		InputStream is = Http.post(url, params, attachments);

		Map<String, String> returnedParams = params(string(is));