Skip to content

Commit 43b39f5

Browse files
committed
1 parent 0758d02 commit 43b39f5

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

examples/TestCaseExampleUsage.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import java.util.concurrent.CountDownLatch;
2+
import java.util.concurrent.TimeUnit;
3+
4+
import com.loopj.android.http.AsyncHttpClient;
5+
import com.loopj.android.http.AsyncHttpResponseHandler;
6+
7+
import android.test.InstrumentationTestCase;
8+
import android.util.Log;
9+
10+
// Credits to Wuyexiong <[email protected]>
11+
// See: https://github.com/loopj/android-async-http/pull/236
12+
public class TestCaseExampleUsage extends InstrumentationTestCase
13+
{
14+
protected String TAG = TestCaseExampleUsage.class.getSimpleName();
15+
16+
public void testAsync() throws Throwable
17+
{
18+
final CountDownLatch signal = new CountDownLatch(1);
19+
runTestOnUiThread(new Runnable()
20+
{
21+
@Override
22+
public void run()
23+
{
24+
AsyncHttpClient client = new AsyncHttpClient();
25+
26+
client.get("http://www.google.com", new AsyncHttpResponseHandler()
27+
{
28+
@Override
29+
public void onStart()
30+
{
31+
Log.v(TAG , "onStart");
32+
}
33+
34+
@Override
35+
public void onSuccess(String response)
36+
{
37+
Log.v(TAG , "onSuccess");
38+
System.out.println(response);
39+
}
40+
41+
@Override
42+
public void onFailure(Throwable error, String content)
43+
{
44+
Log.e(TAG , "onFailure error : " + error.toString() + "content : " + content);
45+
}
46+
47+
@Override
48+
public void onFinish()
49+
{
50+
Log.v(TAG , "onFinish");
51+
signal.countDown();
52+
}
53+
});
54+
55+
try {
56+
signal.await(30, TimeUnit.SECONDS);
57+
} catch (InterruptedException e) {
58+
}
59+
Log.v(TAG , "TestCaseExampleUsage Over");
60+
}
61+
});
62+
}
63+
}

0 commit comments

Comments
 (0)