aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/com/android/volley/toolbox/HttpHeaderParserTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com/android/volley/toolbox/HttpHeaderParserTest.java')
-rw-r--r--src/test/java/com/android/volley/toolbox/HttpHeaderParserTest.java70
1 files changed, 43 insertions, 27 deletions
diff --git a/src/test/java/com/android/volley/toolbox/HttpHeaderParserTest.java b/src/test/java/com/android/volley/toolbox/HttpHeaderParserTest.java
index 9ccac05..9b670f9 100644
--- a/src/test/java/com/android/volley/toolbox/HttpHeaderParserTest.java
+++ b/src/test/java/com/android/volley/toolbox/HttpHeaderParserTest.java
@@ -16,15 +16,14 @@
package com.android.volley.toolbox;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
import com.android.volley.Cache;
import com.android.volley.Header;
import com.android.volley.NetworkResponse;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.RobolectricTestRunner;
-
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -33,8 +32,10 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
-
-import static org.junit.Assert.*;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
public class HttpHeaderParserTest {
@@ -47,12 +48,14 @@ public class HttpHeaderParserTest {
private NetworkResponse response;
private Map<String, String> headers;
- @Before public void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
headers = new HashMap<String, String>();
response = new NetworkResponse(0, null, headers, false);
}
- @Test public void parseCacheHeaders_noHeaders() {
+ @Test
+ public void parseCacheHeaders_noHeaders() {
Cache.Entry entry = HttpHeaderParser.parseCacheHeaders(response);
assertNotNull(entry);
@@ -63,7 +66,8 @@ public class HttpHeaderParserTest {
assertEquals(0, entry.softTtl);
}
- @Test public void parseCacheHeaders_headersSet() {
+ @Test
+ public void parseCacheHeaders_headersSet() {
headers.put("MyCustomHeader", "42");
Cache.Entry entry = HttpHeaderParser.parseCacheHeaders(response);
@@ -74,7 +78,8 @@ public class HttpHeaderParserTest {
assertEquals("42", entry.responseHeaders.get("MyCustomHeader"));
}
- @Test public void parseCacheHeaders_etag() {
+ @Test
+ public void parseCacheHeaders_etag() {
headers.put("ETag", "Yow!");
Cache.Entry entry = HttpHeaderParser.parseCacheHeaders(response);
@@ -83,7 +88,8 @@ public class HttpHeaderParserTest {
assertEquals("Yow!", entry.etag);
}
- @Test public void parseCacheHeaders_normalExpire() {
+ @Test
+ public void parseCacheHeaders_normalExpire() {
long now = System.currentTimeMillis();
headers.put("Date", rfc1123Date(now));
headers.put("Last-Modified", rfc1123Date(now - ONE_DAY_MILLIS));
@@ -99,7 +105,8 @@ public class HttpHeaderParserTest {
assertTrue(entry.ttl == entry.softTtl);
}
- @Test public void parseCacheHeaders_expiresInPast() {
+ @Test
+ public void parseCacheHeaders_expiresInPast() {
long now = System.currentTimeMillis();
headers.put("Date", rfc1123Date(now));
headers.put("Expires", rfc1123Date(now - ONE_HOUR_MILLIS));
@@ -113,7 +120,8 @@ public class HttpHeaderParserTest {
assertEquals(0, entry.softTtl);
}
- @Test public void parseCacheHeaders_serverRelative() {
+ @Test
+ public void parseCacheHeaders_serverRelative() {
long now = System.currentTimeMillis();
// Set "current" date as one hour in the future
@@ -127,7 +135,8 @@ public class HttpHeaderParserTest {
assertEquals(entry.softTtl, entry.ttl);
}
- @Test public void parseCacheHeaders_cacheControlOverridesExpires() {
+ @Test
+ public void parseCacheHeaders_cacheControlOverridesExpires() {
long now = System.currentTimeMillis();
headers.put("Date", rfc1123Date(now));
headers.put("Expires", rfc1123Date(now + ONE_HOUR_MILLIS));
@@ -141,7 +150,8 @@ public class HttpHeaderParserTest {
assertEquals(entry.softTtl, entry.ttl);
}
- @Test public void testParseCacheHeaders_staleWhileRevalidate() {
+ @Test
+ public void testParseCacheHeaders_staleWhileRevalidate() {
long now = System.currentTimeMillis();
headers.put("Date", rfc1123Date(now));
headers.put("Expires", rfc1123Date(now + ONE_HOUR_MILLIS));
@@ -159,7 +169,8 @@ public class HttpHeaderParserTest {
assertEqualsWithin(now + ONE_DAY_MILLIS + ONE_WEEK_MILLIS, entry.ttl, ONE_MINUTE_MILLIS);
}
- @Test public void parseCacheHeaders_cacheControlNoCache() {
+ @Test
+ public void parseCacheHeaders_cacheControlNoCache() {
long now = System.currentTimeMillis();
headers.put("Date", rfc1123Date(now));
headers.put("Expires", rfc1123Date(now + ONE_HOUR_MILLIS));
@@ -170,7 +181,8 @@ public class HttpHeaderParserTest {
assertNull(entry);
}
- @Test public void parseCacheHeaders_cacheControlMustRevalidateNoMaxAge() {
+ @Test
+ public void parseCacheHeaders_cacheControlMustRevalidateNoMaxAge() {
long now = System.currentTimeMillis();
headers.put("Date", rfc1123Date(now));
headers.put("Expires", rfc1123Date(now + ONE_HOUR_MILLIS));
@@ -183,7 +195,8 @@ public class HttpHeaderParserTest {
assertEquals(entry.softTtl, entry.ttl);
}
- @Test public void parseCacheHeaders_cacheControlMustRevalidateWithMaxAge() {
+ @Test
+ public void parseCacheHeaders_cacheControlMustRevalidateWithMaxAge() {
long now = System.currentTimeMillis();
headers.put("Date", rfc1123Date(now));
headers.put("Expires", rfc1123Date(now + ONE_HOUR_MILLIS));
@@ -196,7 +209,8 @@ public class HttpHeaderParserTest {
assertEquals(entry.softTtl, entry.ttl);
}
- @Test public void parseCacheHeaders_cacheControlMustRevalidateWithMaxAgeAndStale() {
+ @Test
+ public void parseCacheHeaders_cacheControlMustRevalidateWithMaxAgeAndStale() {
long now = System.currentTimeMillis();
headers.put("Date", rfc1123Date(now));
headers.put("Expires", rfc1123Date(now + ONE_HOUR_MILLIS));
@@ -205,8 +219,8 @@ public class HttpHeaderParserTest {
// - stale-while-revalidate (entry.ttl) indicates that the asset may
// continue to be served stale for up to additional 7 days, but this is
// ignored in this case because of the must-revalidate header.
- headers.put("Cache-Control",
- "must-revalidate, max-age=86400, stale-while-revalidate=604800");
+ headers.put(
+ "Cache-Control", "must-revalidate, max-age=86400, stale-while-revalidate=604800");
Cache.Entry entry = HttpHeaderParser.parseCacheHeaders(response);
assertNotNull(entry);
@@ -227,7 +241,8 @@ public class HttpHeaderParserTest {
// --------------------------
- @Test public void parseCharset() {
+ @Test
+ public void parseCharset() {
// Like the ones we usually see
headers.put("Content-Type", "text/plain; charset=utf-8");
assertEquals("utf-8", HttpHeaderParser.parseCharset(headers));
@@ -269,7 +284,8 @@ public class HttpHeaderParserTest {
assertEquals("ISO-8859-1", HttpHeaderParser.parseCharset(headers));
}
- @Test public void parseCaseInsensitive() {
+ @Test
+ public void parseCaseInsensitive() {
long now = System.currentTimeMillis();
List<Header> headers = new ArrayList<>();
@@ -286,7 +302,7 @@ public class HttpHeaderParserTest {
assertEquals("Yow!", entry.etag);
assertEqualsWithin(now + ONE_DAY_MILLIS, entry.ttl, ONE_MINUTE_MILLIS);
assertEquals(entry.softTtl, entry.ttl);
- assertEquals("ISO-8859-1",
- HttpHeaderParser.parseCharset(HttpHeaderParser.toHeaderMap(headers)));
+ assertEquals(
+ "ISO-8859-1", HttpHeaderParser.parseCharset(HttpHeaderParser.toHeaderMap(headers)));
}
}