aboutsummaryrefslogtreecommitdiff
path: root/android/guava-tests/test/com/google/common/cache/CacheBuilderTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'android/guava-tests/test/com/google/common/cache/CacheBuilderTest.java')
-rw-r--r--android/guava-tests/test/com/google/common/cache/CacheBuilderTest.java97
1 files changed, 20 insertions, 77 deletions
diff --git a/android/guava-tests/test/com/google/common/cache/CacheBuilderTest.java b/android/guava-tests/test/com/google/common/cache/CacheBuilderTest.java
index 3a3a571f7..6730c48c3 100644
--- a/android/guava-tests/test/com/google/common/cache/CacheBuilderTest.java
+++ b/android/guava-tests/test/com/google/common/cache/CacheBuilderTest.java
@@ -26,6 +26,7 @@ import static com.google.common.truth.Truth.assertThat;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.NANOSECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.junit.Assert.assertThrows;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
@@ -164,11 +165,7 @@ public class CacheBuilderTest extends TestCase {
@GwtIncompatible // maximumWeight
public void testMaximumSize_andWeight() {
CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder().maximumSize(16);
- try {
- builder.maximumWeight(16);
- fail();
- } catch (IllegalStateException expected) {
- }
+ assertThrows(IllegalStateException.class, () -> builder.maximumWeight(16));
}
@GwtIncompatible // digs into internals of the non-GWT implementation
@@ -182,98 +179,53 @@ public class CacheBuilderTest extends TestCase {
@GwtIncompatible // maximumWeight
public void testMaximumWeight_negative() {
CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder();
- try {
- builder.maximumWeight(-1);
- fail();
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(IllegalArgumentException.class, () -> builder.maximumWeight(-1));
}
@GwtIncompatible // maximumWeight
public void testMaximumWeight_setTwice() {
CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder().maximumWeight(16);
- try {
- // even to the same value is not allowed
- builder.maximumWeight(16);
- fail();
- } catch (IllegalStateException expected) {
- }
- try {
- builder.maximumSize(16);
- fail();
- } catch (IllegalStateException expected) {
- }
+ assertThrows(IllegalStateException.class, () -> builder.maximumWeight(16));
+ assertThrows(IllegalStateException.class, () -> builder.maximumSize(16));
}
@GwtIncompatible // maximumWeight
public void testMaximumWeight_withoutWeigher() {
CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder().maximumWeight(1);
- try {
- builder.build(identityLoader());
- fail();
- } catch (IllegalStateException expected) {
- }
+ assertThrows(IllegalStateException.class, () -> builder.build(identityLoader()));
}
@GwtIncompatible // weigher
public void testWeigher_withoutMaximumWeight() {
CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder().weigher(constantWeigher(42));
- try {
- builder.build(identityLoader());
- fail();
- } catch (IllegalStateException expected) {
- }
+ assertThrows(IllegalStateException.class, () -> builder.build(identityLoader()));
}
@GwtIncompatible // weigher
public void testWeigher_withMaximumSize() {
- try {
- CacheBuilder.newBuilder().weigher(constantWeigher(42)).maximumSize(1);
- fail();
- } catch (IllegalStateException expected) {
- }
- try {
- CacheBuilder.newBuilder().maximumSize(1).weigher(constantWeigher(42));
- fail();
- } catch (IllegalStateException expected) {
- }
+ assertThrows(
+ IllegalStateException.class,
+ () -> CacheBuilder.newBuilder().weigher(constantWeigher(42)).maximumSize(1));
+ assertThrows(
+ IllegalStateException.class,
+ () -> CacheBuilder.newBuilder().maximumSize(1).weigher(constantWeigher(42)));
}
@GwtIncompatible // weakKeys
public void testKeyStrengthSetTwice() {
CacheBuilder<Object, Object> builder1 = CacheBuilder.newBuilder().weakKeys();
- try {
- builder1.weakKeys();
- fail();
- } catch (IllegalStateException expected) {
- }
+ assertThrows(IllegalStateException.class, () -> builder1.weakKeys());
}
@GwtIncompatible // weakValues
public void testValueStrengthSetTwice() {
CacheBuilder<Object, Object> builder1 = CacheBuilder.newBuilder().weakValues();
- try {
- builder1.weakValues();
- fail();
- } catch (IllegalStateException expected) {
- }
- try {
- builder1.softValues();
- fail();
- } catch (IllegalStateException expected) {
- }
+ assertThrows(IllegalStateException.class, () -> builder1.weakValues());
+ assertThrows(IllegalStateException.class, () -> builder1.softValues());
CacheBuilder<Object, Object> builder2 = CacheBuilder.newBuilder().softValues();
- try {
- builder2.softValues();
- fail();
- } catch (IllegalStateException expected) {
- }
- try {
- builder2.weakValues();
- fail();
- } catch (IllegalStateException expected) {
- }
+ assertThrows(IllegalStateException.class, () -> builder2.softValues());
+ assertThrows(IllegalStateException.class, () -> builder2.weakValues());
}
public void testTimeToLive_negative() {
@@ -340,23 +292,14 @@ public class CacheBuilderTest extends TestCase {
@GwtIncompatible // refreshAfterWrite
public void testRefresh_zero() {
CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder();
- try {
- builder.refreshAfterWrite(0, SECONDS);
- fail();
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(IllegalArgumentException.class, () -> builder.refreshAfterWrite(0, SECONDS));
}
@GwtIncompatible // refreshAfterWrite
public void testRefresh_setTwice() {
CacheBuilder<Object, Object> builder =
CacheBuilder.newBuilder().refreshAfterWrite(3600, SECONDS);
- try {
- // even to the same value is not allowed
- builder.refreshAfterWrite(3600, SECONDS);
- fail();
- } catch (IllegalStateException expected) {
- }
+ assertThrows(IllegalStateException.class, () -> builder.refreshAfterWrite(3600, SECONDS));
}
public void testTicker_setTwice() {