diff options
Diffstat (limited to 'tests/src/com/android/inputmethod/latin/network/BlockingHttpClientTests.java')
-rw-r--r-- | tests/src/com/android/inputmethod/latin/network/BlockingHttpClientTests.java | 24 |
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(); |