2121import static com .google .common .cache .TestingCacheLoaders .identityLoader ;
2222import static com .google .common .cache .TestingRemovalListeners .countingRemovalListener ;
2323import static com .google .common .truth .Truth .assertThat ;
24- import static java .lang .Thread .currentThread ;
2524import static java .util .Arrays .asList ;
2625import static java .util .concurrent .TimeUnit .MILLISECONDS ;
2726import static org .junit .Assert .assertThrows ;
@@ -75,7 +74,7 @@ public void setUp() throws Exception {
7574 public void tearDown () throws Exception {
7675 super .tearDown ();
7776 // TODO(cpovirk): run tests in other thread instead of messing with main thread interrupt status
78- currentThread () .interrupted ();
77+ Thread .interrupted ();
7978 LocalCache .logger .removeHandler (logHandler );
8079 }
8180
@@ -1148,11 +1147,11 @@ public void testLoadInterruptedException() {
11481147 assertEquals (0 , stats .hitCount ());
11491148
11501149 // Sanity check:
1151- assertFalse (currentThread () .interrupted ());
1150+ assertFalse (Thread .interrupted ());
11521151
11531152 Exception expected = assertThrows (ExecutionException .class , () -> cache .get (new Object ()));
11541153 assertThat (expected ).hasCauseThat ().isSameInstanceAs (e );
1155- assertTrue (currentThread () .interrupted ());
1154+ assertTrue (Thread .interrupted ());
11561155 stats = cache .stats ();
11571156 assertEquals (1 , stats .missCount ());
11581157 assertEquals (0 , stats .loadSuccessCount ());
@@ -1162,15 +1161,15 @@ public void testLoadInterruptedException() {
11621161 expected =
11631162 assertThrows (UncheckedExecutionException .class , () -> cache .getUnchecked (new Object ()));
11641163 assertThat (expected ).hasCauseThat ().isSameInstanceAs (e );
1165- assertTrue (currentThread () .interrupted ());
1164+ assertTrue (Thread .interrupted ());
11661165 stats = cache .stats ();
11671166 assertEquals (2 , stats .missCount ());
11681167 assertEquals (0 , stats .loadSuccessCount ());
11691168 assertEquals (2 , stats .loadExceptionCount ());
11701169 assertEquals (0 , stats .hitCount ());
11711170
11721171 cache .refresh (new Object ());
1173- assertTrue (currentThread () .interrupted ());
1172+ assertTrue (Thread .interrupted ());
11741173 checkLoggedCause (e );
11751174 stats = cache .stats ();
11761175 assertEquals (2 , stats .missCount ());
@@ -1183,7 +1182,7 @@ public void testLoadInterruptedException() {
11831182 assertThrows (
11841183 ExecutionException .class , () -> cache .get (new Object (), throwing (callableException )));
11851184 assertThat (expected ).hasCauseThat ().isSameInstanceAs (callableException );
1186- assertTrue (currentThread () .interrupted ());
1185+ assertTrue (Thread .interrupted ());
11871186 stats = cache .stats ();
11881187 assertEquals (3 , stats .missCount ());
11891188 assertEquals (0 , stats .loadSuccessCount ());
@@ -1192,7 +1191,7 @@ public void testLoadInterruptedException() {
11921191
11931192 expected = assertThrows (ExecutionException .class , () -> cache .getAll (asList (new Object ())));
11941193 assertThat (expected ).hasCauseThat ().isSameInstanceAs (e );
1195- assertTrue (currentThread () .interrupted ());
1194+ assertTrue (Thread .interrupted ());
11961195 stats = cache .stats ();
11971196 assertEquals (4 , stats .missCount ());
11981197 assertEquals (0 , stats .loadSuccessCount ());
@@ -1392,7 +1391,7 @@ public void testBulkLoadInterruptedException() {
13921391 ExecutionException expected =
13931392 assertThrows (ExecutionException .class , () -> cache .getAll (asList (new Object ())));
13941393 assertThat (expected ).hasCauseThat ().isSameInstanceAs (e );
1395- assertTrue (currentThread () .interrupted ());
1394+ assertTrue (Thread .interrupted ());
13961395 stats = cache .stats ();
13971396 assertEquals (1 , stats .missCount ());
13981397 assertEquals (0 , stats .loadSuccessCount ());
@@ -1765,31 +1764,22 @@ public void testLoadingExceptionWithCause() {
17651764 LoadingCache <Object , Object > cacheChecked =
17661765 CacheBuilder .newBuilder ().build (exceptionLoader (ee ));
17671766
1768- try {
1769- cacheUnchecked .get (new Object ());
1770- fail ();
1771- } catch (ExecutionException e ) {
1772- fail ();
1773- } catch (UncheckedExecutionException caughtEe ) {
1774- assertThat (caughtEe ).hasCauseThat ().isSameInstanceAs (uee );
1775- }
1776-
17771767 UncheckedExecutionException caughtUee =
1768+ assertThrows (UncheckedExecutionException .class , () -> cacheUnchecked .get (new Object ()));
1769+ assertThat (caughtUee ).hasCauseThat ().isSameInstanceAs (uee );
1770+
1771+ caughtUee =
17781772 assertThrows (
17791773 UncheckedExecutionException .class , () -> cacheUnchecked .getUnchecked (new Object ()));
17801774 assertThat (caughtUee ).hasCauseThat ().isSameInstanceAs (uee );
17811775
17821776 cacheUnchecked .refresh (new Object ());
17831777 checkLoggedCause (uee );
17841778
1785- try {
1786- cacheUnchecked .getAll (asList (new Object ()));
1787- fail ();
1788- } catch (ExecutionException e ) {
1789- fail ();
1790- } catch (UncheckedExecutionException caughtEe ) {
1791- assertThat (caughtEe ).hasCauseThat ().isSameInstanceAs (uee );
1792- }
1779+ caughtUee =
1780+ assertThrows (
1781+ UncheckedExecutionException .class , () -> cacheUnchecked .getAll (asList (new Object ())));
1782+ assertThat (caughtUee ).hasCauseThat ().isSameInstanceAs (uee );
17931783
17941784 ExecutionException caughtEe =
17951785 assertThrows (ExecutionException .class , () -> cacheChecked .get (new Object ()));
@@ -1818,14 +1808,10 @@ public void testBulkLoadingExceptionWithCause() {
18181808 LoadingCache <Object , Object > cacheChecked =
18191809 CacheBuilder .newBuilder ().build (bulkLoader (exceptionLoader (ee )));
18201810
1821- try {
1822- cacheUnchecked .getAll (asList (new Object ()));
1823- fail ();
1824- } catch (ExecutionException e ) {
1825- fail ();
1826- } catch (UncheckedExecutionException caughtEe ) {
1827- assertThat (caughtEe ).hasCauseThat ().isSameInstanceAs (uee );
1828- }
1811+ UncheckedExecutionException caughtUee =
1812+ assertThrows (
1813+ UncheckedExecutionException .class , () -> cacheUnchecked .getAll (asList (new Object ())));
1814+ assertThat (caughtUee ).hasCauseThat ().isSameInstanceAs (uee );
18291815
18301816 ExecutionException caughtEe =
18311817 assertThrows (ExecutionException .class , () -> cacheChecked .getAll (asList (new Object ())));
@@ -1897,6 +1883,7 @@ private static void testConcurrentLoadingNull(CacheBuilder<Object, Object> build
18971883 builder .build (
18981884 new CacheLoader <String , String >() {
18991885 @ Override
1886+ @ SuppressWarnings ("CacheLoaderNull" ) // test of broken user implementation
19001887 public String load (String key ) throws InterruptedException {
19011888 callCount .incrementAndGet ();
19021889 startSignal .await ();
0 commit comments