aboutsummaryrefslogtreecommitdiff
path: root/java/test/com/android/i18n/addressinput/JsonpRequestBuilderTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/test/com/android/i18n/addressinput/JsonpRequestBuilderTest.java')
-rw-r--r--java/test/com/android/i18n/addressinput/JsonpRequestBuilderTest.java240
1 files changed, 120 insertions, 120 deletions
diff --git a/java/test/com/android/i18n/addressinput/JsonpRequestBuilderTest.java b/java/test/com/android/i18n/addressinput/JsonpRequestBuilderTest.java
index 392a68e..9a40d1a 100644
--- a/java/test/com/android/i18n/addressinput/JsonpRequestBuilderTest.java
+++ b/java/test/com/android/i18n/addressinput/JsonpRequestBuilderTest.java
@@ -27,131 +27,131 @@ import java.net.Socket;
import java.net.SocketTimeoutException;
public class JsonpRequestBuilderTest extends AsyncTestCase {
- private JsonpRequestBuilder builder;
-
- @Override
- public void setUp() {
- builder = new JsonpRequestBuilder();
- }
-
- public void testRequestObject() throws Exception {
- delayTestFinish(4000);
- builder.setTimeout(2000);
-
- String url = HttpServer.execute(1000, "{\"id\": \"data\"}");
-
- builder.requestObject(url, new AsyncCallback<JsoMap>() {
- @Override
- public void onFailure(Throwable caught) {
- fail(caught.toString());
- }
-
- @Override
- public void onSuccess(JsoMap result) {
- assertNotNull(result);
- assertEquals("data", result.get("id"));
- finishTest();
- }
- });
- }
-
- public void testSetTimeout() throws Exception {
- delayTestFinish(4000);
- builder.setTimeout(1000);
-
- String url = HttpServer.execute(2000, "Fubar");
-
- builder.requestObject(url, new AsyncCallback<JsoMap>() {
- @Override
- public void onFailure(Throwable caught) {
- assertNotNull(caught);
- assertTrue(caught instanceof SocketTimeoutException);
- finishTest();
- }
-
- @Override
- public void onSuccess(JsoMap result) {
- fail("The request should have timed out.");
- }
- });
- }
-
- public void testUrlEncoding() throws Exception {
- delayTestFinish(4000);
- builder.setTimeout(2000);
-
- String urlBase = HttpServer.execute(1000, "{\"id\": \"data\"}");
- String url = urlBase + "address/data/VN/B\u1EAFc K\u1EA1n";
-
- builder.requestObject(url, new AsyncCallback<JsoMap>() {
- @Override
- public void onFailure(Throwable caught) {
- fail(caught.toString());
- }
-
- @Override
- public void onSuccess(JsoMap result) {
- assertNotNull(result);
- assertEquals("data", result.get("id"));
- finishTest();
- }
- });
- }
-
+ private JsonpRequestBuilder builder;
+
+ @Override
+ public void setUp() {
+ builder = new JsonpRequestBuilder();
+ }
+
+ public void testRequestObject() throws Exception {
+ delayTestFinish(4000);
+ builder.setTimeout(2000);
+
+ String url = HttpServer.execute(1000, "{\"id\": \"data\"}");
+
+ builder.requestObject(url, new AsyncCallback<JsoMap>() {
+ @Override
+ public void onFailure(Throwable caught) {
+ fail(caught.toString());
+ }
+
+ @Override
+ public void onSuccess(JsoMap result) {
+ assertNotNull(result);
+ assertEquals("data", result.get("id"));
+ finishTest();
+ }
+ });
+ }
+
+ public void testSetTimeout() throws Exception {
+ delayTestFinish(4000);
+ builder.setTimeout(1000);
+
+ String url = HttpServer.execute(2000, "Fubar");
+
+ builder.requestObject(url, new AsyncCallback<JsoMap>() {
+ @Override
+ public void onFailure(Throwable caught) {
+ assertNotNull(caught);
+ assertTrue(caught instanceof SocketTimeoutException);
+ finishTest();
+ }
+
+ @Override
+ public void onSuccess(JsoMap result) {
+ fail("The request should have timed out.");
+ }
+ });
+ }
+
+ public void testUrlEncoding() throws Exception {
+ delayTestFinish(4000);
+ builder.setTimeout(2000);
+
+ String urlBase = HttpServer.execute(1000, "{\"id\": \"data\"}");
+ String url = urlBase + "address/data/VN/B\u1EAFc K\u1EA1n";
+
+ builder.requestObject(url, new AsyncCallback<JsoMap>() {
+ @Override
+ public void onFailure(Throwable caught) {
+ fail(caught.toString());
+ }
+
+ @Override
+ public void onSuccess(JsoMap result) {
+ assertNotNull(result);
+ assertEquals("data", result.get("id"));
+ finishTest();
+ }
+ });
+ }
+
+ /**
+ * Simple implementation of an HTTP server.
+ */
+ private static class HttpServer extends Thread {
/**
- * Simple implementation of an HTTP server.
+ * Start an HTTP server that will serve one request and then terminate.
+ *
+ * @param timeoutMillis
+ * Wait this long before answering a request.
+ * @param response
+ * Reply to any request with this response.
+ * @return The URL to the server.
+ * @throws IOException
*/
- private static class HttpServer extends Thread {
- /**
- * Start an HTTP server that will serve one request and then terminate.
- *
- * @param timeoutMillis
- * Wait this long before answering a request.
- * @param response
- * Reply to any request with this response.
- * @return The URL to the server.
- * @throws IOException
- */
- public static String execute(long timeoutMillis, String response) throws IOException {
- HttpServer server = new HttpServer(timeoutMillis, response);
- server.start();
- return "http://localhost:" + server.serverSocket.getLocalPort() + "/";
- }
+ public static String execute(long timeoutMillis, String response) throws IOException {
+ HttpServer server = new HttpServer(timeoutMillis, response);
+ server.start();
+ return "http://localhost:" + server.serverSocket.getLocalPort() + "/";
+ }
- @Override
- public void run() {
- try {
- Socket clientSocket = serverSocket.accept();
- try {
- synchronized (this) {
- wait(waitMillis);
- }
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- InputStream inputStream = clientSocket.getInputStream();
- inputStream.read(new byte[1024]); // Discard input.
- OutputStream outputStream = clientSocket.getOutputStream();
- outputStream.write(response);
- outputStream.close();
- inputStream.close();
- clientSocket.close();
- serverSocket.close();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
+ @Override
+ public void run() {
+ try {
+ Socket clientSocket = serverSocket.accept();
+ try {
+ synchronized (this) {
+ wait(waitMillis);
+ }
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
}
+ InputStream inputStream = clientSocket.getInputStream();
+ inputStream.read(new byte[1024]); // Discard input.
+ OutputStream outputStream = clientSocket.getOutputStream();
+ outputStream.write(response);
+ outputStream.close();
+ inputStream.close();
+ clientSocket.close();
+ serverSocket.close();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
- private HttpServer(long waitMillis, String response) throws IOException {
- this.waitMillis = waitMillis;
- this.response = (header + response).getBytes();
- serverSocket = new ServerSocket(0);
- }
+ private HttpServer(long waitMillis, String response) throws IOException {
+ this.waitMillis = waitMillis;
+ this.response = (header + response).getBytes();
+ serverSocket = new ServerSocket(0);
+ }
- private long waitMillis;
- private byte[] response;
- private ServerSocket serverSocket;
+ private long waitMillis;
+ private byte[] response;
+ private ServerSocket serverSocket;
- private static final String header = "HTTP/1.0 200 OK\nContent-Type: text/plain\n\n";
- }
+ private static final String header = "HTTP/1.0 200 OK\nContent-Type: text/plain\n\n";
+ }
}