Search in sources :

Example 1 with HttpResponseCache

use of android.net.http.HttpResponseCache in project robolectric by robolectric.

the class ShadowHttpResponseCache method install.

@Implementation
public static HttpResponseCache install(File directory, long maxSize) {
    HttpResponseCache cache = newInstanceOf(HttpResponseCache.class);
    ShadowHttpResponseCache shadowCache = Shadows.shadowOf(cache);
    shadowCache.originalObject = cache;
    shadowCache.directory = directory;
    shadowCache.maxSize = maxSize;
    synchronized (LOCK) {
        installed = shadowCache;
        return cache;
    }
}
Also used : HttpResponseCache(android.net.http.HttpResponseCache) Implementation(org.robolectric.annotation.Implementation)

Example 2 with HttpResponseCache

use of android.net.http.HttpResponseCache in project robolectric by robolectric.

the class ShadowHttpResponseCacheTest method installedCacheIsReturned.

@Test
public void installedCacheIsReturned() throws Exception {
    assertThat(HttpResponseCache.getInstalled()).isNull();
    HttpResponseCache cache = HttpResponseCache.install(File.createTempFile("foo", "bar"), 42);
    HttpResponseCache installed = HttpResponseCache.getInstalled();
    assertThat(installed).isSameAs(cache);
    assertThat(installed.maxSize()).isEqualTo(42);
}
Also used : HttpResponseCache(android.net.http.HttpResponseCache) Test(org.junit.Test)

Example 3 with HttpResponseCache

use of android.net.http.HttpResponseCache in project robolectric by robolectric.

the class ShadowHttpResponseCacheTest method closeRemovesReference.

@Test
public void closeRemovesReference() throws Exception {
    HttpResponseCache cache = HttpResponseCache.install(File.createTempFile("foo", "bar"), 42);
    cache.close();
    assertThat(HttpResponseCache.getInstalled()).isNull();
}
Also used : HttpResponseCache(android.net.http.HttpResponseCache) Test(org.junit.Test)

Example 4 with HttpResponseCache

use of android.net.http.HttpResponseCache in project robolectric by robolectric.

the class ShadowHttpResponseCacheTest method countsStartAtZero.

@Test
public void countsStartAtZero() throws Exception {
    HttpResponseCache cache = HttpResponseCache.install(File.createTempFile("foo", "bar"), 42);
    assertThat(cache.getHitCount()).isZero();
    assertThat(cache.getNetworkCount()).isZero();
    assertThat(cache.getRequestCount()).isZero();
}
Also used : HttpResponseCache(android.net.http.HttpResponseCache) Test(org.junit.Test)

Example 5 with HttpResponseCache

use of android.net.http.HttpResponseCache in project robolectric by robolectric.

the class ShadowHttpResponseCacheTest method deleteRemovesReference.

@Test
public void deleteRemovesReference() throws Exception {
    HttpResponseCache cache = HttpResponseCache.install(File.createTempFile("foo", "bar"), 42);
    cache.delete();
    assertThat(HttpResponseCache.getInstalled()).isNull();
}
Also used : HttpResponseCache(android.net.http.HttpResponseCache) Test(org.junit.Test)

Aggregations

HttpResponseCache (android.net.http.HttpResponseCache)5 Test (org.junit.Test)4 Implementation (org.robolectric.annotation.Implementation)1