aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/com/android/inputmethod/latin/network/BlockingHttpClientTests.java
diff options
context:
space:
mode:
authorYohei Yukawa <yukawa@google.com>2018-07-06 10:10:54 -0700
committerYohei Yukawa <yukawa@google.com>2018-07-06 10:10:54 -0700
commitd3b93cc95061ada6a162d7989e313f818e6d4e15 (patch)
treea4e3eaee6b84d20817d82b2a263e0e47bcc98753 /tests/src/com/android/inputmethod/latin/network/BlockingHttpClientTests.java
parenta497886dda70bbd401652560d11d8f4010985e96 (diff)
downloadlatinime-d3b93cc95061ada6a162d7989e313f818e6d4e15.tar.gz
latinime-d3b93cc95061ada6a162d7989e313f818e6d4e15.tar.xz
latinime-d3b93cc95061ada6a162d7989e313f818e6d4e15.zip
Migrate to Android Testing Support Lib (part 5/N)
This CL converts 19 test classes under com.android.inputmethod.latin to Android Testing Support Library. Bug: 110805255 Test: verified as follows. No new test failures. tapas adb LatinIME LatinIMETests arm64 userdebug && \ DISABLE_PROGUARD=true make -j LatinIME && \ adb install -r $OUT/system/app/LatinIME/LatinIME.apk && \ atest LatinIMETests:com.android.inputmethod.latin Change-Id: I878fcae0126f57c43a644af341e5a0a8ac8f5cc9
Diffstat (limited to 'tests/src/com/android/inputmethod/latin/network/BlockingHttpClientTests.java')
-rw-r--r--tests/src/com/android/inputmethod/latin/network/BlockingHttpClientTests.java24
1 files changed, 18 insertions, 6 deletions
diff --git a/tests/src/com/android/inputmethod/latin/network/BlockingHttpClientTests.java b/tests/src/com/android/inputmethod/latin/network/BlockingHttpClientTests.java
index 8f24cdb44..bdbbaf2e6 100644
--- a/tests/src/com/android/inputmethod/latin/network/BlockingHttpClientTests.java
+++ b/tests/src/com/android/inputmethod/latin/network/BlockingHttpClientTests.java
@@ -16,13 +16,16 @@
package com.android.inputmethod.latin.network;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
import com.android.inputmethod.latin.network.BlockingHttpClient.ResponseProcessor;
@@ -40,19 +43,24 @@ import java.net.HttpURLConnection;
import java.util.Arrays;
import java.util.Random;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
/**
* Tests for {@link BlockingHttpClient}.
*/
@SmallTest
-public class BlockingHttpClientTests extends AndroidTestCase {
+@RunWith(AndroidJUnit4.class)
+public class BlockingHttpClientTests {
@Mock HttpURLConnection mMockHttpConnection;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
}
+ @Test
public void testError_badGateway() throws IOException, AuthException {
when(mMockHttpConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_BAD_GATEWAY);
final BlockingHttpClient client = new BlockingHttpClient(mMockHttpConnection);
@@ -67,6 +75,7 @@ public class BlockingHttpClientTests extends AndroidTestCase {
}
}
+ @Test
public void testError_clientTimeout() throws Exception {
when(mMockHttpConnection.getResponseCode()).thenReturn(
HttpURLConnection.HTTP_CLIENT_TIMEOUT);
@@ -82,6 +91,7 @@ public class BlockingHttpClientTests extends AndroidTestCase {
}
}
+ @Test
public void testError_forbiddenWithRequest() throws Exception {
final OutputStream mockOutputStream = Mockito.mock(OutputStream.class);
when(mMockHttpConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_FORBIDDEN);
@@ -98,6 +108,7 @@ public class BlockingHttpClientTests extends AndroidTestCase {
verify(mockOutputStream).write(any(byte[].class), eq(0), eq(100));
}
+ @Test
public void testSuccess_emptyRequest() throws Exception {
final Random rand = new Random();
byte[] response = new byte[100];
@@ -112,6 +123,7 @@ public class BlockingHttpClientTests extends AndroidTestCase {
assertTrue("ResponseProcessor was not invoked", processor.mInvoked);
}
+ @Test
public void testSuccess() throws Exception {
final OutputStream mockOutputStream = Mockito.mock(OutputStream.class);
final Random rand = new Random();