aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRalph Bergmann <ralph@the4thfloor.eu>2015-02-23 18:57:48 +0100
committerRalph Bergmann <ralph@the4thfloor.eu>2015-02-25 12:39:36 +0100
commite1f0d61968d5194088c18f00b1bcfc46a91adbfd (patch)
tree252f9f00844062085f786b2f729f5e3606b8fa12 /src
parentee454371157d9a3fb74b70ee8ba93cf96559acf3 (diff)
downloadvolley-e1f0d61968d5194088c18f00b1bcfc46a91adbfd.tar.gz
add test for public api
add test for public api. not for all classes but for the most important ones Change-Id: I494f60568c6caafc23754154fe930d9f90a3bde0
Diffstat (limited to 'src')
-rw-r--r--src/test/java/com/android/volley/toolbox/CacheTest.java39
-rw-r--r--src/test/java/com/android/volley/toolbox/DiskBasedCacheTest.java14
-rw-r--r--src/test/java/com/android/volley/toolbox/ImageLoaderTest.java19
-rw-r--r--src/test/java/com/android/volley/toolbox/ImageRequestTest.java11
-rw-r--r--src/test/java/com/android/volley/toolbox/JsonRequestTest.java46
-rw-r--r--src/test/java/com/android/volley/toolbox/NetworkImageViewTest.java16
-rw-r--r--src/test/java/com/android/volley/toolbox/RequestFutureTest.java35
-rw-r--r--src/test/java/com/android/volley/toolbox/RequestQueueTest.java46
-rw-r--r--src/test/java/com/android/volley/toolbox/RequestTest.java69
-rw-r--r--src/test/java/com/android/volley/toolbox/ResponseTest.java53
-rw-r--r--src/test/java/com/android/volley/toolbox/StringRequestTest.java37
11 files changed, 383 insertions, 2 deletions
diff --git a/src/test/java/com/android/volley/toolbox/CacheTest.java b/src/test/java/com/android/volley/toolbox/CacheTest.java
new file mode 100644
index 0000000..dcd8a27
--- /dev/null
+++ b/src/test/java/com/android/volley/toolbox/CacheTest.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.volley.toolbox;
+
+import com.android.volley.Cache;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+
+import static org.junit.Assert.assertNotNull;
+
+@RunWith(RobolectricTestRunner.class)
+public class CacheTest {
+
+ @Test
+ public void publicMethods() throws Exception {
+ // Catch-all test to find API-breaking changes.
+ assertNotNull(Cache.class.getMethod("get", String.class));
+ assertNotNull(Cache.class.getMethod("put", String.class, Cache.Entry.class));
+ assertNotNull(Cache.class.getMethod("initialize"));
+ assertNotNull(Cache.class.getMethod("invalidate", String.class, boolean.class));
+ assertNotNull(Cache.class.getMethod("remove", String.class));
+ assertNotNull(Cache.class.getMethod("clear"));
+ }
+}
diff --git a/src/test/java/com/android/volley/toolbox/DiskBasedCacheTest.java b/src/test/java/com/android/volley/toolbox/DiskBasedCacheTest.java
index d9d49e9..bf1d258 100644
--- a/src/test/java/com/android/volley/toolbox/DiskBasedCacheTest.java
+++ b/src/test/java/com/android/volley/toolbox/DiskBasedCacheTest.java
@@ -22,6 +22,7 @@ import org.junit.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.File;
import java.util.HashMap;
import java.util.Map;
@@ -124,8 +125,8 @@ public class DiskBasedCacheTest {
assertEquals(DiskBasedCache.readStringStringMap(bais), emptyValue);
}
- // Test deserializing the old format into the new one.
- public void testCacheHeaderSerializationOldToNewFormat() throws Exception {
+ /** deserializing the old format into the new one. */
+ @Test public void testCacheHeaderSerializationOldToNewFormat() throws Exception {
final int CACHE_MAGIC = 0x20140623;
final String key = "key";
@@ -162,4 +163,13 @@ public class DiskBasedCacheTest {
// the old format doesn't know lastModified
assertEquals(cacheHeader.lastModified, 0);
}
+
+ @Test
+ public void publicMethods() throws Exception {
+ // Catch-all test to find API-breaking changes.
+ assertNotNull(DiskBasedCache.class.getConstructor(File.class, int.class));
+ assertNotNull(DiskBasedCache.class.getConstructor(File.class));
+
+ assertNotNull(DiskBasedCache.class.getMethod("getFileForKey", String.class));
+ }
}
diff --git a/src/test/java/com/android/volley/toolbox/ImageLoaderTest.java b/src/test/java/com/android/volley/toolbox/ImageLoaderTest.java
index 47c55a6..81de6fe 100644
--- a/src/test/java/com/android/volley/toolbox/ImageLoaderTest.java
+++ b/src/test/java/com/android/volley/toolbox/ImageLoaderTest.java
@@ -17,6 +17,7 @@
package com.android.volley.toolbox;
import android.graphics.Bitmap;
+import android.widget.ImageView;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import org.junit.Assert;
@@ -25,6 +26,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
+import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.*;
@RunWith(RobolectricTestRunner.class)
@@ -75,6 +77,23 @@ public class ImageLoaderTest {
// Catch API breaking changes.
ImageLoader.getImageListener(null, -1, -1);
mImageLoader.setBatchedResponseDelay(1000);
+
+ assertNotNull(ImageLoader.class.getConstructor(RequestQueue.class,
+ ImageLoader.ImageCache.class));
+
+ assertNotNull(ImageLoader.class.getMethod("getImageListener", ImageView.class,
+ int.class, int.class));
+ assertNotNull(ImageLoader.class.getMethod("isCached", String.class, int.class, int.class));
+ assertNotNull(ImageLoader.class.getMethod("get", String.class,
+ ImageLoader.ImageListener.class));
+ assertNotNull(ImageLoader.class.getMethod("get", String.class,
+ ImageLoader.ImageListener.class, int.class, int.class));
+ assertNotNull(ImageLoader.class.getMethod("get", String.class,
+ ImageLoader.ImageListener.class, int.class, int.class, ImageView.ScaleType.class));
+ assertNotNull(ImageLoader.class.getMethod("setBatchedResponseDelay", int.class));
+
+ assertNotNull(ImageLoader.ImageListener.class.getMethod("onResponse",
+ ImageLoader.ImageContainer.class, boolean.class));
}
}
diff --git a/src/test/java/com/android/volley/toolbox/ImageRequestTest.java b/src/test/java/com/android/volley/toolbox/ImageRequestTest.java
index bd98e7d..0ae774e 100644
--- a/src/test/java/com/android/volley/toolbox/ImageRequestTest.java
+++ b/src/test/java/com/android/volley/toolbox/ImageRequestTest.java
@@ -18,6 +18,7 @@ package com.android.volley.toolbox;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
+import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import com.android.volley.NetworkResponse;
import com.android.volley.Response;
@@ -158,4 +159,14 @@ public class ImageRequestTest {
in.close();
return bytes.toByteArray();
}
+
+ @Test
+ public void publicMethods() throws Exception {
+ // Catch-all test to find API-breaking changes.
+ assertNotNull(ImageRequest.class.getConstructor(String.class, Response.Listener.class,
+ int.class, int.class, Bitmap.Config.class, Response.ErrorListener.class));
+ assertNotNull(ImageRequest.class.getConstructor(String.class, Response.Listener.class,
+ int.class, int.class, ImageView.ScaleType.class, Bitmap.Config.class,
+ Response.ErrorListener.class));
+ }
}
diff --git a/src/test/java/com/android/volley/toolbox/JsonRequestTest.java b/src/test/java/com/android/volley/toolbox/JsonRequestTest.java
new file mode 100644
index 0000000..d999d50
--- /dev/null
+++ b/src/test/java/com/android/volley/toolbox/JsonRequestTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.volley.toolbox;
+
+import com.android.volley.Response;
+import org.json.JSONObject;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+
+import static org.junit.Assert.assertNotNull;
+
+@RunWith(RobolectricTestRunner.class)
+public class JsonRequestTest {
+
+ @Test
+ public void publicMethods() throws Exception {
+ // Catch-all test to find API-breaking changes.
+ assertNotNull(JsonRequest.class.getConstructor(String.class, String.class,
+ Response.Listener.class, Response.ErrorListener.class));
+ assertNotNull(JsonRequest.class.getConstructor(int.class, String.class, String.class,
+ Response.Listener.class, Response.ErrorListener.class));
+
+ assertNotNull(JsonArrayRequest.class.getConstructor(String.class,
+ Response.Listener.class, Response.ErrorListener.class));
+
+ assertNotNull(JsonObjectRequest.class.getConstructor(String.class, JSONObject.class,
+ Response.Listener.class, Response.ErrorListener.class));
+ assertNotNull(JsonObjectRequest.class.getConstructor(int.class, String.class,
+ JSONObject.class, Response.Listener.class, Response.ErrorListener.class));
+ }
+}
diff --git a/src/test/java/com/android/volley/toolbox/NetworkImageViewTest.java b/src/test/java/com/android/volley/toolbox/NetworkImageViewTest.java
index bc2cc29..26f8e68 100644
--- a/src/test/java/com/android/volley/toolbox/NetworkImageViewTest.java
+++ b/src/test/java/com/android/volley/toolbox/NetworkImageViewTest.java
@@ -1,8 +1,11 @@
package com.android.volley.toolbox;
+import android.content.Context;
+import android.util.AttributeSet;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView.ScaleType;
+import com.android.volley.Cache;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -51,4 +54,17 @@ public class NetworkImageViewTest {
return null;
}
}
+
+ @Test
+ public void publicMethods() throws Exception {
+ // Catch-all test to find API-breaking changes.
+ assertNotNull(NetworkImageView.class.getConstructor(Context.class));
+ assertNotNull(NetworkImageView.class.getConstructor(Context.class, AttributeSet.class));
+ assertNotNull(NetworkImageView.class.getConstructor(Context.class, AttributeSet.class,
+ int.class));
+
+ assertNotNull(NetworkImageView.class.getMethod("setImageUrl", String.class, ImageLoader.class));
+ assertNotNull(NetworkImageView.class.getMethod("setDefaultImageResId", int.class));
+ assertNotNull(NetworkImageView.class.getMethod("setErrorImageResId", int.class));
+ }
}
diff --git a/src/test/java/com/android/volley/toolbox/RequestFutureTest.java b/src/test/java/com/android/volley/toolbox/RequestFutureTest.java
new file mode 100644
index 0000000..c8e23e7
--- /dev/null
+++ b/src/test/java/com/android/volley/toolbox/RequestFutureTest.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.volley.toolbox;
+
+import com.android.volley.Request;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+
+import static org.junit.Assert.assertNotNull;
+
+@RunWith(RobolectricTestRunner.class)
+public class RequestFutureTest {
+
+ @Test
+ public void publicMethods() throws Exception {
+ // Catch-all test to find API-breaking changes.
+ assertNotNull(RequestFuture.class.getMethod("newFuture"));
+ assertNotNull(RequestFuture.class.getMethod("setRequest", Request.class));
+ }
+}
diff --git a/src/test/java/com/android/volley/toolbox/RequestQueueTest.java b/src/test/java/com/android/volley/toolbox/RequestQueueTest.java
new file mode 100644
index 0000000..1e4b82e
--- /dev/null
+++ b/src/test/java/com/android/volley/toolbox/RequestQueueTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.volley.toolbox;
+
+import com.android.volley.*;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+
+import static org.junit.Assert.assertNotNull;
+
+@RunWith(RobolectricTestRunner.class)
+public class RequestQueueTest {
+
+ @Test
+ public void publicMethods() throws Exception {
+ // Catch-all test to find API-breaking changes.
+ assertNotNull(RequestQueue.class.getConstructor(Cache.class, Network.class, int.class,
+ ResponseDelivery.class));
+ assertNotNull(RequestQueue.class.getConstructor(Cache.class, Network.class, int.class));
+ assertNotNull(RequestQueue.class.getConstructor(Cache.class, Network.class));
+
+ assertNotNull(RequestQueue.class.getMethod("start"));
+ assertNotNull(RequestQueue.class.getMethod("stop"));
+ assertNotNull(RequestQueue.class.getMethod("getSequenceNumber"));
+ assertNotNull(RequestQueue.class.getMethod("getCache"));
+ assertNotNull(RequestQueue.class.getMethod("cancelAll", RequestQueue.RequestFilter.class));
+ assertNotNull(RequestQueue.class.getMethod("cancelAll", Object.class));
+ assertNotNull(RequestQueue.class.getMethod("add", Request.class));
+ assertNotNull(RequestQueue.class.getDeclaredMethod("finish", Request.class));
+ }
+}
diff --git a/src/test/java/com/android/volley/toolbox/RequestTest.java b/src/test/java/com/android/volley/toolbox/RequestTest.java
new file mode 100644
index 0000000..22d2ef2
--- /dev/null
+++ b/src/test/java/com/android/volley/toolbox/RequestTest.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.volley.toolbox;
+
+import com.android.volley.*;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+
+import static org.junit.Assert.assertNotNull;
+
+@RunWith(RobolectricTestRunner.class)
+public class RequestTest {
+
+ @Test
+ public void publicMethods() throws Exception {
+ // Catch-all test to find API-breaking changes.
+ assertNotNull(Request.class.getConstructor(int.class, String.class,
+ Response.ErrorListener.class));
+
+ assertNotNull(Request.class.getMethod("getMethod"));
+ assertNotNull(Request.class.getMethod("setTag", Object.class));
+ assertNotNull(Request.class.getMethod("getTag"));
+ assertNotNull(Request.class.getMethod("getErrorListener"));
+ assertNotNull(Request.class.getMethod("getTrafficStatsTag"));
+ assertNotNull(Request.class.getMethod("setRetryPolicy", RetryPolicy.class));
+ assertNotNull(Request.class.getMethod("addMarker", String.class));
+ assertNotNull(Request.class.getDeclaredMethod("finish", String.class));
+ assertNotNull(Request.class.getMethod("setRequestQueue", RequestQueue.class));
+ assertNotNull(Request.class.getMethod("setSequence", int.class));
+ assertNotNull(Request.class.getMethod("getSequence"));
+ assertNotNull(Request.class.getMethod("getUrl"));
+ assertNotNull(Request.class.getMethod("getCacheKey"));
+ assertNotNull(Request.class.getMethod("setCacheEntry", Cache.Entry.class));
+ assertNotNull(Request.class.getMethod("getCacheEntry"));
+ assertNotNull(Request.class.getMethod("cancel"));
+ assertNotNull(Request.class.getMethod("isCanceled"));
+ assertNotNull(Request.class.getMethod("getHeaders"));
+ assertNotNull(Request.class.getDeclaredMethod("getParams"));
+ assertNotNull(Request.class.getDeclaredMethod("getParamsEncoding"));
+ assertNotNull(Request.class.getMethod("getBodyContentType"));
+ assertNotNull(Request.class.getMethod("getBody"));
+ assertNotNull(Request.class.getMethod("setShouldCache", boolean.class));
+ assertNotNull(Request.class.getMethod("shouldCache"));
+ assertNotNull(Request.class.getMethod("getPriority"));
+ assertNotNull(Request.class.getMethod("getTimeoutMs"));
+ assertNotNull(Request.class.getMethod("getRetryPolicy"));
+ assertNotNull(Request.class.getMethod("markDelivered"));
+ assertNotNull(Request.class.getMethod("hasHadResponseDelivered"));
+ assertNotNull(Request.class.getDeclaredMethod("parseNetworkResponse", NetworkResponse.class));
+ assertNotNull(Request.class.getDeclaredMethod("parseNetworkError", VolleyError.class));
+ assertNotNull(Request.class.getDeclaredMethod("deliverResponse", Object.class));
+ assertNotNull(Request.class.getMethod("deliverError", VolleyError.class));
+ }
+}
diff --git a/src/test/java/com/android/volley/toolbox/ResponseTest.java b/src/test/java/com/android/volley/toolbox/ResponseTest.java
new file mode 100644
index 0000000..e830eb5
--- /dev/null
+++ b/src/test/java/com/android/volley/toolbox/ResponseTest.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.volley.toolbox;
+
+import com.android.volley.Cache;
+import com.android.volley.NetworkResponse;
+import com.android.volley.Response;
+import com.android.volley.VolleyError;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+
+import java.util.Map;
+
+import static org.junit.Assert.assertNotNull;
+
+@RunWith(RobolectricTestRunner.class)
+public class ResponseTest {
+
+ @Test
+ public void publicMethods() throws Exception {
+ // Catch-all test to find API-breaking changes.
+ assertNotNull(Response.class.getMethod("success", Object.class, Cache.Entry.class));
+ assertNotNull(Response.class.getMethod("error", VolleyError.class));
+ assertNotNull(Response.class.getMethod("isSuccess"));
+
+ assertNotNull(Response.Listener.class.getDeclaredMethod("onResponse", Object.class));
+
+ assertNotNull(Response.ErrorListener.class.getDeclaredMethod("onErrorResponse",
+ VolleyError.class));
+
+ assertNotNull(NetworkResponse.class.getConstructor(int.class, byte[].class, Map.class,
+ boolean.class, long.class));
+ assertNotNull(NetworkResponse.class.getConstructor(int.class, byte[].class, Map.class,
+ boolean.class));
+ assertNotNull(NetworkResponse.class.getConstructor(byte[].class));
+ assertNotNull(NetworkResponse.class.getConstructor(byte[].class, Map.class));
+ }
+}
diff --git a/src/test/java/com/android/volley/toolbox/StringRequestTest.java b/src/test/java/com/android/volley/toolbox/StringRequestTest.java
new file mode 100644
index 0000000..eadd73f
--- /dev/null
+++ b/src/test/java/com/android/volley/toolbox/StringRequestTest.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.volley.toolbox;
+
+import com.android.volley.Response;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+
+import static org.junit.Assert.assertNotNull;
+
+@RunWith(RobolectricTestRunner.class)
+public class StringRequestTest {
+
+ @Test
+ public void publicMethods() throws Exception {
+ // Catch-all test to find API-breaking changes.
+ assertNotNull(StringRequest.class.getConstructor(String.class, Response.Listener.class,
+ Response.ErrorListener.class));
+ assertNotNull(StringRequest.class.getConstructor(int.class, String.class,
+ Response.Listener.class, Response.ErrorListener.class));
+ }
+}