aboutsummaryrefslogtreecommitdiff
path: root/android/guava-tests/test/com/google/common/cache/CacheBuilderSpecTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'android/guava-tests/test/com/google/common/cache/CacheBuilderSpecTest.java')
-rw-r--r--android/guava-tests/test/com/google/common/cache/CacheBuilderSpecTest.java145
1 files changed, 32 insertions, 113 deletions
diff --git a/android/guava-tests/test/com/google/common/cache/CacheBuilderSpecTest.java b/android/guava-tests/test/com/google/common/cache/CacheBuilderSpecTest.java
index 09f2eb6c2..8a60cd30d 100644
--- a/android/guava-tests/test/com/google/common/cache/CacheBuilderSpecTest.java
+++ b/android/guava-tests/test/com/google/common/cache/CacheBuilderSpecTest.java
@@ -18,6 +18,7 @@ package com.google.common.cache;
import static com.google.common.cache.CacheBuilderSpec.parse;
import static com.google.common.cache.TestingWeighers.constantWeigher;
+import static org.junit.Assert.assertThrows;
import com.google.common.base.Suppliers;
import com.google.common.cache.LocalCache.Strength;
@@ -60,11 +61,8 @@ public class CacheBuilderSpecTest extends TestCase {
}
public void testParse_initialCapacityRepeated() {
- try {
- parse("initialCapacity=10, initialCapacity=20");
- fail("Expected exception");
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(
+ IllegalArgumentException.class, () -> parse("initialCapacity=10, initialCapacity=20"));
}
public void testParse_maximumSize() {
@@ -81,11 +79,7 @@ public class CacheBuilderSpecTest extends TestCase {
}
public void testParse_maximumSizeRepeated() {
- try {
- parse("maximumSize=10, maximumSize=20");
- fail("Expected exception");
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(IllegalArgumentException.class, () -> parse("maximumSize=10, maximumSize=20"));
}
public void testParse_maximumWeight() {
@@ -102,19 +96,11 @@ public class CacheBuilderSpecTest extends TestCase {
}
public void testParse_maximumWeightRepeated() {
- try {
- parse("maximumWeight=10, maximumWeight=20");
- fail("Expected exception");
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(IllegalArgumentException.class, () -> parse("maximumWeight=10, maximumWeight=20"));
}
public void testParse_maximumSizeAndMaximumWeight() {
- try {
- parse("maximumSize=10, maximumWeight=20");
- fail("Expected exception");
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(IllegalArgumentException.class, () -> parse("maximumSize=10, maximumWeight=20"));
}
public void testParse_concurrencyLevel() {
@@ -132,11 +118,8 @@ public class CacheBuilderSpecTest extends TestCase {
}
public void testParse_concurrencyLevelRepeated() {
- try {
- parse("concurrencyLevel=10, concurrencyLevel=20");
- fail("Expected exception");
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(
+ IllegalArgumentException.class, () -> parse("concurrencyLevel=10, concurrencyLevel=20"));
}
public void testParse_weakKeys() {
@@ -153,19 +136,11 @@ public class CacheBuilderSpecTest extends TestCase {
}
public void testParse_weakKeysCannotHaveValue() {
- try {
- parse("weakKeys=true");
- fail("Expected exception");
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(IllegalArgumentException.class, () -> parse("weakKeys=true"));
}
public void testParse_repeatedKeyStrength() {
- try {
- parse("weakKeys, weakKeys");
- fail("Expected exception");
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(IllegalArgumentException.class, () -> parse("weakKeys, weakKeys"));
}
public void testParse_softValues() {
@@ -182,11 +157,7 @@ public class CacheBuilderSpecTest extends TestCase {
}
public void testParse_softValuesCannotHaveValue() {
- try {
- parse("softValues=true");
- fail("Expected exception");
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(IllegalArgumentException.class, () -> parse("softValues=true"));
}
public void testParse_weakValues() {
@@ -203,37 +174,17 @@ public class CacheBuilderSpecTest extends TestCase {
}
public void testParse_weakValuesCannotHaveValue() {
- try {
- parse("weakValues=true");
- fail("Expected exception");
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(IllegalArgumentException.class, () -> parse("weakValues=true"));
}
public void testParse_repeatedValueStrength() {
- try {
- parse("softValues, softValues");
- fail("Expected exception");
- } catch (IllegalArgumentException expected) {
- }
-
- try {
- parse("softValues, weakValues");
- fail("Expected exception");
- } catch (IllegalArgumentException expected) {
- }
-
- try {
- parse("weakValues, softValues");
- fail("Expected exception");
- } catch (IllegalArgumentException expected) {
- }
-
- try {
- parse("weakValues, weakValues");
- fail("Expected exception");
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(IllegalArgumentException.class, () -> parse("softValues, softValues"));
+
+ assertThrows(IllegalArgumentException.class, () -> parse("softValues, weakValues"));
+
+ assertThrows(IllegalArgumentException.class, () -> parse("weakValues, softValues"));
+
+ assertThrows(IllegalArgumentException.class, () -> parse("weakValues, weakValues"));
}
public void testParse_writeExpirationDays() {
@@ -276,11 +227,8 @@ public class CacheBuilderSpecTest extends TestCase {
}
public void testParse_writeExpirationRepeated() {
- try {
- parse("expireAfterWrite=10s,expireAfterWrite=10m");
- fail("Expected exception");
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(
+ IllegalArgumentException.class, () -> parse("expireAfterWrite=10s,expireAfterWrite=10m"));
}
public void testParse_accessExpirationDays() {
@@ -325,11 +273,8 @@ public class CacheBuilderSpecTest extends TestCase {
}
public void testParse_accessExpirationRepeated() {
- try {
- parse("expireAfterAccess=10s,expireAfterAccess=10m");
- fail("Expected exception");
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(
+ IllegalArgumentException.class, () -> parse("expireAfterAccess=10s,expireAfterAccess=10m"));
}
public void testParse_recordStats() {
@@ -339,19 +284,11 @@ public class CacheBuilderSpecTest extends TestCase {
}
public void testParse_recordStatsValueSpecified() {
- try {
- parse("recordStats=True");
- fail("Expected exception");
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(IllegalArgumentException.class, () -> parse("recordStats=True"));
}
public void testParse_recordStatsRepeated() {
- try {
- parse("recordStats,recordStats");
- fail("Expected exception");
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(IllegalArgumentException.class, () -> parse("recordStats,recordStats"));
}
public void testParse_accessExpirationAndWriteExpiration() {
@@ -419,31 +356,15 @@ public class CacheBuilderSpecTest extends TestCase {
}
public void testParse_unknownKey() {
- try {
- parse("foo=17");
- fail("Expected exception");
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(IllegalArgumentException.class, () -> parse("foo=17"));
}
public void testParse_extraCommaIsInvalid() {
- try {
- parse("weakKeys,");
- fail("Expected exception");
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(IllegalArgumentException.class, () -> parse("weakKeys,"));
- try {
- parse(",weakKeys");
- fail("Expected exception");
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(IllegalArgumentException.class, () -> parse(",weakKeys"));
- try {
- parse("weakKeys,,softValues");
- fail("Expected exception");
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(IllegalArgumentException.class, () -> parse("weakKeys,,softValues"));
}
public void testEqualsAndHashCode() {
@@ -477,11 +398,9 @@ public class CacheBuilderSpecTest extends TestCase {
@SuppressWarnings("ReturnValueIgnored")
public void testMaximumWeight_withoutWeigher() {
CacheBuilder<Object, Object> builder = CacheBuilder.from(parse("maximumWeight=9000"));
- try {
- builder.build(CacheLoader.from(Suppliers.ofInstance(null)));
- fail();
- } catch (IllegalStateException expected) {
- }
+ assertThrows(
+ IllegalStateException.class,
+ () -> builder.build(CacheLoader.from(Suppliers.ofInstance(null))));
}
@SuppressWarnings("ReturnValueIgnored")