@@ -69,6 +69,7 @@ class TestBasicHttpAsyncCache {
6969 private Instant now ;
7070 private Instant tenSecondsAgo ;
7171 private SimpleHttpAsyncCacheStorage backing ;
72+ private CacheKeyGenerator keyGenerator ;
7273 private BasicHttpAsyncCache impl ;
7374
7475 @ BeforeEach
@@ -77,6 +78,7 @@ void setUp() {
7778 now = Instant .now ();
7879 tenSecondsAgo = now .minusSeconds (10 );
7980 backing = Mockito .spy (new SimpleHttpAsyncCacheStorage ());
81+ keyGenerator = CacheKeyGenerator .INSTANCE ;
8082 impl = new BasicHttpAsyncCache (HeapResourceFactory .INSTANCE , backing );
8183 }
8284
@@ -102,7 +104,7 @@ void testGetCacheEntryFetchesFromCacheOnCacheHitIfNoVariants() throws Exception
102104 final HttpHost host = new HttpHost ("foo.example.com" );
103105 final SimpleHttpRequest request = new SimpleHttpRequest ("GET" , "http://foo.example.com/bar" );
104106
105- final String key = CacheKeyGenerator . INSTANCE . generateKey (host , request );
107+ final String key = keyGenerator . generateKey (host , request , SimpleHttpRequest :: getBodyText );
106108
107109 backing .map .put (key ,entry );
108110
@@ -275,7 +277,7 @@ void testGetVariantCacheEntriesReturnsAllVariants() throws Exception {
275277 final SimpleHttpRequest req1 = new SimpleHttpRequest ("GET" , uri );
276278 req1 .setHeader ("Accept-Encoding" , "gzip" );
277279
278- final String rootKey = CacheKeyGenerator . INSTANCE .generateKey (uri );
280+ final String rootKey = keyGenerator .generateKey (uri );
279281
280282 final HttpResponse resp1 = HttpTestUtils .make200Response ();
281283 resp1 .setHeader ("Date" , DateUtils .formatStandardDate (now ));
@@ -547,7 +549,7 @@ void testInvalidatesUnsafeRequests() throws Exception {
547549 final SimpleHttpRequest request = new SimpleHttpRequest ( "POST" , "/path" );
548550 final HttpResponse response = HttpTestUtils .make200Response ();
549551
550- final String key = CacheKeyGenerator . INSTANCE . generateKey (host , request );
552+ final String key = keyGenerator . generateKey (host , request , SimpleHttpRequest :: getBodyText );
551553
552554 backing .putEntry (key , HttpTestUtils .makeCacheEntry ());
553555
@@ -587,7 +589,7 @@ void testDoesNotInvalidateSafeRequests() throws Exception {
587589 @ Test
588590 void testInvalidatesUnsafeRequestsWithVariants () throws Exception {
589591 final SimpleHttpRequest request = new SimpleHttpRequest ( "POST" , "/path" );
590- final String rootKey = CacheKeyGenerator . INSTANCE . generateKey (host , request );
592+ final String rootKey = keyGenerator . generateKey (host , request , SimpleHttpRequest :: getBodyText );
591593 final Set <String > variants = new HashSet <>();
592594 variants .add ("{var1}" );
593595 variants .add ("{var2}" );
@@ -618,12 +620,12 @@ void testInvalidatesUnsafeRequestsWithVariants() throws Exception {
618620 @ Test
619621 void testInvalidateUriSpecifiedByContentLocationAndFresher () throws Exception {
620622 final SimpleHttpRequest request = new SimpleHttpRequest ( "PUT" , "/foo" );
621- final String rootKey = CacheKeyGenerator . INSTANCE . generateKey (host , request );
623+ final String rootKey = keyGenerator . generateKey (host , request , SimpleHttpRequest :: getBodyText );
622624 final URI contentUri = new URIBuilder ()
623625 .setHttpHost (host )
624626 .setPath ("/bar" )
625627 .build ();
626- final String contentKey = CacheKeyGenerator . INSTANCE .generateKey (contentUri );
628+ final String contentKey = keyGenerator .generateKey (contentUri );
627629
628630 final HttpResponse response = HttpTestUtils .make200Response ();
629631 response .setHeader ("ETag" ,"\" new-etag\" " );
@@ -650,12 +652,12 @@ void testInvalidateUriSpecifiedByContentLocationAndFresher() throws Exception {
650652 @ Test
651653 void testInvalidateUriSpecifiedByLocationAndFresher () throws Exception {
652654 final SimpleHttpRequest request = new SimpleHttpRequest ( "PUT" , "/foo" );
653- final String rootKey = CacheKeyGenerator . INSTANCE . generateKey (host , request );
655+ final String rootKey = keyGenerator . generateKey (host , request , SimpleHttpRequest :: getBodyText );
654656 final URI contentUri = new URIBuilder ()
655657 .setHttpHost (host )
656658 .setPath ("/bar" )
657659 .build ();
658- final String contentKey = CacheKeyGenerator . INSTANCE .generateKey (contentUri );
660+ final String contentKey = keyGenerator .generateKey (contentUri );
659661
660662 final HttpResponse response = HttpTestUtils .make200Response ();
661663 response .setHeader ("ETag" ,"\" new-etag\" " );
@@ -702,12 +704,12 @@ void testDoesNotInvalidateForUnsuccessfulResponse() throws Exception {
702704 @ Test
703705 void testInvalidateUriSpecifiedByContentLocationNonCanonical () throws Exception {
704706 final SimpleHttpRequest request = new SimpleHttpRequest ( "PUT" , "/foo" );
705- final String rootKey = CacheKeyGenerator . INSTANCE . generateKey (host , request );
707+ final String rootKey = keyGenerator . generateKey (host , request , SimpleHttpRequest :: getBodyText );
706708 final URI contentUri = new URIBuilder ()
707709 .setHttpHost (host )
708710 .setPath ("/bar" )
709711 .build ();
710- final String contentKey = CacheKeyGenerator . INSTANCE .generateKey (contentUri );
712+ final String contentKey = keyGenerator .generateKey (contentUri );
711713
712714 final HttpResponse response = HttpTestUtils .make200Response ();
713715 response .setHeader ("ETag" ,"\" new-etag\" " );
@@ -737,12 +739,12 @@ void testInvalidateUriSpecifiedByContentLocationNonCanonical() throws Exception
737739 @ Test
738740 void testInvalidateUriSpecifiedByContentLocationRelative () throws Exception {
739741 final SimpleHttpRequest request = new SimpleHttpRequest ( "PUT" , "/foo" );
740- final String rootKey = CacheKeyGenerator . INSTANCE . generateKey (host , request );
742+ final String rootKey = keyGenerator . generateKey (host , request , SimpleHttpRequest :: getBodyText );
741743 final URI contentUri = new URIBuilder ()
742744 .setHttpHost (host )
743745 .setPath ("/bar" )
744746 .build ();
745- final String contentKey = CacheKeyGenerator . INSTANCE .generateKey (contentUri );
747+ final String contentKey = keyGenerator .generateKey (contentUri );
746748
747749 final HttpResponse response = HttpTestUtils .make200Response ();
748750 response .setHeader ("ETag" ,"\" new-etag\" " );
@@ -776,7 +778,7 @@ void testDoesNotInvalidateUriSpecifiedByContentLocationOtherOrigin() throws Exce
776778 .setHost ("bar.example.com" )
777779 .setPath ("/" )
778780 .build ();
779- final String contentKey = CacheKeyGenerator . INSTANCE .generateKey (contentUri );
781+ final String contentKey = keyGenerator .generateKey (contentUri );
780782
781783 final HttpResponse response = HttpTestUtils .make200Response ();
782784 response .setHeader ("ETag" ,"\" new-etag\" " );
@@ -801,7 +803,7 @@ void testDoesNotInvalidateUriSpecifiedByContentLocationIfEtagsMatch() throws Exc
801803 .setHttpHost (host )
802804 .setPath ("/bar" )
803805 .build ();
804- final String contentKey = CacheKeyGenerator . INSTANCE .generateKey (contentUri );
806+ final String contentKey = keyGenerator .generateKey (contentUri );
805807
806808 final HttpResponse response = HttpTestUtils .make200Response ();
807809 response .setHeader ("ETag" ,"\" same-etag\" " );
@@ -828,7 +830,7 @@ void testDoesNotInvalidateUriSpecifiedByContentLocationIfOlder() throws Exceptio
828830 .setHttpHost (host )
829831 .setPath ("/bar" )
830832 .build ();
831- final String contentKey = CacheKeyGenerator . INSTANCE .generateKey (contentUri );
833+ final String contentKey = keyGenerator .generateKey (contentUri );
832834
833835 final HttpResponse response = HttpTestUtils .make200Response ();
834836 response .setHeader ("ETag" ,"\" new-etag\" " );
@@ -855,7 +857,7 @@ void testDoesNotInvalidateUriSpecifiedByContentLocationIfResponseHasNoEtag() thr
855857 .setHttpHost (host )
856858 .setPath ("/bar" )
857859 .build ();
858- final String contentKey = CacheKeyGenerator . INSTANCE .generateKey (contentUri );
860+ final String contentKey = keyGenerator .generateKey (contentUri );
859861
860862 final HttpResponse response = HttpTestUtils .make200Response ();
861863 response .removeHeaders ("ETag" );
@@ -882,7 +884,7 @@ void testDoesNotInvalidateUriSpecifiedByContentLocationIfEntryHasNoEtag() throws
882884 .setHttpHost (host )
883885 .setPath ("/bar" )
884886 .build ();
885- final String contentKey = CacheKeyGenerator . INSTANCE .generateKey (contentUri );
887+ final String contentKey = keyGenerator .generateKey (contentUri );
886888
887889 final HttpResponse response = HttpTestUtils .make200Response ();
888890 response .setHeader ("ETag" , "\" some-etag\" " );
@@ -908,7 +910,7 @@ void testInvalidatesUriSpecifiedByContentLocationIfResponseHasNoDate() throws Ex
908910 .setHttpHost (host )
909911 .setPath ("/bar" )
910912 .build ();
911- final String contentKey = CacheKeyGenerator . INSTANCE .generateKey (contentUri );
913+ final String contentKey = keyGenerator .generateKey (contentUri );
912914
913915 final HttpResponse response = HttpTestUtils .make200Response ();
914916 response .setHeader ("ETag" , "\" new-etag\" " );
@@ -935,7 +937,7 @@ void testInvalidatesUriSpecifiedByContentLocationIfEntryHasNoDate() throws Excep
935937 .setHttpHost (host )
936938 .setPath ("/bar" )
937939 .build ();
938- final String contentKey = CacheKeyGenerator . INSTANCE .generateKey (contentUri );
940+ final String contentKey = keyGenerator .generateKey (contentUri );
939941
940942 final HttpResponse response = HttpTestUtils .make200Response ();
941943 response .setHeader ("ETag" ,"\" new-etag\" " );
@@ -961,7 +963,7 @@ void testInvalidatesUriSpecifiedByContentLocationIfResponseHasMalformedDate() th
961963 .setHttpHost (host )
962964 .setPath ("/bar" )
963965 .build ();
964- final String contentKey = CacheKeyGenerator . INSTANCE .generateKey (contentUri );
966+ final String contentKey = keyGenerator .generateKey (contentUri );
965967
966968 final HttpResponse response = HttpTestUtils .make200Response ();
967969 response .setHeader ("ETag" ,"\" new-etag\" " );
@@ -988,7 +990,7 @@ void testInvalidatesUriSpecifiedByContentLocationIfEntryHasMalformedDate() throw
988990 .setHttpHost (host )
989991 .setPath ("/bar" )
990992 .build ();
991- final String contentKey = CacheKeyGenerator . INSTANCE .generateKey (contentUri );
993+ final String contentKey = keyGenerator .generateKey (contentUri );
992994
993995 final HttpResponse response = HttpTestUtils .make200Response ();
994996 response .setHeader ("ETag" ,"\" new-etag\" " );
0 commit comments