@throws Exception if the test fails
()
| 396 | * @throws Exception if the test fails |
| 397 | */ |
| 398 | @Test |
| 399 | public void maxSizeMaintained() throws Exception { |
| 400 | final String html = DOCTYPE_HTML |
| 401 | + "<html><head><title>page 1</title>\n" |
| 402 | + "<script src='foo1.js' type='text/javascript'/>\n" |
| 403 | + "<script src='foo2.js' type='text/javascript'/>\n" |
| 404 | + "</head><body>abc</body></html>"; |
| 405 | |
| 406 | final WebClient client = getWebClient(); |
| 407 | client.getCache().setMaxSize(1); |
| 408 | |
| 409 | final MockWebConnection connection = new MockWebConnection(); |
| 410 | client.setWebConnection(connection); |
| 411 | |
| 412 | final URL pageUrl = new URL(URL_FIRST, "page1.html"); |
| 413 | connection.setResponse(pageUrl, html); |
| 414 | |
| 415 | final List<NameValuePair> headers = |
| 416 | Collections.singletonList(new NameValuePair(LAST_MODIFIED, "Sun, 15 Jul 2007 20:46:27 GMT")); |
| 417 | connection.setResponse(new URL(URL_FIRST, "foo1.js"), ";", 200, "ok", MimeType.TEXT_JAVASCRIPT, headers); |
| 418 | connection.setResponse(new URL(URL_FIRST, "foo2.js"), ";", 200, "ok", MimeType.TEXT_JAVASCRIPT, headers); |
| 419 | |
| 420 | client.getPage(pageUrl); |
| 421 | assertEquals(1, client.getCache().getSize()); |
| 422 | |
| 423 | client.getCache().clear(); |
| 424 | assertEquals(0, client.getCache().getSize()); |
| 425 | } |
| 426 | |
| 427 | /** |
| 428 | * TODO: improve CSS caching to cache a COPY of the object as stylesheet objects can be modified dynamically. |
nothing calls this directly
no test coverage detected