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