diff --git a/guava-gwt/test-super/com/google/common/base/super/com/google/common/base/EnumsTest.java b/guava-gwt/test-super/com/google/common/base/super/com/google/common/base/EnumsTest.java index c61855a8ff08..963fe73229b3 100644 --- a/guava-gwt/test-super/com/google/common/base/super/com/google/common/base/EnumsTest.java +++ b/guava-gwt/test-super/com/google/common/base/super/com/google/common/base/EnumsTest.java @@ -16,6 +16,8 @@ package com.google.common.base; +import static com.google.common.truth.Truth.assertThat; + import com.google.common.annotations.GwtCompatible; import com.google.common.testing.SerializableTester; @@ -41,27 +43,27 @@ private enum TestEnum { private enum OtherEnum {} public void testGetIfPresent() { - assertEquals(Optional.of(TestEnum.CHEETO), Enums.getIfPresent(TestEnum.class, "CHEETO")); - assertEquals(Optional.of(TestEnum.HONDA), Enums.getIfPresent(TestEnum.class, "HONDA")); - assertEquals(Optional.of(TestEnum.POODLE), Enums.getIfPresent(TestEnum.class, "POODLE")); + assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).hasValue(TestEnum.CHEETO); + assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).hasValue(TestEnum.HONDA); + assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).hasValue(TestEnum.POODLE); - assertTrue(Enums.getIfPresent(TestEnum.class, "CHEETO").isPresent()); - assertTrue(Enums.getIfPresent(TestEnum.class, "HONDA").isPresent()); - assertTrue(Enums.getIfPresent(TestEnum.class, "POODLE").isPresent()); + assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).isPresent(); + assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).isPresent(); + assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).isPresent(); - assertEquals(TestEnum.CHEETO, Enums.getIfPresent(TestEnum.class, "CHEETO").get()); - assertEquals(TestEnum.HONDA, Enums.getIfPresent(TestEnum.class, "HONDA").get()); - assertEquals(TestEnum.POODLE, Enums.getIfPresent(TestEnum.class, "POODLE").get()); + assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).hasValue(TestEnum.CHEETO); + assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).hasValue(TestEnum.HONDA); + assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).hasValue(TestEnum.POODLE); } public void testGetIfPresent_caseSensitive() { - assertFalse(Enums.getIfPresent(TestEnum.class, "cHEETO").isPresent()); - assertFalse(Enums.getIfPresent(TestEnum.class, "Honda").isPresent()); - assertFalse(Enums.getIfPresent(TestEnum.class, "poodlE").isPresent()); + assertThat(Enums.getIfPresent(TestEnum.class, "cHEETO")).isAbsent(); + assertThat(Enums.getIfPresent(TestEnum.class, "Honda")).isAbsent(); + assertThat(Enums.getIfPresent(TestEnum.class, "poodlE")).isAbsent(); } public void testGetIfPresent_whenNoMatchingConstant() { - assertEquals(Optional.absent(), Enums.getIfPresent(TestEnum.class, "WOMBAT")); + assertThat(Enums.getIfPresent(TestEnum.class, "WOMBAT")).isAbsent(); } // Create a second ClassLoader and use it to get a second version of the TestEnum class. diff --git a/guava-gwt/test-super/com/google/common/base/super/com/google/common/base/PreconditionsTest.java b/guava-gwt/test-super/com/google/common/base/super/com/google/common/base/PreconditionsTest.java index e35864a4574e..bb4bc091d6ae 100644 --- a/guava-gwt/test-super/com/google/common/base/super/com/google/common/base/PreconditionsTest.java +++ b/guava-gwt/test-super/com/google/common/base/super/com/google/common/base/PreconditionsTest.java @@ -16,6 +16,8 @@ package com.google.common.base; +import static com.google.common.truth.Truth.assertThat; + import com.google.common.annotations.GwtCompatible; import junit.framework.AssertionFailedError; @@ -59,7 +61,7 @@ public void testCheckArgument_nullMessage_failure() { Preconditions.checkArgument(false, null); fail("no exception thrown"); } catch (IllegalArgumentException expected) { - assertEquals("null", expected.getMessage()); + assertThat(expected).hasMessage("null"); } } @@ -106,7 +108,7 @@ public void testCheckState_nullMessage_failure() { Preconditions.checkState(false, null); fail("no exception thrown"); } catch (IllegalStateException expected) { - assertEquals("null", expected.getMessage()); + assertThat(expected).hasMessage("null"); } } @@ -188,7 +190,7 @@ public void testCheckElementIndex_negative() { Preconditions.checkElementIndex(-1, 1); fail(); } catch (IndexOutOfBoundsException expected) { - assertEquals("index (-1) must not be negative", expected.getMessage()); + assertThat(expected).hasMessage("index (-1) must not be negative"); } } @@ -197,8 +199,7 @@ public void testCheckElementIndex_tooHigh() { Preconditions.checkElementIndex(1, 1); fail(); } catch (IndexOutOfBoundsException expected) { - assertEquals("index (1) must be less than size (1)", - expected.getMessage()); + assertThat(expected).hasMessage("index (1) must be less than size (1)"); } } @@ -207,7 +208,7 @@ public void testCheckElementIndex_withDesc_negative() { Preconditions.checkElementIndex(-1, 1, "foo"); fail(); } catch (IndexOutOfBoundsException expected) { - assertEquals("foo (-1) must not be negative", expected.getMessage()); + assertThat(expected).hasMessage("foo (-1) must not be negative"); } } @@ -216,8 +217,7 @@ public void testCheckElementIndex_withDesc_tooHigh() { Preconditions.checkElementIndex(1, 1, "foo"); fail(); } catch (IndexOutOfBoundsException expected) { - assertEquals("foo (1) must be less than size (1)", - expected.getMessage()); + assertThat(expected).hasMessage("foo (1) must be less than size (1)"); } } @@ -242,7 +242,7 @@ public void testCheckPositionIndex_negative() { Preconditions.checkPositionIndex(-1, 1); fail(); } catch (IndexOutOfBoundsException expected) { - assertEquals("index (-1) must not be negative", expected.getMessage()); + assertThat(expected).hasMessage("index (-1) must not be negative"); } } @@ -251,8 +251,7 @@ public void testCheckPositionIndex_tooHigh() { Preconditions.checkPositionIndex(2, 1); fail(); } catch (IndexOutOfBoundsException expected) { - assertEquals("index (2) must not be greater than size (1)", - expected.getMessage()); + assertThat(expected).hasMessage("index (2) must not be greater than size (1)"); } } @@ -261,7 +260,7 @@ public void testCheckPositionIndex_withDesc_negative() { Preconditions.checkPositionIndex(-1, 1, "foo"); fail(); } catch (IndexOutOfBoundsException expected) { - assertEquals("foo (-1) must not be negative", expected.getMessage()); + assertThat(expected).hasMessage("foo (-1) must not be negative"); } } @@ -270,8 +269,7 @@ public void testCheckPositionIndex_withDesc_tooHigh() { Preconditions.checkPositionIndex(2, 1, "foo"); fail(); } catch (IndexOutOfBoundsException expected) { - assertEquals("foo (2) must not be greater than size (1)", - expected.getMessage()); + assertThat(expected).hasMessage("foo (2) must not be greater than size (1)"); } } @@ -295,8 +293,7 @@ public void testCheckPositionIndex_startNegative() { Preconditions.checkPositionIndexes(-1, 1, 1); fail(); } catch (IndexOutOfBoundsException expected) { - assertEquals("start index (-1) must not be negative", - expected.getMessage()); + assertThat(expected).hasMessage("start index (-1) must not be negative"); } } @@ -305,8 +302,7 @@ public void testCheckPositionIndexes_endTooHigh() { Preconditions.checkPositionIndexes(0, 2, 1); fail(); } catch (IndexOutOfBoundsException expected) { - assertEquals("end index (2) must not be greater than size (1)", - expected.getMessage()); + assertThat(expected).hasMessage("end index (2) must not be greater than size (1)"); } } @@ -315,8 +311,7 @@ public void testCheckPositionIndexes_reversed() { Preconditions.checkPositionIndexes(1, 0, 1); fail(); } catch (IndexOutOfBoundsException expected) { - assertEquals("end index (0) must not be less than start index (1)", - expected.getMessage()); + assertThat(expected).hasMessage("end index (0) must not be less than start index (1)"); } } @@ -356,10 +351,10 @@ private static class Message { private static final String FORMAT = "I ate %s pies."; private static void verifySimpleMessage(Exception e) { - assertEquals("A message", e.getMessage()); + assertThat(e).hasMessage("A message"); } private static void verifyComplexMessage(Exception e) { - assertEquals("I ate 5 pies.", e.getMessage()); + assertThat(e).hasMessage("I ate 5 pies."); } } diff --git a/guava-gwt/test-super/com/google/common/base/super/com/google/common/base/Utf8Test.java b/guava-gwt/test-super/com/google/common/base/super/com/google/common/base/Utf8Test.java index 7e9bd206888c..95b5c62f82fb 100644 --- a/guava-gwt/test-super/com/google/common/base/super/com/google/common/base/Utf8Test.java +++ b/guava-gwt/test-super/com/google/common/base/super/com/google/common/base/Utf8Test.java @@ -16,6 +16,7 @@ package com.google.common.base; +import static com.google.common.truth.Truth.assertThat; import static java.lang.Character.MAX_CODE_POINT; import static java.lang.Character.MAX_HIGH_SURROGATE; import static java.lang.Character.MAX_LOW_SURROGATE; @@ -121,8 +122,7 @@ private static void testEncodedLengthFails(String invalidString, Utf8.encodedLength(invalidString); fail(); } catch (IllegalArgumentException expected) { - assertEquals("Unpaired surrogate at index " + invalidCodePointIndex, - expected.getMessage()); + assertThat(expected).hasMessage("Unpaired surrogate at index " + invalidCodePointIndex); } } diff --git a/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/ArrayTableTest.java b/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/ArrayTableTest.java index 4dd7af5fda50..817ce6847604 100644 --- a/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/ArrayTableTest.java +++ b/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/ArrayTableTest.java @@ -362,13 +362,13 @@ public void testPutIllegal() { table.put("dog", 1, 'd'); fail(); } catch (IllegalArgumentException expected) { - assertEquals("Row dog not in [foo, bar, cat]", expected.getMessage()); + assertThat(expected).hasMessage("Row dog not in [foo, bar, cat]"); } try { table.put("foo", 4, 'd'); fail(); } catch (IllegalArgumentException expected) { - assertEquals("Column 4 not in [1, 2, 3]", expected.getMessage()); + assertThat(expected).hasMessage("Column 4 not in [1, 2, 3]"); } assertFalse(table.containsValue('d')); } @@ -422,7 +422,7 @@ public void testRowPutIllegal() { map.put(4, 'd'); fail(); } catch (IllegalArgumentException expected) { - assertEquals("Column 4 not in [1, 2, 3]", expected.getMessage()); + assertThat(expected).hasMessage("Column 4 not in [1, 2, 3]"); } } @@ -433,7 +433,7 @@ public void testColumnPutIllegal() { map.put("dog", 'd'); fail(); } catch (IllegalArgumentException expected) { - assertEquals("Row dog not in [foo, bar, cat]", expected.getMessage()); + assertThat(expected).hasMessage("Row dog not in [foo, bar, cat]"); } } } diff --git a/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/ImmutableBiMapTest.java b/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/ImmutableBiMapTest.java index 0033bcfb25d8..b71116e49308 100644 --- a/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/ImmutableBiMapTest.java +++ b/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/ImmutableBiMapTest.java @@ -278,7 +278,7 @@ public void testPuttingTheSameKeyTwiceThrowsOnBuild() { builder.build(); fail(); } catch (IllegalArgumentException expected) { - assertTrue(expected.getMessage().contains("one")); + assertThat(expected.getMessage()).contains("one"); } } @@ -351,7 +351,7 @@ public void testOfWithDuplicateKey() { ImmutableBiMap.of("one", 1, "one", 1); fail(); } catch (IllegalArgumentException expected) { - assertTrue(expected.getMessage().contains("one")); + assertThat(expected.getMessage()).contains("one"); } } @@ -425,7 +425,7 @@ public void testDuplicateValues() { ImmutableBiMap.copyOf(map); fail(); } catch (IllegalArgumentException expected) { - assertTrue(expected.getMessage().contains("1")); + assertThat(expected.getMessage()).contains("1"); } } } diff --git a/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/ImmutableSetMultimapTest.java b/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/ImmutableSetMultimapTest.java index db3b56531226..6365e3560f3d 100644 --- a/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/ImmutableSetMultimapTest.java +++ b/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/ImmutableSetMultimapTest.java @@ -240,9 +240,9 @@ public void testBuilderOrderKeysBy() { assertThat(multimap.values()).containsExactly(2, 4, 3, 6, 5, 2).inOrder(); assertThat(multimap.get("a")).containsExactly(5, 2).inOrder(); assertThat(multimap.get("b")).containsExactly(3, 6).inOrder(); - assertFalse(multimap.get("a") instanceof ImmutableSortedSet); - assertFalse(multimap.get("x") instanceof ImmutableSortedSet); - assertFalse(multimap.asMap().get("a") instanceof ImmutableSortedSet); + assertThat(multimap.get("a")).isNotInstanceOf(ImmutableSortedSet.class); + assertThat(multimap.get("x")).isNotInstanceOf(ImmutableSortedSet.class); + assertThat(multimap.asMap().get("a")).isNotInstanceOf(ImmutableSortedSet.class); } public void testBuilderOrderKeysByDuplicates() { @@ -265,9 +265,9 @@ public int compare(String left, String right) { assertThat(multimap.values()).containsExactly(2, 5, 2, 3, 6, 4).inOrder(); assertThat(multimap.get("a")).containsExactly(5, 2).inOrder(); assertThat(multimap.get("bb")).containsExactly(3, 6).inOrder(); - assertFalse(multimap.get("a") instanceof ImmutableSortedSet); - assertFalse(multimap.get("x") instanceof ImmutableSortedSet); - assertFalse(multimap.asMap().get("a") instanceof ImmutableSortedSet); + assertThat(multimap.get("a")).isNotInstanceOf(ImmutableSortedSet.class); + assertThat(multimap.get("x")).isNotInstanceOf(ImmutableSortedSet.class); + assertThat(multimap.asMap().get("a")).isNotInstanceOf(ImmutableSortedSet.class); } public void testBuilderOrderValuesBy() { diff --git a/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/IterablesTest.java b/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/IterablesTest.java index 9b85c5ed3e7f..68101eccc1c8 100644 --- a/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/IterablesTest.java +++ b/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/IterablesTest.java @@ -26,7 +26,6 @@ import com.google.common.annotations.GwtCompatible; import com.google.common.base.Function; -import com.google.common.base.Optional; import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.collect.testing.IteratorTester; @@ -234,14 +233,10 @@ public void testFind_withDefault() { public void testTryFind() { Iterable list = newArrayList("cool", "pants"); - assertEquals(Optional.of("cool"), - Iterables.tryFind(list, Predicates.equalTo("cool"))); - assertEquals(Optional.of("pants"), - Iterables.tryFind(list, Predicates.equalTo("pants"))); - assertEquals(Optional.of("cool"), - Iterables.tryFind(list, Predicates.alwaysTrue())); - assertEquals(Optional.absent(), - Iterables.tryFind(list, Predicates.alwaysFalse())); + assertThat(Iterables.tryFind(list, Predicates.equalTo("cool"))).hasValue("cool"); + assertThat(Iterables.tryFind(list, Predicates.equalTo("pants"))).hasValue("pants"); + assertThat(Iterables.tryFind(list, Predicates.alwaysTrue())).hasValue("cool"); + assertThat(Iterables.tryFind(list, Predicates.alwaysFalse())).isAbsent(); assertCanIterateAgain(list); } diff --git a/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/IteratorsTest.java b/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/IteratorsTest.java index 0324e7fafa5b..a1fd86b9dba5 100644 --- a/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/IteratorsTest.java +++ b/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/IteratorsTest.java @@ -172,8 +172,7 @@ public void testGetOnlyElement_noDefault_moreThanOneLessThanFiveElements() { Iterators.getOnlyElement(iterator); fail(); } catch (IllegalArgumentException expected) { - assertEquals("expected one element but was: ", - expected.getMessage()); + assertThat(expected).hasMessage("expected one element but was: "); } } @@ -184,9 +183,8 @@ public void testGetOnlyElement_noDefault_fiveElements() { Iterators.getOnlyElement(iterator); fail(); } catch (IllegalArgumentException expected) { - assertEquals("expected one element but was: " - + "", - expected.getMessage()); + assertThat(expected) + .hasMessage("expected one element but was: " + ""); } } @@ -197,9 +195,8 @@ public void testGetOnlyElement_noDefault_moreThanFiveElements() { Iterators.getOnlyElement(iterator); fail(); } catch (IllegalArgumentException expected) { - assertEquals("expected one element but was: " - + "", - expected.getMessage()); + assertThat(expected) + .hasMessage("expected one element but was: " + ""); } } @@ -224,8 +221,7 @@ public void testGetOnlyElement_withDefault_two() { Iterators.getOnlyElement(iterator, "x"); fail(); } catch (IllegalArgumentException expected) { - assertEquals("expected one element but was: ", - expected.getMessage()); + assertThat(expected).hasMessage("expected one element but was: "); } } @@ -368,22 +364,19 @@ public void testFind_withDefault_matchAlways() { public void testTryFind_firstElement() { Iterable list = Lists.newArrayList("cool", "pants"); Iterator iterator = list.iterator(); - assertEquals("cool", - Iterators.tryFind(iterator, Predicates.equalTo("cool")).get()); + assertThat(Iterators.tryFind(iterator, Predicates.equalTo("cool"))).hasValue("cool"); } public void testTryFind_lastElement() { Iterable list = Lists.newArrayList("cool", "pants"); Iterator iterator = list.iterator(); - assertEquals("pants", - Iterators.tryFind(iterator, Predicates.equalTo("pants")).get()); + assertThat(Iterators.tryFind(iterator, Predicates.equalTo("pants"))).hasValue("pants"); } public void testTryFind_alwaysTrue() { Iterable list = Lists.newArrayList("cool", "pants"); Iterator iterator = list.iterator(); - assertEquals("cool", - Iterators.tryFind(iterator, Predicates.alwaysTrue()).get()); + assertThat(Iterators.tryFind(iterator, Predicates.alwaysTrue())).hasValue("cool"); } public void testTryFind_alwaysFalse_orDefault() { @@ -397,8 +390,7 @@ public void testTryFind_alwaysFalse_orDefault() { public void testTryFind_alwaysFalse_isPresent() { Iterable list = Lists.newArrayList("cool", "pants"); Iterator iterator = list.iterator(); - assertFalse( - Iterators.tryFind(iterator, Predicates.alwaysFalse()).isPresent()); + assertThat(Iterators.tryFind(iterator, Predicates.alwaysFalse())).isAbsent(); assertFalse(iterator.hasNext()); } diff --git a/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/LinkedListMultimapTest.java b/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/LinkedListMultimapTest.java index 923cbc503998..ea7d041d4d7a 100644 --- a/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/LinkedListMultimapTest.java +++ b/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/LinkedListMultimapTest.java @@ -51,8 +51,8 @@ public void testGetRandomAccess() { Multimap multimap = create(); multimap.put("foo", 1); multimap.put("foo", 3); - assertFalse(multimap.get("foo") instanceof RandomAccess); - assertFalse(multimap.get("bar") instanceof RandomAccess); + assertThat(multimap.get("foo")).isNotInstanceOf(RandomAccess.class); + assertThat(multimap.get("bar")).isNotInstanceOf(RandomAccess.class); } /** diff --git a/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/ListsTest.java b/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/ListsTest.java index 55c88cf6ef2c..7f5a57c3f6db 100644 --- a/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/ListsTest.java +++ b/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/ListsTest.java @@ -442,7 +442,7 @@ public void testTransformRandomAccess() { public void testTransformSequential() { List list = Lists.transform(SOME_SEQUENTIAL_LIST, SOME_FUNCTION); - assertFalse(list instanceof RandomAccess); + assertThat(list).isNotInstanceOf(RandomAccess.class); } public void testTransformListIteratorRandomAccess() { @@ -598,9 +598,9 @@ public void testPartition_3_2() { public void testPartitionRandomAccessFalse() { List source = Lists.newLinkedList(asList(1, 2, 3)); List> partitions = Lists.partition(source, 2); - assertFalse(partitions instanceof RandomAccess); - assertFalse(partitions.get(0) instanceof RandomAccess); - assertFalse(partitions.get(1) instanceof RandomAccess); + assertThat(partitions).isNotInstanceOf(RandomAccess.class); + assertThat(partitions.get(0)).isNotInstanceOf(RandomAccess.class); + assertThat(partitions.get(1)).isNotInstanceOf(RandomAccess.class); } // TODO: use the suite builders diff --git a/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/MapConstraintsTest.java b/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/MapConstraintsTest.java index f1ec18ba7cab..05263d3c5c7c 100644 --- a/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/MapConstraintsTest.java +++ b/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/MapConstraintsTest.java @@ -110,7 +110,7 @@ public void testConstrainedMapLegal() { assertEquals(map.keySet(), constrained.keySet()); assertEquals(HashMultiset.create(map.values()), HashMultiset.create(constrained.values())); - assertFalse(map.values() instanceof Serializable); + assertThat(map.values()).isNotInstanceOf(Serializable.class); assertEquals(map.toString(), constrained.toString()); assertEquals(map.hashCode(), constrained.hashCode()); assertThat(map.entrySet()).containsExactly( @@ -251,9 +251,8 @@ public void testConstrainedMultimapLegal() { Maps.immutableEntry("bop", 9), Maps.immutableEntry("dig", 10), Maps.immutableEntry("dag", 11)).inOrder(); - assertFalse(constrained.asMap().values() instanceof Serializable); - Iterator> iterator = - constrained.asMap().values().iterator(); + assertThat(constrained.asMap().values()).isNotInstanceOf(Serializable.class); + Iterator> iterator = constrained.asMap().values().iterator(); iterator.next(); iterator.next().add(12); assertTrue(multimap.containsEntry("foo", 12)); diff --git a/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/MultimapsTest.java b/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/MultimapsTest.java index f8351c86090c..81fe77574531 100644 --- a/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/MultimapsTest.java +++ b/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/MultimapsTest.java @@ -28,7 +28,6 @@ import com.google.common.base.Functions; import com.google.common.base.Predicates; import com.google.common.base.Supplier; -import com.google.common.collect.Maps.EntryTransformer; import com.google.common.collect.testing.IteratorTester; import com.google.common.collect.testing.google.UnmodifiableCollectionTests; @@ -66,14 +65,6 @@ public class MultimapsTest extends TestCase { private static final Comparator INT_COMPARATOR = Ordering.natural().reverse().nullsFirst(); - private static final EntryTransformer ALWAYS_NULL = - new EntryTransformer() { - @Override - public Object transformEntry(Object k, Object v1) { - return null; - } - }; - @SuppressWarnings("deprecation") public void testUnmodifiableListMultimapShortCircuit() { ListMultimap mod = ArrayListMultimap.create(); @@ -125,10 +116,9 @@ public void testUnmodifiableLinkedListMultimapRandomAccess() { ListMultimap delegate = LinkedListMultimap.create(); delegate.put("foo", 1); delegate.put("foo", 3); - ListMultimap multimap - = Multimaps.unmodifiableListMultimap(delegate); - assertFalse(multimap.get("foo") instanceof RandomAccess); - assertFalse(multimap.get("bar") instanceof RandomAccess); + ListMultimap multimap = Multimaps.unmodifiableListMultimap(delegate); + assertThat(multimap.get("foo")).isNotInstanceOf(RandomAccess.class); + assertThat(multimap.get("bar")).isNotInstanceOf(RandomAccess.class); } public void testUnmodifiableMultimapIsView() { @@ -208,7 +198,7 @@ private static void checkUnmodifiableMultimap( assertThat(unmodifiable.asMap().get("bar")).containsExactly(5, -1); assertNull(unmodifiable.asMap().get("missing")); - assertFalse(unmodifiable.entries() instanceof Serializable); + assertThat(unmodifiable.entries()).isNotInstanceOf(Serializable.class); } /** @@ -537,8 +527,8 @@ public void testNewMultimap() { Collection collection = multimap.get(Color.BLUE); assertEquals(collection, collection); - assertFalse(multimap.keySet() instanceof SortedSet); - assertFalse(multimap.asMap() instanceof SortedMap); + assertThat(multimap.keySet()).isNotInstanceOf(SortedSet.class); + assertThat(multimap.asMap()).isNotInstanceOf(SortedMap.class); } private static class ListSupplier extends @@ -560,7 +550,7 @@ public void testNewListMultimap() { multimap.putAll(Color.RED, asList(2, 7, 1, 8)); assertEquals(2, factory.count); assertEquals("{BLUE=[3, 1, 4, 1], RED=[2, 7, 1, 8]}", multimap.toString()); - assertFalse(multimap.get(Color.BLUE) instanceof RandomAccess); + assertThat(multimap.get(Color.BLUE)).isNotInstanceOf(RandomAccess.class); assertTrue(multimap.keySet() instanceof SortedSet); assertTrue(multimap.asMap() instanceof SortedMap); diff --git a/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/ObjectArraysTest.java b/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/ObjectArraysTest.java index 48ad0d71d580..e6ff97ede798 100644 --- a/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/ObjectArraysTest.java +++ b/guava-gwt/test-super/com/google/common/collect/super/com/google/common/collect/ObjectArraysTest.java @@ -36,20 +36,20 @@ public class ObjectArraysTest extends TestCase { public void testNewArray_fromArray_Empty() { String[] in = new String[0]; String[] empty = ObjectArrays.newArray(in, 0); - assertEquals(0, empty.length); + assertThat(empty).isEmpty(); } public void testNewArray_fromArray_Nonempty() { String[] array = ObjectArrays.newArray(new String[0], 2); assertEquals(String[].class, array.getClass()); - assertEquals(2, array.length); + assertThat(array).hasLength(2); assertNull(array[0]); } public void testNewArray_fromArray_OfArray() { String[][] array = ObjectArrays.newArray(new String[0][0], 1); assertEquals(String[][].class, array.getClass()); - assertEquals(1, array.length); + assertThat(array).hasLength(1); assertNull(array[0]); } diff --git a/guava-gwt/test-super/com/google/common/net/super/com/google/common/net/MediaTypeTest.java b/guava-gwt/test-super/com/google/common/net/super/com/google/common/net/MediaTypeTest.java index 75e6f80edec5..571c7f97cf54 100644 --- a/guava-gwt/test-super/com/google/common/net/super/com/google/common/net/MediaTypeTest.java +++ b/guava-gwt/test-super/com/google/common/net/super/com/google/common/net/MediaTypeTest.java @@ -26,9 +26,9 @@ import static com.google.common.net.MediaType.HTML_UTF_8; import static com.google.common.net.MediaType.JPEG; import static com.google.common.net.MediaType.PLAIN_TEXT_UTF_8; +import static com.google.common.truth.Truth.assertThat; import com.google.common.annotations.GwtCompatible; -import com.google.common.base.Optional; import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.ImmutableMultimap; import com.google.common.testing.EqualsTester; @@ -271,9 +271,8 @@ public void testParse_badInput() { } public void testGetCharset() { - assertEquals(Optional.absent(), MediaType.parse("text/plain").charset()); - assertEquals(Optional.of(UTF_8), - MediaType.parse("text/plain; charset=utf-8").charset()); + assertThat(MediaType.parse("text/plain").charset()).isAbsent(); + assertThat(MediaType.parse("text/plain; charset=utf-8").charset()).hasValue(UTF_8); } public void testGetCharset_tooMany() { diff --git a/guava-gwt/test-super/com/google/common/util/concurrent/super/com/google/common/util/concurrent/FutureCallbackTest.java b/guava-gwt/test-super/com/google/common/util/concurrent/super/com/google/common/util/concurrent/FutureCallbackTest.java index 2302d58ad361..c05813f5e516 100644 --- a/guava-gwt/test-super/com/google/common/util/concurrent/super/com/google/common/util/concurrent/FutureCallbackTest.java +++ b/guava-gwt/test-super/com/google/common/util/concurrent/super/com/google/common/util/concurrent/FutureCallbackTest.java @@ -16,6 +16,8 @@ package com.google.common.util.concurrent; +import static com.google.common.truth.Truth.assertThat; + import com.google.common.annotations.GwtCompatible; import com.google.common.base.Preconditions; @@ -64,6 +66,7 @@ public void testCancel() { FutureCallback callback = new FutureCallback() { private boolean called = false; + @Override public void onSuccess(String result) { fail("Was not expecting onSuccess() to be called."); @@ -72,7 +75,7 @@ public void onSuccess(String result) { @Override public synchronized void onFailure(Throwable t) { assertFalse(called); - assertTrue(t instanceof CancellationException); + assertThat(t).isInstanceOf(CancellationException.class); called = true; } }; diff --git a/guava-gwt/test-super/com/google/common/util/concurrent/super/com/google/common/util/concurrent/FuturesTest.java b/guava-gwt/test-super/com/google/common/util/concurrent/super/com/google/common/util/concurrent/FuturesTest.java index f64b2193a332..1299f58a2403 100644 --- a/guava-gwt/test-super/com/google/common/util/concurrent/super/com/google/common/util/concurrent/FuturesTest.java +++ b/guava-gwt/test-super/com/google/common/util/concurrent/super/com/google/common/util/concurrent/FuturesTest.java @@ -1282,9 +1282,9 @@ public void testAllAsList_logging_exception() throws Exception { Futures.allAsList(immediateFailedFuture(new MyException())).get(); fail(); } catch (ExecutionException e) { - assertTrue(e.getCause() instanceof MyException); - assertEquals("Nothing should be logged", 0, - aggregateFutureLogHandler.getStoredLogRecords().size()); + assertThat(e.getCause()).isInstanceOf(MyException.class); + assertEquals( + "Nothing should be logged", 0, aggregateFutureLogHandler.getStoredLogRecords().size()); } } @@ -1297,10 +1297,10 @@ public void testAllAsList_logging_error() throws Exception { Futures.allAsList(immediateFailedFuture(new MyError())).get(); fail(); } catch (ExecutionException e) { - assertTrue(e.getCause() instanceof MyError); + assertThat(e.getCause()).isInstanceOf(MyError.class); List logged = aggregateFutureLogHandler.getStoredLogRecords(); - assertEquals(1, logged.size()); // errors are always logged - assertTrue(logged.get(0).getThrown() instanceof MyError); + assertThat(logged).hasSize(1); // errors are always logged + assertThat(logged.get(0).getThrown()).isInstanceOf(MyError.class); } } @@ -1314,10 +1314,10 @@ public void testAllAsList_logging_multipleExceptions_alreadyDone() throws Except immediateFailedFuture(new MyException())).get(); fail(); } catch (ExecutionException e) { - assertTrue(e.getCause() instanceof MyException); + assertThat(e.getCause()).isInstanceOf(MyException.class); List logged = aggregateFutureLogHandler.getStoredLogRecords(); - assertEquals(1, logged.size()); // the second failure is logged - assertTrue(logged.get(0).getThrown() instanceof MyException); + assertThat(logged).hasSize(1); // the second failure is logged + assertThat(logged.get(0).getThrown()).isInstanceOf(MyException.class); } } @@ -1339,9 +1339,9 @@ public void testAllAsList_logging_multipleExceptions_doneLater() throws Exceptio all.get(); } catch (ExecutionException e) { List logged = aggregateFutureLogHandler.getStoredLogRecords(); - assertEquals(2, logged.size()); // failures are the first are logged - assertTrue(logged.get(0).getThrown() instanceof MyException); - assertTrue(logged.get(1).getThrown() instanceof MyException); + assertThat(logged).hasSize(2); // failures after the first are logged + assertThat(logged.get(0).getThrown()).isInstanceOf(MyException.class); + assertThat(logged.get(1).getThrown()).isInstanceOf(MyException.class); } } @@ -1356,9 +1356,9 @@ public void testAllAsList_logging_same_exception() throws Exception { immediateFailedFuture(sameInstance)).get(); fail(); } catch (ExecutionException e) { - assertTrue(e.getCause() instanceof MyException); - assertEquals("Nothing should be logged", 0, - aggregateFutureLogHandler.getStoredLogRecords().size()); + assertThat(e.getCause()).isInstanceOf(MyException.class); + assertEquals( + "Nothing should be logged", 0, aggregateFutureLogHandler.getStoredLogRecords().size()); } } @@ -1385,7 +1385,7 @@ public void run() { bulkFuture.get(); fail(); } catch (ExecutionException expected) { - assertTrue(expected.getCause() instanceof MyException); + assertThat(expected.getCause()).isInstanceOf(MyException.class); assertThat(aggregateFutureLogHandler.getStoredLogRecords()).isEmpty(); } } @@ -1436,9 +1436,9 @@ public void testAllAsList_logging_same_cause() throws Exception { immediateFailedFuture(exception3)).get(); fail(); } catch (ExecutionException e) { - assertTrue(e.getCause() instanceof MyException); - assertEquals("Nothing should be logged", 0, - aggregateFutureLogHandler.getStoredLogRecords().size()); + assertThat(e.getCause()).isInstanceOf(MyException.class); + assertEquals( + "Nothing should be logged", 0, aggregateFutureLogHandler.getStoredLogRecords().size()); } } @@ -1481,8 +1481,8 @@ public void testSuccessfulAsList_logging_error() throws Exception { Futures.successfulAsList( immediateFailedFuture(new MyError())).get()); List logged = aggregateFutureLogHandler.getStoredLogRecords(); - assertEquals(1, logged.size()); // errors are always logged - assertTrue(logged.get(0).getThrown() instanceof MyError); + assertThat(logged).hasSize(1); // errors are always logged + assertThat(logged.get(0).getThrown()).isInstanceOf(MyError.class); } // Mostly an example of how it would look like to use a list of mixed types diff --git a/guava-testlib/test/com/google/common/testing/ArbitraryInstancesTest.java b/guava-testlib/test/com/google/common/testing/ArbitraryInstancesTest.java index e18f51ed5b52..e94d28360425 100644 --- a/guava-testlib/test/com/google/common/testing/ArbitraryInstancesTest.java +++ b/guava-testlib/test/com/google/common/testing/ArbitraryInstancesTest.java @@ -16,6 +16,8 @@ package com.google.common.testing; +import static com.google.common.truth.Truth.assertThat; + import com.google.common.base.CharMatcher; import com.google.common.base.Charsets; import com.google.common.base.Equivalence; @@ -224,7 +226,7 @@ public void testGet_misc() { assertNotNull(ArbitraryInstances.get(Locale.class)); assertNotNull(ArbitraryInstances.get(Joiner.class).join(ImmutableList.of("a"))); assertNotNull(ArbitraryInstances.get(Splitter.class).split("a,b")); - assertFalse(ArbitraryInstances.get(Optional.class).isPresent()); + assertThat(ArbitraryInstances.get(Optional.class)).isAbsent(); ArbitraryInstances.get(Stopwatch.class).start(); assertNotNull(ArbitraryInstances.get(Ticker.class)); assertNotNull(ArbitraryInstances.get(MapConstraint.class)); @@ -271,9 +273,9 @@ public void testGet_comparable() { } public void testGet_array() { - assertEquals(0, ArbitraryInstances.get(int[].class).length); - assertEquals(0, ArbitraryInstances.get(Object[].class).length); - assertEquals(0, ArbitraryInstances.get(String[].class).length); + assertThat(ArbitraryInstances.get(int[].class)).isEmpty(); + assertThat(ArbitraryInstances.get(Object[].class)).isEmpty(); + assertThat(ArbitraryInstances.get(String[].class)).isEmpty(); } public void testGet_enum() { @@ -302,13 +304,17 @@ public void testGet_class() { public void testGet_mutable() { assertEquals(0, ArbitraryInstances.get(ArrayList.class).size()); assertEquals(0, ArbitraryInstances.get(HashMap.class).size()); - assertEquals("", ArbitraryInstances.get(Appendable.class).toString()); - assertEquals("", ArbitraryInstances.get(StringBuilder.class).toString()); - assertEquals("", ArbitraryInstances.get(StringBuffer.class).toString()); + assertThat(ArbitraryInstances.get(Appendable.class).toString()).isEmpty(); + assertThat(ArbitraryInstances.get(StringBuilder.class).toString()).isEmpty(); + assertThat(ArbitraryInstances.get(StringBuffer.class).toString()).isEmpty(); assertFreshInstanceReturned( - ArrayList.class, HashMap.class, - Appendable.class, StringBuilder.class, StringBuffer.class, - Throwable.class, Exception.class); + ArrayList.class, + HashMap.class, + Appendable.class, + StringBuilder.class, + StringBuffer.class, + Throwable.class, + Exception.class); } public void testGet_io() throws IOException { diff --git a/guava-testlib/test/com/google/common/testing/ClassSanityTesterTest.java b/guava-testlib/test/com/google/common/testing/ClassSanityTesterTest.java index 3665c1b02ec4..639b73ff33aa 100644 --- a/guava-testlib/test/com/google/common/testing/ClassSanityTesterTest.java +++ b/guava-testlib/test/com/google/common/testing/ClassSanityTesterTest.java @@ -84,10 +84,11 @@ public void testForAllPublicStaticMethods_noPublicStaticMethods() throws Excepti try { tester.forAllPublicStaticMethods(NoPublicStaticMethods.class).testEquals(); } catch (AssertionFailedError expected) { - assertEquals( - "No public static methods that return java.lang.Object or subtype are found in " - + NoPublicStaticMethods.class + ".", - expected.getMessage()); + assertThat(expected) + .hasMessage( + "No public static methods that return java.lang.Object or subtype are found in " + + NoPublicStaticMethods.class + + "."); return; } fail(); @@ -141,10 +142,11 @@ public void testNullsOnReturnValues_returnTypeFiltered() throws Exception { .thatReturn(Iterable.class) .testNulls(); } catch (AssertionFailedError expected) { - assertEquals( - "No public static methods that return java.lang.Iterable or subtype are found in " - + BadNullsFactory.class + ".", - expected.getMessage()); + assertThat(expected) + .hasMessage( + "No public static methods that return java.lang.Iterable or subtype are found in " + + BadNullsFactory.class + + "."); return; } fail(); diff --git a/guava-testlib/test/com/google/common/testing/GcFinalizationTest.java b/guava-testlib/test/com/google/common/testing/GcFinalizationTest.java index 117186f4e749..bcf501b9e6e9 100644 --- a/guava-testlib/test/com/google/common/testing/GcFinalizationTest.java +++ b/guava-testlib/test/com/google/common/testing/GcFinalizationTest.java @@ -16,6 +16,8 @@ package com.google.common.testing; +import static com.google.common.truth.Truth.assertThat; + import com.google.common.testing.GcFinalization.FinalizationPredicate; import com.google.common.util.concurrent.SettableFuture; @@ -118,8 +120,8 @@ void shutdown() { } void assertWrapsInterruptedException(RuntimeException e) { - assertTrue(e.getMessage().contains("Unexpected interrupt")); - assertTrue(e.getCause() instanceof InterruptedException); + assertThat(e.getMessage()).contains("Unexpected interrupt"); + assertThat(e.getCause()).isInstanceOf(InterruptedException.class); } public void testAwait_CountDownLatch_Interrupted() { diff --git a/guava-testlib/test/com/google/common/testing/NullPointerTesterTest.java b/guava-testlib/test/com/google/common/testing/NullPointerTesterTest.java index 0023a40a6cd0..8bedfd9f060d 100644 --- a/guava-testlib/test/com/google/common/testing/NullPointerTesterTest.java +++ b/guava-testlib/test/com/google/common/testing/NullPointerTesterTest.java @@ -902,7 +902,7 @@ public void checkArray(Object[] array, String s) { void check() { runTester(); Object[] defaultArray = (Object[]) getDefaultParameterValue(0); - assertEquals(0, defaultArray.length); + assertThat(defaultArray).isEmpty(); } } @@ -921,7 +921,7 @@ public void checkArray(String[] array, String s) { void check() { runTester(); String[] defaultArray = (String[]) getDefaultParameterValue(0); - assertEquals(0, defaultArray.length); + assertThat(defaultArray).isEmpty(); } } diff --git a/guava-testlib/test/com/google/common/testing/TearDownStackTest.java b/guava-testlib/test/com/google/common/testing/TearDownStackTest.java index 7c3aa6e436e9..30c0db85e31d 100644 --- a/guava-testlib/test/com/google/common/testing/TearDownStackTest.java +++ b/guava-testlib/test/com/google/common/testing/TearDownStackTest.java @@ -16,6 +16,8 @@ package com.google.common.testing; +import static com.google.common.truth.Truth.assertThat; + import com.google.common.annotations.GwtCompatible; import junit.framework.TestCase; @@ -83,7 +85,7 @@ public void testThrowingTearDown() throws Exception { stack.runTearDown(); fail("runTearDown should have thrown an exception"); } catch (ClusterException expected) { - assertEquals("two", expected.getCause().getMessage()); + assertThat(expected.getCause()).hasMessage("two"); } catch (RuntimeException e) { throw new RuntimeException( "A ClusterException should have been thrown, rather than a " + e.getClass().getName(), e); diff --git a/guava-tests/test/com/google/common/base/EnumsTest.java b/guava-tests/test/com/google/common/base/EnumsTest.java index a5faed2c0446..69c65fc01675 100644 --- a/guava-tests/test/com/google/common/base/EnumsTest.java +++ b/guava-tests/test/com/google/common/base/EnumsTest.java @@ -16,6 +16,8 @@ package com.google.common.base; +import static com.google.common.truth.Truth.assertThat; + import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import com.google.common.collect.ImmutableSet; @@ -50,27 +52,27 @@ private enum TestEnum { private enum OtherEnum {} public void testGetIfPresent() { - assertEquals(Optional.of(TestEnum.CHEETO), Enums.getIfPresent(TestEnum.class, "CHEETO")); - assertEquals(Optional.of(TestEnum.HONDA), Enums.getIfPresent(TestEnum.class, "HONDA")); - assertEquals(Optional.of(TestEnum.POODLE), Enums.getIfPresent(TestEnum.class, "POODLE")); + assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).hasValue(TestEnum.CHEETO); + assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).hasValue(TestEnum.HONDA); + assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).hasValue(TestEnum.POODLE); - assertTrue(Enums.getIfPresent(TestEnum.class, "CHEETO").isPresent()); - assertTrue(Enums.getIfPresent(TestEnum.class, "HONDA").isPresent()); - assertTrue(Enums.getIfPresent(TestEnum.class, "POODLE").isPresent()); + assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).isPresent(); + assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).isPresent(); + assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).isPresent(); - assertEquals(TestEnum.CHEETO, Enums.getIfPresent(TestEnum.class, "CHEETO").get()); - assertEquals(TestEnum.HONDA, Enums.getIfPresent(TestEnum.class, "HONDA").get()); - assertEquals(TestEnum.POODLE, Enums.getIfPresent(TestEnum.class, "POODLE").get()); + assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).hasValue(TestEnum.CHEETO); + assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).hasValue(TestEnum.HONDA); + assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).hasValue(TestEnum.POODLE); } public void testGetIfPresent_caseSensitive() { - assertFalse(Enums.getIfPresent(TestEnum.class, "cHEETO").isPresent()); - assertFalse(Enums.getIfPresent(TestEnum.class, "Honda").isPresent()); - assertFalse(Enums.getIfPresent(TestEnum.class, "poodlE").isPresent()); + assertThat(Enums.getIfPresent(TestEnum.class, "cHEETO")).isAbsent(); + assertThat(Enums.getIfPresent(TestEnum.class, "Honda")).isAbsent(); + assertThat(Enums.getIfPresent(TestEnum.class, "poodlE")).isAbsent(); } public void testGetIfPresent_whenNoMatchingConstant() { - assertEquals(Optional.absent(), Enums.getIfPresent(TestEnum.class, "WOMBAT")); + assertThat(Enums.getIfPresent(TestEnum.class, "WOMBAT")).isAbsent(); } @GwtIncompatible("weak references") @@ -95,12 +97,12 @@ private WeakReference doTestClassUnloading() throws Exception { Set shadowConstants = new HashSet(); for (TestEnum constant : TestEnum.values()) { Optional result = Enums.getIfPresent(shadowTestEnum, constant.name()); - assertTrue(result.isPresent()); + assertThat(result).isPresent(); shadowConstants.add(result.get()); } assertEquals(ImmutableSet.copyOf(shadowTestEnum.getEnumConstants()), shadowConstants); Optional result = Enums.getIfPresent(shadowTestEnum, "blibby"); - assertFalse(result.isPresent()); + assertThat(result).isAbsent(); return new WeakReference(shadowLoader); } diff --git a/guava-tests/test/com/google/common/base/PreconditionsTest.java b/guava-tests/test/com/google/common/base/PreconditionsTest.java index df44a3fe26d1..e4b1aa8fd8ff 100644 --- a/guava-tests/test/com/google/common/base/PreconditionsTest.java +++ b/guava-tests/test/com/google/common/base/PreconditionsTest.java @@ -16,6 +16,8 @@ package com.google.common.base; +import static com.google.common.truth.Truth.assertThat; + import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import com.google.common.testing.NullPointerTester; @@ -61,7 +63,7 @@ public void testCheckArgument_nullMessage_failure() { Preconditions.checkArgument(false, null); fail("no exception thrown"); } catch (IllegalArgumentException expected) { - assertEquals("null", expected.getMessage()); + assertThat(expected).hasMessage("null"); } } @@ -108,7 +110,7 @@ public void testCheckState_nullMessage_failure() { Preconditions.checkState(false, null); fail("no exception thrown"); } catch (IllegalStateException expected) { - assertEquals("null", expected.getMessage()); + assertThat(expected).hasMessage("null"); } } @@ -190,7 +192,7 @@ public void testCheckElementIndex_negative() { Preconditions.checkElementIndex(-1, 1); fail(); } catch (IndexOutOfBoundsException expected) { - assertEquals("index (-1) must not be negative", expected.getMessage()); + assertThat(expected).hasMessage("index (-1) must not be negative"); } } @@ -199,8 +201,7 @@ public void testCheckElementIndex_tooHigh() { Preconditions.checkElementIndex(1, 1); fail(); } catch (IndexOutOfBoundsException expected) { - assertEquals("index (1) must be less than size (1)", - expected.getMessage()); + assertThat(expected).hasMessage("index (1) must be less than size (1)"); } } @@ -209,7 +210,7 @@ public void testCheckElementIndex_withDesc_negative() { Preconditions.checkElementIndex(-1, 1, "foo"); fail(); } catch (IndexOutOfBoundsException expected) { - assertEquals("foo (-1) must not be negative", expected.getMessage()); + assertThat(expected).hasMessage("foo (-1) must not be negative"); } } @@ -218,8 +219,7 @@ public void testCheckElementIndex_withDesc_tooHigh() { Preconditions.checkElementIndex(1, 1, "foo"); fail(); } catch (IndexOutOfBoundsException expected) { - assertEquals("foo (1) must be less than size (1)", - expected.getMessage()); + assertThat(expected).hasMessage("foo (1) must be less than size (1)"); } } @@ -244,7 +244,7 @@ public void testCheckPositionIndex_negative() { Preconditions.checkPositionIndex(-1, 1); fail(); } catch (IndexOutOfBoundsException expected) { - assertEquals("index (-1) must not be negative", expected.getMessage()); + assertThat(expected).hasMessage("index (-1) must not be negative"); } } @@ -253,8 +253,7 @@ public void testCheckPositionIndex_tooHigh() { Preconditions.checkPositionIndex(2, 1); fail(); } catch (IndexOutOfBoundsException expected) { - assertEquals("index (2) must not be greater than size (1)", - expected.getMessage()); + assertThat(expected).hasMessage("index (2) must not be greater than size (1)"); } } @@ -263,7 +262,7 @@ public void testCheckPositionIndex_withDesc_negative() { Preconditions.checkPositionIndex(-1, 1, "foo"); fail(); } catch (IndexOutOfBoundsException expected) { - assertEquals("foo (-1) must not be negative", expected.getMessage()); + assertThat(expected).hasMessage("foo (-1) must not be negative"); } } @@ -272,8 +271,7 @@ public void testCheckPositionIndex_withDesc_tooHigh() { Preconditions.checkPositionIndex(2, 1, "foo"); fail(); } catch (IndexOutOfBoundsException expected) { - assertEquals("foo (2) must not be greater than size (1)", - expected.getMessage()); + assertThat(expected).hasMessage("foo (2) must not be greater than size (1)"); } } @@ -297,8 +295,7 @@ public void testCheckPositionIndex_startNegative() { Preconditions.checkPositionIndexes(-1, 1, 1); fail(); } catch (IndexOutOfBoundsException expected) { - assertEquals("start index (-1) must not be negative", - expected.getMessage()); + assertThat(expected).hasMessage("start index (-1) must not be negative"); } } @@ -307,8 +304,7 @@ public void testCheckPositionIndexes_endTooHigh() { Preconditions.checkPositionIndexes(0, 2, 1); fail(); } catch (IndexOutOfBoundsException expected) { - assertEquals("end index (2) must not be greater than size (1)", - expected.getMessage()); + assertThat(expected).hasMessage("end index (2) must not be greater than size (1)"); } } @@ -317,8 +313,7 @@ public void testCheckPositionIndexes_reversed() { Preconditions.checkPositionIndexes(1, 0, 1); fail(); } catch (IndexOutOfBoundsException expected) { - assertEquals("end index (0) must not be less than start index (1)", - expected.getMessage()); + assertThat(expected).hasMessage("end index (0) must not be less than start index (1)"); } } @@ -364,10 +359,10 @@ private static class Message { private static final String FORMAT = "I ate %s pies."; private static void verifySimpleMessage(Exception e) { - assertEquals("A message", e.getMessage()); + assertThat(e).hasMessage("A message"); } private static void verifyComplexMessage(Exception e) { - assertEquals("I ate 5 pies.", e.getMessage()); + assertThat(e).hasMessage("I ate 5 pies."); } } diff --git a/guava-tests/test/com/google/common/base/ThrowablesTest.java b/guava-tests/test/com/google/common/base/ThrowablesTest.java index 3e2f2cd84e09..0af930275b32 100644 --- a/guava-tests/test/com/google/common/base/ThrowablesTest.java +++ b/guava-tests/test/com/google/common/base/ThrowablesTest.java @@ -341,7 +341,7 @@ public void testPropagate_NoneDeclared_CheckedThrown() { sample.noneDeclared(); fail(); } catch (RuntimeException expected) { - assertTrue(expected.getCause() instanceof SomeCheckedException); + assertThat(expected.getCause()).isInstanceOf(SomeCheckedException.class); } } @@ -421,7 +421,7 @@ public void testPropagateIfInstanceOf_UndeclaredThrown() sample.oneDeclared(); fail(); } catch (RuntimeException expected) { - assertTrue(expected.getCause() instanceof SomeOtherCheckedException); + assertThat(expected.getCause()).isInstanceOf(SomeOtherCheckedException.class); } } @@ -495,7 +495,7 @@ class StackTraceException extends Exception { String secondLine = "\\s*at " + ThrowablesTest.class.getName() + "\\..*"; String moreLines = "(?:.*\n?)*"; String expected = firstLine + "\n" + secondLine + "\n" + moreLines; - assertTrue(getStackTraceAsString(e).matches(expected)); + assertThat(getStackTraceAsString(e)).matches(expected); } public void testGetCausalChain() { diff --git a/guava-tests/test/com/google/common/base/Utf8Test.java b/guava-tests/test/com/google/common/base/Utf8Test.java index 22442f74a588..88741e72c934 100644 --- a/guava-tests/test/com/google/common/base/Utf8Test.java +++ b/guava-tests/test/com/google/common/base/Utf8Test.java @@ -16,6 +16,7 @@ package com.google.common.base; +import static com.google.common.truth.Truth.assertThat; import static java.lang.Character.MAX_CODE_POINT; import static java.lang.Character.MAX_HIGH_SURROGATE; import static java.lang.Character.MAX_LOW_SURROGATE; @@ -123,8 +124,7 @@ private static void testEncodedLengthFails(String invalidString, Utf8.encodedLength(invalidString); fail(); } catch (IllegalArgumentException expected) { - assertEquals("Unpaired surrogate at index " + invalidCodePointIndex, - expected.getMessage()); + assertThat(expected).hasMessage("Unpaired surrogate at index " + invalidCodePointIndex); } } diff --git a/guava-tests/test/com/google/common/base/VerifyTest.java b/guava-tests/test/com/google/common/base/VerifyTest.java index bb089807f6b7..fb40263d71c5 100644 --- a/guava-tests/test/com/google/common/base/VerifyTest.java +++ b/guava-tests/test/com/google/common/base/VerifyTest.java @@ -16,6 +16,7 @@ import static com.google.common.base.Verify.verify; import static com.google.common.base.Verify.verifyNotNull; +import static com.google.common.truth.Truth.assertThat; import com.google.common.annotations.GwtCompatible; @@ -48,7 +49,7 @@ public void testVerify_simpleMessage_failure() { verify(false, "message"); fail(); } catch (VerifyException expected) { - assertEquals("message", expected.getMessage()); + assertThat(expected).hasMessage("message"); } } @@ -103,6 +104,6 @@ public void testVerifyNotNull_simpleMessage_failure() { private static final String FORMAT = "I ate %s pies."; private static void checkMessage(Exception e) { - assertEquals("I ate 5 pies.", e.getMessage()); + assertThat(e).hasMessage("I ate 5 pies."); } } diff --git a/guava-tests/test/com/google/common/cache/CacheBuilderTest.java b/guava-tests/test/com/google/common/cache/CacheBuilderTest.java index dd11a86bdbaa..3795db841121 100644 --- a/guava-tests/test/com/google/common/cache/CacheBuilderTest.java +++ b/guava-tests/test/com/google/common/cache/CacheBuilderTest.java @@ -88,7 +88,7 @@ public void testInitialCapacity_small() { .build(identityLoader()); LocalCache map = CacheTesting.toLocalCache(cache); - assertEquals(4, map.segments.length); + assertThat(map.segments).hasLength(4); assertEquals(2, map.segments[0].table.length()); assertEquals(2, map.segments[1].table.length()); assertEquals(2, map.segments[2].table.length()); @@ -102,7 +102,7 @@ public void testInitialCapacity_smallest() { .build(identityLoader()); LocalCache map = CacheTesting.toLocalCache(cache); - assertEquals(4, map.segments.length); + assertThat(map.segments).hasLength(4); // 1 is as low as it goes, not 0. it feels dirty to know this/test this. assertEquals(1, map.segments[0].table.length()); assertEquals(1, map.segments[1].table.length()); @@ -139,7 +139,7 @@ public void testConcurrencyLevel_small() { .concurrencyLevel(1) .build(identityLoader()); LocalCache map = CacheTesting.toLocalCache(cache); - assertEquals(1, map.segments.length); + assertThat(map.segments).hasLength(1); } public void testConcurrencyLevel_large() { @@ -219,15 +219,11 @@ public void testWeigher_withoutMaximumWeight() { @GwtIncompatible("weigher") public void testWeigher_withMaximumSize() { try { - CacheBuilder builder = new CacheBuilder() - .weigher(constantWeigher(42)) - .maximumSize(1); + new CacheBuilder().weigher(constantWeigher(42)).maximumSize(1); fail(); } catch (IllegalStateException expected) {} try { - CacheBuilder builder = new CacheBuilder() - .maximumSize(1) - .weigher(constantWeigher(42)); + new CacheBuilder().maximumSize(1).weigher(constantWeigher(42)); fail(); } catch (IllegalStateException expected) {} } @@ -612,7 +608,7 @@ public void testNullParameters() throws Exception { public void testSizingDefaults() { LoadingCache cache = CacheBuilder.newBuilder().build(identityLoader()); LocalCache map = CacheTesting.toLocalCache(cache); - assertEquals(4, map.segments.length); // concurrency level + assertThat(map.segments).hasLength(4); // concurrency level assertEquals(4, map.segments[0].table.length()); // capacity / conc level } diff --git a/guava-tests/test/com/google/common/cache/CacheLoadingTest.java b/guava-tests/test/com/google/common/cache/CacheLoadingTest.java index 632355a77a76..3cf35b171338 100644 --- a/guava-tests/test/com/google/common/cache/CacheLoadingTest.java +++ b/guava-tests/test/com/google/common/cache/CacheLoadingTest.java @@ -96,7 +96,7 @@ private void checkLoggedCause(Throwable t) { } private void checkLoggedInvalidLoad() { - assertTrue(popLoggedThrowable() instanceof InvalidCacheLoadException); + assertThat(popLoggedThrowable()).isInstanceOf(InvalidCacheLoadException.class); } public void testLoad() throws ExecutionException { @@ -1983,7 +1983,7 @@ private static void testConcurrentLoadingNull(CacheBuilder build assertEquals(1, callCount.get()); for (int i = 0; i < count; i++) { - assertTrue(result.get(i) instanceof InvalidCacheLoadException); + assertThat(result.get(i)).isInstanceOf(InvalidCacheLoadException.class); } // subsequent calls should call the loader again, not get the old exception @@ -2023,7 +2023,7 @@ private static void testConcurrentLoadingUncheckedException( for (int i = 0; i < count; i++) { // doConcurrentGet alternates between calling getUnchecked and calling get, but an unchecked // exception thrown by the loader is always wrapped as an UncheckedExecutionException. - assertTrue(result.get(i) instanceof UncheckedExecutionException); + assertThat(result.get(i)).isInstanceOf(UncheckedExecutionException.class); assertSame(e, ((UncheckedExecutionException) result.get(i)).getCause()); } @@ -2067,10 +2067,10 @@ private static void testConcurrentLoadingCheckedException( // UncheckedExecutionException. int mod = i % 3; if (mod == 0 || mod == 2) { - assertTrue(result.get(i) instanceof ExecutionException); + assertThat(result.get(i)).isInstanceOf(ExecutionException.class); assertSame(e, ((ExecutionException) result.get(i)).getCause()); } else { - assertTrue(result.get(i) instanceof UncheckedExecutionException); + assertThat(result.get(i)).isInstanceOf(UncheckedExecutionException.class); assertSame(e, ((UncheckedExecutionException) result.get(i)).getCause()); } } diff --git a/guava-tests/test/com/google/common/cache/CacheTesting.java b/guava-tests/test/com/google/common/cache/CacheTesting.java index 660fecdb5154..83614da56273 100644 --- a/guava-tests/test/com/google/common/cache/CacheTesting.java +++ b/guava-tests/test/com/google/common/cache/CacheTesting.java @@ -15,6 +15,7 @@ package com.google.common.cache; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.truth.Truth.assertThat; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertNotNull; @@ -199,7 +200,7 @@ static void checkValidState(LocalCache cchm) { // cleanup and then check count after we have a strong reference to all entries segment.cleanUp(); // under high memory pressure keys/values may be nulled out but not yet enqueued - assertTrue(table.size() <= segment.count); + assertThat(table.size()).isAtMost(segment.count); for (Entry entry : table.entrySet()) { assertNotNull(entry.getKey()); assertNotNull(entry.getValue()); @@ -232,7 +233,7 @@ static void checkExpiration(LocalCache cchm) { if (prev != null) { assertSame(prev, current.getPreviousInWriteQueue()); assertSame(prev.getNextInWriteQueue(), current); - assertTrue(prev.getWriteTime() <= current.getWriteTime()); + assertThat(prev.getWriteTime()).isAtMost(current.getWriteTime()); } Object key = current.getKey(); if (key != null) { @@ -480,8 +481,8 @@ static void checkEmpty(Collection collection) { assertTrue(collection.isEmpty()); assertEquals(0, collection.size()); assertFalse(collection.iterator().hasNext()); - assertEquals(0, collection.toArray().length); - assertEquals(0, collection.toArray(new Object[0]).length); + assertThat(collection.toArray()).isEmpty(); + assertThat(collection.toArray(new Object[0])).isEmpty(); if (collection instanceof Set) { new EqualsTester() .addEqualityGroup(ImmutableSet.of(), collection) diff --git a/guava-tests/test/com/google/common/cache/LocalCacheTest.java b/guava-tests/test/com/google/common/cache/LocalCacheTest.java index b2c9dd5b18de..c959d54073ec 100644 --- a/guava-tests/test/com/google/common/cache/LocalCacheTest.java +++ b/guava-tests/test/com/google/common/cache/LocalCacheTest.java @@ -27,6 +27,7 @@ import static com.google.common.cache.TestingWeighers.constantWeigher; import static com.google.common.collect.Lists.newArrayList; import static com.google.common.collect.Maps.immutableEntry; +import static com.google.common.truth.Truth.assertThat; import static java.util.concurrent.TimeUnit.MINUTES; import static java.util.concurrent.TimeUnit.NANOSECONDS; import static java.util.concurrent.TimeUnit.SECONDS; @@ -249,7 +250,7 @@ public void testDefaults() { assertEquals(4, map.concurrencyLevel); // concurrency level - assertEquals(4, map.segments.length); + assertThat(map.segments).hasLength(4); // initial capacity / concurrency level assertEquals(16 / map.segments.length, map.segments[0].table.length()); @@ -314,7 +315,7 @@ public void testSetConcurrencyLevel() { private static void checkConcurrencyLevel(int concurrencyLevel, int segmentCount) { LocalCache map = makeLocalCache(createCacheBuilder().concurrencyLevel(concurrencyLevel)); - assertEquals(segmentCount, map.segments.length); + assertThat(map.segments).hasLength(segmentCount); } public void testSetInitialCapacity() { @@ -661,7 +662,7 @@ public void testValues() { map.put("foo", "bar"); map.put("baz", "bar"); map.put("quux", "quux"); - assertFalse(map.values() instanceof Set); + assertThat(map.values()).isNotInstanceOf(Set.class); assertTrue(map.values().removeAll(ImmutableSet.of("bar"))); assertEquals(1, map.size()); } diff --git a/guava-tests/test/com/google/common/collect/ArrayTableTest.java b/guava-tests/test/com/google/common/collect/ArrayTableTest.java index 32635a3f5b6b..bf68e09560ff 100644 --- a/guava-tests/test/com/google/common/collect/ArrayTableTest.java +++ b/guava-tests/test/com/google/common/collect/ArrayTableTest.java @@ -369,13 +369,13 @@ public void testPutIllegal() { table.put("dog", 1, 'd'); fail(); } catch (IllegalArgumentException expected) { - assertEquals("Row dog not in [foo, bar, cat]", expected.getMessage()); + assertThat(expected).hasMessage("Row dog not in [foo, bar, cat]"); } try { table.put("foo", 4, 'd'); fail(); } catch (IllegalArgumentException expected) { - assertEquals("Column 4 not in [1, 2, 3]", expected.getMessage()); + assertThat(expected).hasMessage("Column 4 not in [1, 2, 3]"); } assertFalse(table.containsValue('d')); } @@ -399,7 +399,7 @@ public void testToArray() { ArrayTable table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c'); Character[][] array = table.toArray(Character.class); - assertEquals(3, array.length); + assertThat(array).hasLength(3); assertThat(array[0]).asList().containsExactly('a', null, 'c').inOrder(); assertThat(array[1]).asList().containsExactly('b', null, null).inOrder(); assertThat(array[2]).asList().containsExactly(null, null, null).inOrder(); @@ -444,7 +444,7 @@ public void testRowPutIllegal() { map.put(4, 'd'); fail(); } catch (IllegalArgumentException expected) { - assertEquals("Column 4 not in [1, 2, 3]", expected.getMessage()); + assertThat(expected).hasMessage("Column 4 not in [1, 2, 3]"); } } @@ -455,7 +455,7 @@ public void testColumnPutIllegal() { map.put("dog", 'd'); fail(); } catch (IllegalArgumentException expected) { - assertEquals("Row dog not in [foo, bar, cat]", expected.getMessage()); + assertThat(expected).hasMessage("Row dog not in [foo, bar, cat]"); } } diff --git a/guava-tests/test/com/google/common/collect/ConstraintsTest.java b/guava-tests/test/com/google/common/collect/ConstraintsTest.java index 0228a30082a2..f6c112a7c0b0 100644 --- a/guava-tests/test/com/google/common/collect/ConstraintsTest.java +++ b/guava-tests/test/com/google/common/collect/ConstraintsTest.java @@ -203,7 +203,7 @@ public void testConstrainedListRandomAccessFalse() { list, TEST_CONSTRAINT); list.add(TEST_ELEMENT); constrained.add("qux"); - assertFalse(constrained instanceof RandomAccess); + assertThat(constrained).isNotInstanceOf(RandomAccess.class); } public void testConstrainedListIllegal() { diff --git a/guava-tests/test/com/google/common/collect/FluentIterableTest.java b/guava-tests/test/com/google/common/collect/FluentIterableTest.java index 03e1e1af3933..af70b4c7d8f8 100644 --- a/guava-tests/test/com/google/common/collect/FluentIterableTest.java +++ b/guava-tests/test/com/google/common/collect/FluentIterableTest.java @@ -24,7 +24,6 @@ import com.google.common.base.Function; import com.google.common.base.Functions; import com.google.common.base.Joiner; -import com.google.common.base.Optional; import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.collect.testing.IteratorFeature; @@ -251,10 +250,10 @@ public void testAllMatch() { public void testFirstMatch() { FluentIterable iterable = FluentIterable.from(Lists.newArrayList("cool", "pants")); - assertEquals(Optional.of("cool"), iterable.firstMatch(Predicates.equalTo("cool"))); - assertEquals(Optional.of("pants"), iterable.firstMatch(Predicates.equalTo("pants"))); - assertEquals(Optional.absent(), iterable.firstMatch(Predicates.alwaysFalse())); - assertEquals(Optional.of("cool"), iterable.firstMatch(Predicates.alwaysTrue())); + assertThat(iterable.firstMatch(Predicates.equalTo("cool"))).hasValue("cool"); + assertThat(iterable.firstMatch(Predicates.equalTo("pants"))).hasValue("pants"); + assertThat(iterable.firstMatch(Predicates.alwaysFalse())).isAbsent(); + assertThat(iterable.firstMatch(Predicates.alwaysTrue())).hasValue("cool"); } private static final class IntegerValueOfFunction implements Function { @@ -335,7 +334,7 @@ public void testTransformAndConcat_wildcardFunctionGenerics() { public void testFirst_list() { List list = Lists.newArrayList("a", "b", "c"); - assertEquals("a", FluentIterable.from(list).first().get()); + assertThat(FluentIterable.from(list).first()).hasValue("a"); } public void testFirst_null() { @@ -349,32 +348,32 @@ public void testFirst_null() { public void testFirst_emptyList() { List list = Collections.emptyList(); - assertEquals(Optional.absent(), FluentIterable.from(list).first()); + assertThat(FluentIterable.from(list).first()).isAbsent(); } public void testFirst_sortedSet() { SortedSet sortedSet = ImmutableSortedSet.of("b", "c", "a"); - assertEquals("a", FluentIterable.from(sortedSet).first().get()); + assertThat(FluentIterable.from(sortedSet).first()).hasValue("a"); } public void testFirst_emptySortedSet() { SortedSet sortedSet = ImmutableSortedSet.of(); - assertEquals(Optional.absent(), FluentIterable.from(sortedSet).first()); + assertThat(FluentIterable.from(sortedSet).first()).isAbsent(); } public void testFirst_iterable() { Set set = ImmutableSet.of("a", "b", "c"); - assertEquals("a", FluentIterable.from(set).first().get()); + assertThat(FluentIterable.from(set).first()).hasValue("a"); } public void testFirst_emptyIterable() { Set set = Sets.newHashSet(); - assertEquals(Optional.absent(), FluentIterable.from(set).first()); + assertThat(FluentIterable.from(set).first()).isAbsent(); } public void testLast_list() { List list = Lists.newArrayList("a", "b", "c"); - assertEquals("c", FluentIterable.from(list).last().get()); + assertThat(FluentIterable.from(list).last()).hasValue("c"); } public void testLast_null() { @@ -388,27 +387,27 @@ public void testLast_null() { public void testLast_emptyList() { List list = Collections.emptyList(); - assertEquals(Optional.absent(), FluentIterable.from(list).last()); + assertThat(FluentIterable.from(list).last()).isAbsent(); } public void testLast_sortedSet() { SortedSet sortedSet = ImmutableSortedSet.of("b", "c", "a"); - assertEquals("c", FluentIterable.from(sortedSet).last().get()); + assertThat(FluentIterable.from(sortedSet).last()).hasValue("c"); } public void testLast_emptySortedSet() { SortedSet sortedSet = ImmutableSortedSet.of(); - assertEquals(Optional.absent(), FluentIterable.from(sortedSet).last()); + assertThat(FluentIterable.from(sortedSet).last()).isAbsent(); } public void testLast_iterable() { Set set = ImmutableSet.of("a", "b", "c"); - assertEquals("c", FluentIterable.from(set).last().get()); + assertThat(FluentIterable.from(set).last()).hasValue("c"); } public void testLast_emptyIterable() { Set set = Sets.newHashSet(); - assertEquals(Optional.absent(), FluentIterable.from(set).last()); + assertThat(FluentIterable.from(set).last()).isAbsent(); } public void testSkip_simple() { diff --git a/guava-tests/test/com/google/common/collect/ForwardingListTest.java b/guava-tests/test/com/google/common/collect/ForwardingListTest.java index 159c3931d524..c829a9a43f10 100644 --- a/guava-tests/test/com/google/common/collect/ForwardingListTest.java +++ b/guava-tests/test/com/google/common/collect/ForwardingListTest.java @@ -16,6 +16,8 @@ package com.google.common.collect; +import static com.google.common.truth.Truth.assertThat; + import com.google.common.collect.testing.ListTestSuiteBuilder; import com.google.common.collect.testing.TestStringListGenerator; import com.google.common.collect.testing.features.CollectionFeature; @@ -306,7 +308,7 @@ public void testHashCode() { } public void testRandomAccess() { - assertFalse(forward instanceof RandomAccess); + assertThat(forward).isNotInstanceOf(RandomAccess.class); } public void testToString() { diff --git a/guava-tests/test/com/google/common/collect/ImmutableBiMapTest.java b/guava-tests/test/com/google/common/collect/ImmutableBiMapTest.java index 4e98207e56de..4ef71a194ca2 100644 --- a/guava-tests/test/com/google/common/collect/ImmutableBiMapTest.java +++ b/guava-tests/test/com/google/common/collect/ImmutableBiMapTest.java @@ -329,7 +329,7 @@ public void testPuttingTheSameKeyTwiceThrowsOnBuild() { builder.build(); fail(); } catch (IllegalArgumentException expected) { - assertTrue(expected.getMessage().contains("one")); + assertThat(expected.getMessage()).contains("one"); } } @@ -402,7 +402,7 @@ public void testOfWithDuplicateKey() { ImmutableBiMap.of("one", 1, "one", 1); fail(); } catch (IllegalArgumentException expected) { - assertTrue(expected.getMessage().contains("one")); + assertThat(expected.getMessage()).contains("one"); } } @@ -476,7 +476,7 @@ public void testDuplicateValues() { ImmutableBiMap.copyOf(map); fail(); } catch (IllegalArgumentException expected) { - assertTrue(expected.getMessage().contains("1")); + assertThat(expected.getMessage()).contains("1"); } } } diff --git a/guava-tests/test/com/google/common/collect/ImmutableSetMultimapTest.java b/guava-tests/test/com/google/common/collect/ImmutableSetMultimapTest.java index 1eb63e45957e..220638d02c47 100644 --- a/guava-tests/test/com/google/common/collect/ImmutableSetMultimapTest.java +++ b/guava-tests/test/com/google/common/collect/ImmutableSetMultimapTest.java @@ -275,9 +275,9 @@ public void testBuilderOrderKeysBy() { assertThat(multimap.values()).containsExactly(2, 4, 3, 6, 5, 2).inOrder(); assertThat(multimap.get("a")).containsExactly(5, 2).inOrder(); assertThat(multimap.get("b")).containsExactly(3, 6).inOrder(); - assertFalse(multimap.get("a") instanceof ImmutableSortedSet); - assertFalse(multimap.get("x") instanceof ImmutableSortedSet); - assertFalse(multimap.asMap().get("a") instanceof ImmutableSortedSet); + assertThat(multimap.get("a")).isNotInstanceOf(ImmutableSortedSet.class); + assertThat(multimap.get("x")).isNotInstanceOf(ImmutableSortedSet.class); + assertThat(multimap.asMap().get("a")).isNotInstanceOf(ImmutableSortedSet.class); } public void testBuilderOrderKeysByDuplicates() { @@ -300,9 +300,9 @@ public int compare(String left, String right) { assertThat(multimap.values()).containsExactly(2, 5, 2, 3, 6, 4).inOrder(); assertThat(multimap.get("a")).containsExactly(5, 2).inOrder(); assertThat(multimap.get("bb")).containsExactly(3, 6).inOrder(); - assertFalse(multimap.get("a") instanceof ImmutableSortedSet); - assertFalse(multimap.get("x") instanceof ImmutableSortedSet); - assertFalse(multimap.asMap().get("a") instanceof ImmutableSortedSet); + assertThat(multimap.get("a")).isNotInstanceOf(ImmutableSortedSet.class); + assertThat(multimap.get("x")).isNotInstanceOf(ImmutableSortedSet.class); + assertThat(multimap.asMap().get("a")).isNotInstanceOf(ImmutableSortedSet.class); } public void testBuilderOrderValuesBy() { diff --git a/guava-tests/test/com/google/common/collect/IterablesTest.java b/guava-tests/test/com/google/common/collect/IterablesTest.java index 8d36825214bf..9a853cc4d116 100644 --- a/guava-tests/test/com/google/common/collect/IterablesTest.java +++ b/guava-tests/test/com/google/common/collect/IterablesTest.java @@ -28,7 +28,6 @@ import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import com.google.common.base.Function; -import com.google.common.base.Optional; import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.collect.testing.IteratorTester; @@ -262,14 +261,10 @@ public void testFind_withDefault() { public void testTryFind() { Iterable list = newArrayList("cool", "pants"); - assertEquals(Optional.of("cool"), - Iterables.tryFind(list, Predicates.equalTo("cool"))); - assertEquals(Optional.of("pants"), - Iterables.tryFind(list, Predicates.equalTo("pants"))); - assertEquals(Optional.of("cool"), - Iterables.tryFind(list, Predicates.alwaysTrue())); - assertEquals(Optional.absent(), - Iterables.tryFind(list, Predicates.alwaysFalse())); + assertThat(Iterables.tryFind(list, Predicates.equalTo("cool"))).hasValue("cool"); + assertThat(Iterables.tryFind(list, Predicates.equalTo("pants"))).hasValue("pants"); + assertThat(Iterables.tryFind(list, Predicates.alwaysTrue())).hasValue("cool"); + assertThat(Iterables.tryFind(list, Predicates.alwaysFalse())).isAbsent(); assertCanIterateAgain(list); } diff --git a/guava-tests/test/com/google/common/collect/IteratorsTest.java b/guava-tests/test/com/google/common/collect/IteratorsTest.java index 2c5d0e7dab7f..eb9886861fea 100644 --- a/guava-tests/test/com/google/common/collect/IteratorsTest.java +++ b/guava-tests/test/com/google/common/collect/IteratorsTest.java @@ -197,8 +197,7 @@ public void testGetOnlyElement_noDefault_moreThanOneLessThanFiveElements() { Iterators.getOnlyElement(iterator); fail(); } catch (IllegalArgumentException expected) { - assertEquals("expected one element but was: ", - expected.getMessage()); + assertThat(expected).hasMessage("expected one element but was: "); } } @@ -209,9 +208,8 @@ public void testGetOnlyElement_noDefault_fiveElements() { Iterators.getOnlyElement(iterator); fail(); } catch (IllegalArgumentException expected) { - assertEquals("expected one element but was: " - + "", - expected.getMessage()); + assertThat(expected) + .hasMessage("expected one element but was: " + ""); } } @@ -222,9 +220,8 @@ public void testGetOnlyElement_noDefault_moreThanFiveElements() { Iterators.getOnlyElement(iterator); fail(); } catch (IllegalArgumentException expected) { - assertEquals("expected one element but was: " - + "", - expected.getMessage()); + assertThat(expected) + .hasMessage("expected one element but was: " + ""); } } @@ -249,8 +246,7 @@ public void testGetOnlyElement_withDefault_two() { Iterators.getOnlyElement(iterator, "x"); fail(); } catch (IllegalArgumentException expected) { - assertEquals("expected one element but was: ", - expected.getMessage()); + assertThat(expected).hasMessage("expected one element but was: "); } } @@ -432,22 +428,19 @@ public void testFind_withDefault_matchAlways() { public void testTryFind_firstElement() { Iterable list = Lists.newArrayList("cool", "pants"); Iterator iterator = list.iterator(); - assertEquals("cool", - Iterators.tryFind(iterator, Predicates.equalTo("cool")).get()); + assertThat(Iterators.tryFind(iterator, Predicates.equalTo("cool"))).hasValue("cool"); } public void testTryFind_lastElement() { Iterable list = Lists.newArrayList("cool", "pants"); Iterator iterator = list.iterator(); - assertEquals("pants", - Iterators.tryFind(iterator, Predicates.equalTo("pants")).get()); + assertThat(Iterators.tryFind(iterator, Predicates.equalTo("pants"))).hasValue("pants"); } public void testTryFind_alwaysTrue() { Iterable list = Lists.newArrayList("cool", "pants"); Iterator iterator = list.iterator(); - assertEquals("cool", - Iterators.tryFind(iterator, Predicates.alwaysTrue()).get()); + assertThat(Iterators.tryFind(iterator, Predicates.alwaysTrue())).hasValue("cool"); } public void testTryFind_alwaysFalse_orDefault() { @@ -461,8 +454,7 @@ public void testTryFind_alwaysFalse_orDefault() { public void testTryFind_alwaysFalse_isPresent() { Iterable list = Lists.newArrayList("cool", "pants"); Iterator iterator = list.iterator(); - assertFalse( - Iterators.tryFind(iterator, Predicates.alwaysFalse()).isPresent()); + assertThat(Iterators.tryFind(iterator, Predicates.alwaysFalse())).isAbsent(); assertFalse(iterator.hasNext()); } diff --git a/guava-tests/test/com/google/common/collect/LinkedListMultimapTest.java b/guava-tests/test/com/google/common/collect/LinkedListMultimapTest.java index f8e648d706b9..fa090890e02e 100644 --- a/guava-tests/test/com/google/common/collect/LinkedListMultimapTest.java +++ b/guava-tests/test/com/google/common/collect/LinkedListMultimapTest.java @@ -99,8 +99,8 @@ public void testGetRandomAccess() { Multimap multimap = create(); multimap.put("foo", 1); multimap.put("foo", 3); - assertFalse(multimap.get("foo") instanceof RandomAccess); - assertFalse(multimap.get("bar") instanceof RandomAccess); + assertThat(multimap.get("foo")).isNotInstanceOf(RandomAccess.class); + assertThat(multimap.get("bar")).isNotInstanceOf(RandomAccess.class); } /** diff --git a/guava-tests/test/com/google/common/collect/ListsTest.java b/guava-tests/test/com/google/common/collect/ListsTest.java index 90b677f0ea2a..b1803e9404a6 100644 --- a/guava-tests/test/com/google/common/collect/ListsTest.java +++ b/guava-tests/test/com/google/common/collect/ListsTest.java @@ -667,7 +667,7 @@ public void testTransformRandomAccess() { public void testTransformSequential() { List list = Lists.transform(SOME_SEQUENTIAL_LIST, SOME_FUNCTION); - assertFalse(list instanceof RandomAccess); + assertThat(list).isNotInstanceOf(RandomAccess.class); } public void testTransformListIteratorRandomAccess() { @@ -862,9 +862,9 @@ public void testPartitionRandomAccessTrue() { public void testPartitionRandomAccessFalse() { List source = Lists.newLinkedList(asList(1, 2, 3)); List> partitions = Lists.partition(source, 2); - assertFalse(partitions instanceof RandomAccess); - assertFalse(partitions.get(0) instanceof RandomAccess); - assertFalse(partitions.get(1) instanceof RandomAccess); + assertThat(partitions).isNotInstanceOf(RandomAccess.class); + assertThat(partitions.get(0)).isNotInstanceOf(RandomAccess.class); + assertThat(partitions.get(1)).isNotInstanceOf(RandomAccess.class); } // TODO: use the suite builders diff --git a/guava-tests/test/com/google/common/collect/MapConstraintsTest.java b/guava-tests/test/com/google/common/collect/MapConstraintsTest.java index 5fec453de64f..006b1a81af48 100644 --- a/guava-tests/test/com/google/common/collect/MapConstraintsTest.java +++ b/guava-tests/test/com/google/common/collect/MapConstraintsTest.java @@ -112,7 +112,7 @@ public void testConstrainedMapLegal() { assertEquals(map.keySet(), constrained.keySet()); assertEquals(HashMultiset.create(map.values()), HashMultiset.create(constrained.values())); - assertFalse(map.values() instanceof Serializable); + assertThat(map.values()).isNotInstanceOf(Serializable.class); assertEquals(map.toString(), constrained.toString()); assertEquals(map.hashCode(), constrained.hashCode()); assertThat(map.entrySet()).containsExactly( @@ -253,9 +253,8 @@ public void testConstrainedMultimapLegal() { Maps.immutableEntry("bop", 9), Maps.immutableEntry("dig", 10), Maps.immutableEntry("dag", 11)).inOrder(); - assertFalse(constrained.asMap().values() instanceof Serializable); - Iterator> iterator = - constrained.asMap().values().iterator(); + assertThat(constrained.asMap().values()).isNotInstanceOf(Serializable.class); + Iterator> iterator = constrained.asMap().values().iterator(); iterator.next(); iterator.next().add(12); assertTrue(multimap.containsEntry("foo", 12)); diff --git a/guava-tests/test/com/google/common/collect/MapMakerInternalMapTest.java b/guava-tests/test/com/google/common/collect/MapMakerInternalMapTest.java index c8c4d4794e07..ce4d2d1cfe2f 100644 --- a/guava-tests/test/com/google/common/collect/MapMakerInternalMapTest.java +++ b/guava-tests/test/com/google/common/collect/MapMakerInternalMapTest.java @@ -21,6 +21,7 @@ import static com.google.common.collect.MapMakerInternalMap.DRAIN_THRESHOLD; import static com.google.common.collect.MapMakerInternalMap.nullEntry; import static com.google.common.collect.MapMakerInternalMap.unset; +import static com.google.common.truth.Truth.assertThat; import static java.util.concurrent.TimeUnit.SECONDS; import com.google.common.base.Equivalence; @@ -93,7 +94,7 @@ public void testDefaults() { assertEquals(4, map.concurrencyLevel); // concurrency level - assertEquals(4, map.segments.length); + assertThat(map.segments).hasLength(4); // initial capacity / concurrency level assertEquals(16 / map.segments.length, map.segments[0].table.length()); @@ -138,7 +139,7 @@ public void testSetConcurrencyLevel() { private static void checkConcurrencyLevel(int concurrencyLevel, int segmentCount) { MapMakerInternalMap map = makeMap(createMapMaker().concurrencyLevel(concurrencyLevel)); - assertEquals(segmentCount, map.segments.length); + assertThat(map.segments).hasLength(segmentCount); } public void testSetInitialCapacity() { diff --git a/guava-tests/test/com/google/common/collect/MultimapsTest.java b/guava-tests/test/com/google/common/collect/MultimapsTest.java index e826c08db46a..d4b5ec14a77d 100644 --- a/guava-tests/test/com/google/common/collect/MultimapsTest.java +++ b/guava-tests/test/com/google/common/collect/MultimapsTest.java @@ -70,14 +70,6 @@ public class MultimapsTest extends TestCase { private static final Comparator INT_COMPARATOR = Ordering.natural().reverse().nullsFirst(); - private static final EntryTransformer ALWAYS_NULL = - new EntryTransformer() { - @Override - public Object transformEntry(Object k, Object v1) { - return null; - } - }; - @SuppressWarnings("deprecation") public void testUnmodifiableListMultimapShortCircuit() { ListMultimap mod = ArrayListMultimap.create(); @@ -142,10 +134,9 @@ public void testUnmodifiableLinkedListMultimapRandomAccess() { ListMultimap delegate = LinkedListMultimap.create(); delegate.put("foo", 1); delegate.put("foo", 3); - ListMultimap multimap - = Multimaps.unmodifiableListMultimap(delegate); - assertFalse(multimap.get("foo") instanceof RandomAccess); - assertFalse(multimap.get("bar") instanceof RandomAccess); + ListMultimap multimap = Multimaps.unmodifiableListMultimap(delegate); + assertThat(multimap.get("foo")).isNotInstanceOf(RandomAccess.class); + assertThat(multimap.get("bar")).isNotInstanceOf(RandomAccess.class); } @GwtIncompatible("slow (~10s)") @@ -300,7 +291,7 @@ private static void checkUnmodifiableMultimap( assertThat(unmodifiable.asMap().get("bar")).containsExactly(5, -1); assertNull(unmodifiable.asMap().get("missing")); - assertFalse(unmodifiable.entries() instanceof Serializable); + assertThat(unmodifiable.entries()).isNotInstanceOf(Serializable.class); } /** @@ -638,8 +629,8 @@ public void testNewMultimap() { Collection collection = multimap.get(Color.BLUE); assertEquals(collection, collection); - assertFalse(multimap.keySet() instanceof SortedSet); - assertFalse(multimap.asMap() instanceof SortedMap); + assertThat(multimap.keySet()).isNotInstanceOf(SortedSet.class); + assertThat(multimap.asMap()).isNotInstanceOf(SortedMap.class); } @GwtIncompatible("SerializableTester") @@ -671,7 +662,7 @@ public void testNewListMultimap() { multimap.putAll(Color.RED, asList(2, 7, 1, 8)); assertEquals(2, factory.count); assertEquals("{BLUE=[3, 1, 4, 1], RED=[2, 7, 1, 8]}", multimap.toString()); - assertFalse(multimap.get(Color.BLUE) instanceof RandomAccess); + assertThat(multimap.get(Color.BLUE)).isNotInstanceOf(RandomAccess.class); assertTrue(multimap.keySet() instanceof SortedSet); assertTrue(multimap.asMap() instanceof SortedMap); diff --git a/guava-tests/test/com/google/common/collect/ObjectArraysTest.java b/guava-tests/test/com/google/common/collect/ObjectArraysTest.java index a95df86cc8b3..b8dba1a621af 100644 --- a/guava-tests/test/com/google/common/collect/ObjectArraysTest.java +++ b/guava-tests/test/com/google/common/collect/ObjectArraysTest.java @@ -46,14 +46,14 @@ public void testNullPointerExceptions() { public void testNewArray_fromClass_Empty() { String[] empty = ObjectArrays.newArray(String.class, 0); assertEquals(String[].class, empty.getClass()); - assertEquals(0, empty.length); + assertThat(empty).isEmpty(); } @GwtIncompatible("ObjectArrays.newArray(Class, int)") public void testNewArray_fromClass_Nonempty() { String[] array = ObjectArrays.newArray(String.class, 2); assertEquals(String[].class, array.getClass()); - assertEquals(2, array.length); + assertThat(array).hasLength(2); assertNull(array[0]); } @@ -61,27 +61,27 @@ public void testNewArray_fromClass_Nonempty() { public void testNewArray_fromClass_OfArray() { String[][] array = ObjectArrays.newArray(String[].class, 1); assertEquals(String[][].class, array.getClass()); - assertEquals(1, array.length); + assertThat(array).hasLength(1); assertNull(array[0]); } public void testNewArray_fromArray_Empty() { String[] in = new String[0]; String[] empty = ObjectArrays.newArray(in, 0); - assertEquals(0, empty.length); + assertThat(empty).isEmpty(); } public void testNewArray_fromArray_Nonempty() { String[] array = ObjectArrays.newArray(new String[0], 2); assertEquals(String[].class, array.getClass()); - assertEquals(2, array.length); + assertThat(array).hasLength(2); assertNull(array[0]); } public void testNewArray_fromArray_OfArray() { String[][] array = ObjectArrays.newArray(new String[0][0], 1); assertEquals(String[][].class, array.getClass()); - assertEquals(1, array.length); + assertThat(array).hasLength(1); assertNull(array[0]); } @@ -90,7 +90,7 @@ public void testConcatEmptyEmpty() { String[] result = ObjectArrays.concat(new String[0], new String[0], String.class); assertEquals(String[].class, result.getClass()); - assertEquals(0, result.length); + assertThat(result).isEmpty(); } @GwtIncompatible("ObjectArrays.concat(Object[], Object[], Class)") diff --git a/guava-tests/test/com/google/common/collect/SynchronizedMultimapTest.java b/guava-tests/test/com/google/common/collect/SynchronizedMultimapTest.java index 161c0d4ed30d..6f74329c08b8 100644 --- a/guava-tests/test/com/google/common/collect/SynchronizedMultimapTest.java +++ b/guava-tests/test/com/google/common/collect/SynchronizedMultimapTest.java @@ -239,9 +239,8 @@ public void testSynchronizedLinkedListMultimapRandomAccess() { ListMultimap delegate = LinkedListMultimap.create(); delegate.put("foo", 1); delegate.put("foo", 3); - ListMultimap multimap - = Multimaps.synchronizedListMultimap(delegate); - assertFalse(multimap.get("foo") instanceof RandomAccess); - assertFalse(multimap.get("bar") instanceof RandomAccess); + ListMultimap multimap = Multimaps.synchronizedListMultimap(delegate); + assertThat(multimap.get("foo")).isNotInstanceOf(RandomAccess.class); + assertThat(multimap.get("bar")).isNotInstanceOf(RandomAccess.class); } } diff --git a/guava-tests/test/com/google/common/eventbus/SubscriberTest.java b/guava-tests/test/com/google/common/eventbus/SubscriberTest.java index 58fe187731a3..3860d56045a5 100644 --- a/guava-tests/test/com/google/common/eventbus/SubscriberTest.java +++ b/guava-tests/test/com/google/common/eventbus/SubscriberTest.java @@ -16,6 +16,8 @@ package com.google.common.eventbus; +import static com.google.common.truth.Truth.assertThat; + import com.google.common.testing.EqualsTester; import junit.framework.TestCase; @@ -46,11 +48,11 @@ protected void setUp() throws Exception { public void testCreate() { Subscriber s1 = Subscriber.create(bus, this, getTestSubscriberMethod("recordingMethod")); - assertTrue(s1 instanceof Subscriber.SynchronizedSubscriber); + assertThat(s1).isInstanceOf(Subscriber.SynchronizedSubscriber.class); // a thread-safe method should not create a synchronized subscriber Subscriber s2 = Subscriber.create(bus, this, getTestSubscriberMethod("threadSafeMethod")); - assertFalse(s2 instanceof Subscriber.SynchronizedSubscriber); + assertThat(s2).isNotInstanceOf(Subscriber.SynchronizedSubscriber.class); } public void testInvokeSubscriberMethod_basicMethodCall() throws Throwable { @@ -72,7 +74,7 @@ public void testInvokeSubscriberMethod_exceptionWrapping() throws Throwable { subscriber.invokeSubscriberMethod(FIXTURE_ARGUMENT); fail("Subscribers whose methods throw must throw InvocationTargetException"); } catch (InvocationTargetException expected) { - assertTrue(expected.getCause() instanceof IntentionalException); + assertThat(expected.getCause()).isInstanceOf(IntentionalException.class); } } diff --git a/guava-tests/test/com/google/common/hash/BloomFilterTest.java b/guava-tests/test/com/google/common/hash/BloomFilterTest.java index 1fd6687cf5ea..594bcf8c8484 100644 --- a/guava-tests/test/com/google/common/hash/BloomFilterTest.java +++ b/guava-tests/test/com/google/common/hash/BloomFilterTest.java @@ -18,6 +18,7 @@ import static com.google.common.base.Charsets.UTF_8; import static com.google.common.hash.BloomFilterStrategies.BitArray; +import static com.google.common.truth.Truth.assertThat; import com.google.common.collect.ImmutableSet; import com.google.common.math.LongMath; @@ -265,7 +266,7 @@ public void testOptimalSize() { BloomFilter.create(HashTestUtils.BAD_FUNNEL, Integer.MAX_VALUE, Double.MIN_VALUE); fail("we can't represent such a large BF!"); } catch (IllegalArgumentException expected) { - assertEquals("Could not create BloomFilter of 3327428144502 bits", expected.getMessage()); + assertThat(expected).hasMessage("Could not create BloomFilter of 3327428144502 bits"); } } @@ -475,7 +476,7 @@ public void testCustomSerialization() throws Exception { * Only appending a new constant is allowed. */ public void testBloomFilterStrategies() { - assertEquals(2, BloomFilterStrategies.values().length); + assertThat(BloomFilterStrategies.values()).hasLength(2); assertEquals(BloomFilterStrategies.MURMUR128_MITZ_32, BloomFilterStrategies.values()[0]); assertEquals(BloomFilterStrategies.MURMUR128_MITZ_64, BloomFilterStrategies.values()[1]); } diff --git a/guava-tests/test/com/google/common/io/ByteStreamsTest.java b/guava-tests/test/com/google/common/io/ByteStreamsTest.java index 123de56f88e7..40df0ea4b8cd 100644 --- a/guava-tests/test/com/google/common/io/ByteStreamsTest.java +++ b/guava-tests/test/com/google/common/io/ByteStreamsTest.java @@ -197,7 +197,7 @@ public void testNewDataInput_readFullyAndThenSome() { in.readFully(actual); fail("expected exception"); } catch (IllegalStateException ex) { - assertTrue(ex.getCause() instanceof EOFException); + assertThat(ex.getCause()).isInstanceOf(EOFException.class); } } @@ -278,7 +278,7 @@ public void testNewDataInput_readByte() { in.readByte(); fail("expected exception"); } catch (IllegalStateException ex) { - assertTrue(ex.getCause() instanceof EOFException); + assertThat(ex.getCause()).isInstanceOf(EOFException.class); } } @@ -291,7 +291,7 @@ public void testNewDataInput_readUnsignedByte() { in.readUnsignedByte(); fail("expected exception"); } catch (IllegalStateException ex) { - assertTrue(ex.getCause() instanceof EOFException); + assertThat(ex.getCause()).isInstanceOf(EOFException.class); } } @@ -597,7 +597,7 @@ public void testLimit_markNotSet() { lin.reset(); fail(); } catch (IOException expected) { - assertEquals("Mark not set", expected.getMessage()); + assertThat(expected).hasMessage("Mark not set"); } } @@ -608,7 +608,7 @@ public void testLimit_markNotSupported() { lin.reset(); fail(); } catch (IOException expected) { - assertEquals("Mark not supported", expected.getMessage()); + assertThat(expected).hasMessage("Mark not supported"); } } diff --git a/guava-tests/test/com/google/common/io/CloserTest.java b/guava-tests/test/com/google/common/io/CloserTest.java index 07c0c4a7b3da..ee5ef7675f26 100644 --- a/guava-tests/test/com/google/common/io/CloserTest.java +++ b/guava-tests/test/com/google/common/io/CloserTest.java @@ -16,6 +16,8 @@ package com.google.common.io; +import static com.google.common.truth.Truth.assertThat; + import com.google.common.base.MoreObjects; import com.google.common.base.Objects; import com.google.common.base.Splitter; @@ -57,9 +59,9 @@ public void testCreate() { String secondPart = Iterables.get(Splitter.on('.').split(javaVersion), 1); int versionNumber = Integer.parseInt(secondPart); if (versionNumber < 7) { - assertTrue(closer.suppressor instanceof Closer.LoggingSuppressor); + assertThat(closer.suppressor).isInstanceOf(Closer.LoggingSuppressor.class); } else { - assertTrue(closer.suppressor instanceof Closer.SuppressingSuppressor); + assertThat(closer.suppressor).isInstanceOf(Closer.SuppressingSuppressor.class); } } @@ -126,7 +128,7 @@ public void testExceptionThrown_whenCreatingCloseables() throws IOException { closer.close(); } } catch (Throwable expected) { - assertTrue(expected instanceof IOException); + assertThat(expected).isInstanceOf(IOException.class); } assertTrue(c1.isClosed()); @@ -340,7 +342,7 @@ public static void testSuppressingSuppressorIfPossible() throws IOException { } catch (Throwable e) { throw closer.rethrow(thrownException, IOException.class); } finally { - assertEquals(0, getSuppressed(thrownException).length); + assertThat(getSuppressed(thrownException)).isEmpty(); closer.close(); } } catch (IOException expected) { diff --git a/guava-tests/test/com/google/common/io/CountingInputStreamTest.java b/guava-tests/test/com/google/common/io/CountingInputStreamTest.java index 9e06fef5b40e..e6341a6b194f 100644 --- a/guava-tests/test/com/google/common/io/CountingInputStreamTest.java +++ b/guava-tests/test/com/google/common/io/CountingInputStreamTest.java @@ -16,6 +16,8 @@ package com.google.common.io; +import static com.google.common.truth.Truth.assertThat; + import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -90,7 +92,7 @@ public void testMarkNotSet() { counter.reset(); fail(); } catch (IOException expected) { - assertEquals("Mark not set", expected.getMessage()); + assertThat(expected).hasMessage("Mark not set"); } } @@ -101,7 +103,7 @@ public void testMarkNotSupported() { counter.reset(); fail(); } catch (IOException expected) { - assertEquals("Mark not supported", expected.getMessage()); + assertThat(expected).hasMessage("Mark not supported"); } } diff --git a/guava-tests/test/com/google/common/io/FilesTest.java b/guava-tests/test/com/google/common/io/FilesTest.java index 67d67f6d2947..c9055e593f80 100644 --- a/guava-tests/test/com/google/common/io/FilesTest.java +++ b/guava-tests/test/com/google/common/io/FilesTest.java @@ -417,7 +417,7 @@ public void testCreateTempDir() { File temp = Files.createTempDir(); assertTrue(temp.exists()); assertTrue(temp.isDirectory()); - assertEquals(0, temp.listFiles().length); + assertThat(temp.listFiles()).isEmpty(); assertTrue(temp.delete()); } diff --git a/guava-tests/test/com/google/common/io/LittleEndianDataInputStreamTest.java b/guava-tests/test/com/google/common/io/LittleEndianDataInputStreamTest.java index d794ad6a33e7..6dae4397b168 100644 --- a/guava-tests/test/com/google/common/io/LittleEndianDataInputStreamTest.java +++ b/guava-tests/test/com/google/common/io/LittleEndianDataInputStreamTest.java @@ -16,6 +16,8 @@ package com.google.common.io; +import static com.google.common.truth.Truth.assertThat; + import com.google.common.primitives.Bytes; import junit.framework.TestCase; @@ -97,7 +99,7 @@ public void testReadLine() throws IOException { in.readLine(); fail(); } catch (UnsupportedOperationException expected) { - assertEquals("readLine is not supported", expected.getMessage()); + assertThat(expected).hasMessage("readLine is not supported"); } } diff --git a/guava-tests/test/com/google/common/io/ResourcesTest.java b/guava-tests/test/com/google/common/io/ResourcesTest.java index ab9e2d2cfe9d..80a21cc8a379 100644 --- a/guava-tests/test/com/google/common/io/ResourcesTest.java +++ b/guava-tests/test/com/google/common/io/ResourcesTest.java @@ -109,7 +109,7 @@ public void testGetResource_notFound() { Resources.getResource("no such resource"); fail(); } catch (IllegalArgumentException e) { - assertEquals("resource no such resource not found.", e.getMessage()); + assertThat(e).hasMessage("resource no such resource not found."); } } @@ -124,9 +124,10 @@ public void testGetResource_relativePath_notFound() { getClass(), "com/google/common/io/testdata/i18n.txt"); fail(); } catch (IllegalArgumentException e) { - assertEquals("resource com/google/common/io/testdata/i18n.txt" + - " relative to com.google.common.io.ResourcesTest not found.", - e.getMessage()); + assertThat(e) + .hasMessage( + "resource com/google/common/io/testdata/i18n.txt" + + " relative to com.google.common.io.ResourcesTest not found."); } } diff --git a/guava-tests/test/com/google/common/net/HostSpecifierTest.java b/guava-tests/test/com/google/common/net/HostSpecifierTest.java index 12c7631fd52c..439bae6ab6d8 100644 --- a/guava-tests/test/com/google/common/net/HostSpecifierTest.java +++ b/guava-tests/test/com/google/common/net/HostSpecifierTest.java @@ -16,6 +16,8 @@ package com.google.common.net; +import static com.google.common.truth.Truth.assertThat; + import com.google.common.collect.ImmutableList; import com.google.common.testing.EqualsTester; import com.google.common.testing.NullPointerTester; @@ -112,7 +114,7 @@ private void assertBad(String spec) { HostSpecifier.from(spec); fail("Should have thrown ParseException: " + spec); } catch (ParseException expected) { - assertTrue(expected.getCause() instanceof IllegalArgumentException); + assertThat(expected.getCause()).isInstanceOf(IllegalArgumentException.class); } assertFalse(HostSpecifier.isValid(spec)); diff --git a/guava-tests/test/com/google/common/net/InetAddressesTest.java b/guava-tests/test/com/google/common/net/InetAddressesTest.java index 79781559b475..f5f2fb505dde 100644 --- a/guava-tests/test/com/google/common/net/InetAddressesTest.java +++ b/guava-tests/test/com/google/common/net/InetAddressesTest.java @@ -16,6 +16,8 @@ package com.google.common.net; +import static com.google.common.truth.Truth.assertThat; + import com.google.common.testing.NullPointerTester; import junit.framework.TestCase; @@ -387,26 +389,26 @@ public void testMappedIPv4Addresses() throws UnknownHostException { String mappedStr = "::ffff:192.168.0.1"; assertTrue(InetAddresses.isMappedIPv4Address(mappedStr)); InetAddress mapped = InetAddresses.forString(mappedStr); - assertFalse(mapped instanceof Inet6Address); + assertThat(mapped).isNotInstanceOf(Inet6Address.class); assertEquals(InetAddress.getByName("192.168.0.1"), mapped); // check upper case mappedStr = "::FFFF:192.168.0.1"; assertTrue(InetAddresses.isMappedIPv4Address(mappedStr)); mapped = InetAddresses.forString(mappedStr); - assertFalse(mapped instanceof Inet6Address); + assertThat(mapped).isNotInstanceOf(Inet6Address.class); assertEquals(InetAddress.getByName("192.168.0.1"), mapped); mappedStr = "0:00:000:0000:0:ffff:1.2.3.4"; assertTrue(InetAddresses.isMappedIPv4Address(mappedStr)); mapped = InetAddresses.forString(mappedStr); - assertFalse(mapped instanceof Inet6Address); + assertThat(mapped).isNotInstanceOf(Inet6Address.class); assertEquals(InetAddress.getByName("1.2.3.4"), mapped); mappedStr = "::ffff:0102:0304"; assertTrue(InetAddresses.isMappedIPv4Address(mappedStr)); mapped = InetAddresses.forString(mappedStr); - assertFalse(mapped instanceof Inet6Address); + assertThat(mapped).isNotInstanceOf(Inet6Address.class); assertEquals(InetAddress.getByName("1.2.3.4"), mapped); assertFalse(InetAddresses.isMappedIPv4Address("::")); diff --git a/guava-tests/test/com/google/common/net/MediaTypeTest.java b/guava-tests/test/com/google/common/net/MediaTypeTest.java index 7c8182d98902..bfbc1c6290ba 100644 --- a/guava-tests/test/com/google/common/net/MediaTypeTest.java +++ b/guava-tests/test/com/google/common/net/MediaTypeTest.java @@ -27,6 +27,7 @@ import static com.google.common.net.MediaType.HTML_UTF_8; import static com.google.common.net.MediaType.JPEG; import static com.google.common.net.MediaType.PLAIN_TEXT_UTF_8; +import static com.google.common.truth.Truth.assertThat; import static java.lang.reflect.Modifier.isFinal; import static java.lang.reflect.Modifier.isPublic; import static java.lang.reflect.Modifier.isStatic; @@ -75,9 +76,9 @@ public class MediaTypeTest extends TestCase { for (Field field : getConstantFields()) { Optional charset = ((MediaType) field.get(null)).charset(); if (field.getName().endsWith("_UTF_8")) { - assertEquals(Optional.of(UTF_8), charset); + assertThat(charset).hasValue(UTF_8); } else { - assertEquals(Optional.absent(), charset); + assertThat(charset).isAbsent(); } } } @@ -331,14 +332,13 @@ public void testParse_badInput() { } public void testGetCharset() { - assertEquals(Optional.absent(), MediaType.parse("text/plain").charset()); - assertEquals(Optional.of(UTF_8), - MediaType.parse("text/plain; charset=utf-8").charset()); + assertThat(MediaType.parse("text/plain").charset()).isAbsent(); + assertThat(MediaType.parse("text/plain; charset=utf-8").charset()).hasValue(UTF_8); } - @GwtIncompatible("Non-UTF-8 Charset") public void testGetCharset_utf16() { - assertEquals(Optional.of(UTF_16), - MediaType.parse("text/plain; charset=utf-16").charset()); + @GwtIncompatible("Non-UTF-8 Charset") + public void testGetCharset_utf16() { + assertThat(MediaType.parse("text/plain; charset=utf-16").charset()).hasValue(UTF_16); } public void testGetCharset_tooMany() { diff --git a/guava-tests/test/com/google/common/net/PercentEscaperTest.java b/guava-tests/test/com/google/common/net/PercentEscaperTest.java index 65425d3847b9..7acdd41f85ca 100644 --- a/guava-tests/test/com/google/common/net/PercentEscaperTest.java +++ b/guava-tests/test/com/google/common/net/PercentEscaperTest.java @@ -19,6 +19,7 @@ import static com.google.common.escape.testing.EscaperAsserts.assertEscaping; import static com.google.common.escape.testing.EscaperAsserts.assertUnescaped; import static com.google.common.escape.testing.EscaperAsserts.assertUnicodeEscaping; +import static com.google.common.truth.Truth.assertThat; import com.google.common.annotations.GwtCompatible; import com.google.common.base.Preconditions; @@ -124,7 +125,7 @@ public void testBadArguments_badchars() { new PercentEscaper("-+#abc.!", false); fail(msg); } catch (IllegalArgumentException expected) { - assertEquals(msg, expected.getMessage()); + assertThat(expected).hasMessage(msg); } } @@ -144,7 +145,7 @@ public void testBadArguments_plusforspace() { new PercentEscaper(" ", true); fail(msg); } catch (IllegalArgumentException expected) { - assertEquals(msg, expected.getMessage()); + assertThat(expected).hasMessage(msg); } } diff --git a/guava-tests/test/com/google/common/primitives/DoublesTest.java b/guava-tests/test/com/google/common/primitives/DoublesTest.java index 990ecf210ca2..23fa450d8157 100644 --- a/guava-tests/test/com/google/common/primitives/DoublesTest.java +++ b/guava-tests/test/com/google/common/primitives/DoublesTest.java @@ -439,7 +439,7 @@ private static void checkTryParse(String input) { @GwtIncompatible("Doubles.tryParse") private static void checkTryParse(double expected, String input) { assertEquals(Double.valueOf(expected), Doubles.tryParse(input)); - assertTrue(Doubles.FLOATING_POINT_PATTERN.matcher(input).matches()); + assertThat(input).matches(Doubles.FLOATING_POINT_PATTERN); } @GwtIncompatible("Doubles.tryParse") @@ -507,7 +507,7 @@ public void testTryParseInfinity() { @GwtIncompatible("Doubles.tryParse") public void testTryParseFailures() { for (String badInput : BAD_TRY_PARSE_INPUTS) { - assertFalse(Doubles.FLOATING_POINT_PATTERN.matcher(badInput).matches()); + assertThat(badInput).doesNotMatch(Doubles.FLOATING_POINT_PATTERN); assertEquals(referenceTryParse(badInput), Doubles.tryParse(badInput)); assertNull(Doubles.tryParse(badInput)); } diff --git a/guava-tests/test/com/google/common/reflect/InvokableTest.java b/guava-tests/test/com/google/common/reflect/InvokableTest.java index 8f20f6772133..af0f9c05a919 100644 --- a/guava-tests/test/com/google/common/reflect/InvokableTest.java +++ b/guava-tests/test/com/google/common/reflect/InvokableTest.java @@ -16,6 +16,8 @@ package com.google.common.reflect; +import static com.google.common.truth.Truth.assertThat; + import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.google.common.testing.EqualsTester; @@ -57,7 +59,7 @@ public void testConstructor_returnType_hasTypeParameter() throws Exception { @SuppressWarnings("rawtypes") // Foo.class Constructor constructor = type.getDeclaredConstructor(); Invokable factory = Invokable.from(constructor); - assertEquals(2, factory.getTypeParameters().length); + assertThat(factory.getTypeParameters()).hasLength(2); assertEquals(type.getTypeParameters()[0], factory.getTypeParameters()[0]); assertEquals(constructor.getTypeParameters()[0], factory.getTypeParameters()[1]); ParameterizedType returnType = (ParameterizedType) factory.getReturnType().getType(); @@ -72,9 +74,8 @@ public void testConstructor_exceptionTypes() throws Exception { } public void testConstructor_typeParameters() throws Exception { - TypeVariable[] variables = - Prepender.constructor().getTypeParameters(); - assertEquals(1, variables.length); + TypeVariable[] variables = Prepender.constructor().getTypeParameters(); + assertThat(variables).hasLength(1); assertEquals("A", variables[0].getName()); } @@ -128,7 +129,7 @@ public void testStaticMethod_exceptionTypes() throws Exception { public void testStaticMethod_typeParameters() throws Exception { Invokable delegate = Prepender.method("prepend", String.class, Iterable.class); TypeVariable[] variables = delegate.getTypeParameters(); - assertEquals(1, variables.length); + assertThat(variables).hasLength(1); assertEquals("T", variables[0].getName()); } @@ -198,7 +199,7 @@ public void testInstanceMethod_exceptionTypes() throws Exception { public void testInstanceMethod_typeParameters() throws Exception { Invokable delegate = Prepender.method("prepend", Iterable.class); - assertEquals(0, delegate.getTypeParameters().length); + assertThat(delegate.getTypeParameters()).isEmpty(); } public void testInstanceMethod_parameters() throws Exception { @@ -206,10 +207,8 @@ public void testInstanceMethod_parameters() throws Exception { ImmutableList parameters = delegate.getParameters(); assertEquals(1, parameters.size()); assertEquals(new TypeToken>() {}, parameters.get(0).getType()); - assertEquals(0, parameters.get(0).getAnnotations().length); - new EqualsTester() - .addEqualityGroup(parameters.get(0)) - .testEquals(); + assertThat(parameters.get(0).getAnnotations()).isEmpty(); + new EqualsTester().addEqualityGroup(parameters.get(0)).testEquals(); } public void testInstanceMethod_call() throws Exception { diff --git a/guava-tests/test/com/google/common/reflect/TypeTokenTest.java b/guava-tests/test/com/google/common/reflect/TypeTokenTest.java index 2429dda650a6..4a9139267316 100644 --- a/guava-tests/test/com/google/common/reflect/TypeTokenTest.java +++ b/guava-tests/test/com/google/common/reflect/TypeTokenTest.java @@ -113,13 +113,13 @@ class Local {} public void testGenericArrayType() { TypeToken[]> token = new TypeToken[]>() {}; assertEquals(List[].class, token.getRawType()); - assertTrue(token.getType() instanceof GenericArrayType); + assertThat(token.getType()).isInstanceOf(GenericArrayType.class); } public void testMultiDimensionalGenericArrayType() { TypeToken[][][]> token = new TypeToken[][][]>() {}; assertEquals(List[][][].class, token.getRawType()); - assertTrue(token.getType() instanceof GenericArrayType); + assertThat(token.getType()).isInstanceOf(GenericArrayType.class); } public void testGenericVariableTypeArrays() { diff --git a/guava-tests/test/com/google/common/util/concurrent/AbstractExecutionThreadServiceTest.java b/guava-tests/test/com/google/common/util/concurrent/AbstractExecutionThreadServiceTest.java index 0322912b449a..587ff26785ae 100644 --- a/guava-tests/test/com/google/common/util/concurrent/AbstractExecutionThreadServiceTest.java +++ b/guava-tests/test/com/google/common/util/concurrent/AbstractExecutionThreadServiceTest.java @@ -172,13 +172,13 @@ public void testServiceThrowOnStartUp() throws Exception { service.awaitRunning(); fail(); } catch (IllegalStateException expected) { - assertEquals("kaboom!", expected.getCause().getMessage()); + assertThat(expected.getCause()).hasMessage("kaboom!"); } executionThread.join(); assertTrue(service.startUpCalled); assertEquals(Service.State.FAILED, service.state()); - assertEquals("kaboom!", service.failureCause().getMessage()); + assertThat(service.failureCause()).hasMessage("kaboom!"); } private class ThrowOnStartUpService extends AbstractExecutionThreadService { @@ -208,7 +208,7 @@ public void testServiceThrowOnRun() throws Exception { } catch (IllegalStateException expected) { executionThread.join(); assertEquals(service.failureCause(), expected.getCause()); - assertEquals("kaboom!", expected.getCause().getMessage()); + assertThat(expected.getCause()).hasMessage("kaboom!"); } assertTrue(service.shutDownCalled); assertEquals(Service.State.FAILED, service.state()); @@ -225,7 +225,7 @@ public void testServiceThrowOnRunAndThenAgainOnShutDown() throws Exception { } catch (IllegalStateException expected) { executionThread.join(); assertEquals(service.failureCause(), expected.getCause()); - assertEquals("kaboom!", expected.getCause().getMessage()); + assertThat(expected.getCause()).hasMessage("kaboom!"); } assertTrue(service.shutDownCalled); @@ -263,7 +263,7 @@ public void testServiceThrowOnShutDown() throws Exception { executionThread.join(); assertEquals(Service.State.FAILED, service.state()); - assertEquals("kaboom!", service.failureCause().getMessage()); + assertThat(service.failureCause()).hasMessage("kaboom!"); } private class ThrowOnShutDown extends AbstractExecutionThreadService { @@ -291,7 +291,7 @@ public void testServiceTimeoutOnStartUp() throws Exception { service.startAsync().awaitRunning(1, TimeUnit.MILLISECONDS); fail(); } catch (TimeoutException e) { - assertTrue(e.getMessage().contains(Service.State.STARTING.toString())); + assertThat(e.getMessage()).contains(Service.State.STARTING.toString()); } } @@ -359,8 +359,7 @@ public void testTimeout() { service.startAsync().awaitRunning(1, TimeUnit.MILLISECONDS); fail("Expected timeout"); } catch (TimeoutException e) { - assertThat(e.getMessage()) - .isEqualTo("Timed out waiting for Foo [STARTING] to reach the RUNNING state."); + assertThat(e).hasMessage("Timed out waiting for Foo [STARTING] to reach the RUNNING state."); } } diff --git a/guava-tests/test/com/google/common/util/concurrent/AbstractIdleServiceTest.java b/guava-tests/test/com/google/common/util/concurrent/AbstractIdleServiceTest.java index 97df4b4ecdde..fbfa404a81bb 100644 --- a/guava-tests/test/com/google/common/util/concurrent/AbstractIdleServiceTest.java +++ b/guava-tests/test/com/google/common/util/concurrent/AbstractIdleServiceTest.java @@ -189,8 +189,7 @@ public void testTimeout() throws Exception { service.startAsync().awaitRunning(1, TimeUnit.MILLISECONDS); fail("Expected timeout"); } catch (TimeoutException e) { - assertThat(e.getMessage()) - .isEqualTo("Timed out waiting for Foo [STARTING] to reach the RUNNING state."); + assertThat(e).hasMessage("Timed out waiting for Foo [STARTING] to reach the RUNNING state."); } } diff --git a/guava-tests/test/com/google/common/util/concurrent/AbstractListeningExecutorServiceTest.java b/guava-tests/test/com/google/common/util/concurrent/AbstractListeningExecutorServiceTest.java index ee0897114385..7742dbb6f2df 100644 --- a/guava-tests/test/com/google/common/util/concurrent/AbstractListeningExecutorServiceTest.java +++ b/guava-tests/test/com/google/common/util/concurrent/AbstractListeningExecutorServiceTest.java @@ -16,6 +16,8 @@ package com.google.common.util.concurrent; +import static com.google.common.truth.Truth.assertThat; + import com.google.common.collect.ImmutableList; import junit.framework.TestCase; @@ -41,18 +43,18 @@ public void testSubmit() throws Exception { TestRunnable runnable = new TestRunnable(); ListenableFuture runnableFuture = e.submit(runnable); - assertTrue(runnableFuture instanceof TrustedListenableFutureTask); + assertThat(runnableFuture).isInstanceOf(TrustedListenableFutureTask.class); assertTrue(runnableFuture.isDone()); assertTrue(runnable.run); ListenableFuture callableFuture = e.submit(new TestCallable()); - assertTrue(callableFuture instanceof TrustedListenableFutureTask); + assertThat(callableFuture).isInstanceOf(TrustedListenableFutureTask.class); assertTrue(callableFuture.isDone()); assertEquals("foo", callableFuture.get()); TestRunnable runnable2 = new TestRunnable(); ListenableFuture runnableFuture2 = e.submit(runnable2, 3); - assertTrue(runnableFuture2 instanceof TrustedListenableFutureTask); + assertThat(runnableFuture2).isInstanceOf(TrustedListenableFutureTask.class); assertTrue(runnableFuture2.isDone()); assertTrue(runnable2.run); assertEquals((Integer) 3, runnableFuture2.get()); @@ -81,7 +83,7 @@ private static class TestListeningExecutorService extends AbstractListeningExecu @Override public void execute(Runnable runnable) { - assertTrue(runnable instanceof TrustedListenableFutureTask); + assertThat(runnable).isInstanceOf(TrustedListenableFutureTask.class); runnable.run(); } diff --git a/guava-tests/test/com/google/common/util/concurrent/AbstractScheduledServiceTest.java b/guava-tests/test/com/google/common/util/concurrent/AbstractScheduledServiceTest.java index 068da20d7bcb..599c1ab8ca75 100644 --- a/guava-tests/test/com/google/common/util/concurrent/AbstractScheduledServiceTest.java +++ b/guava-tests/test/com/google/common/util/concurrent/AbstractScheduledServiceTest.java @@ -267,8 +267,7 @@ public void testTimeout() { service.startAsync().awaitRunning(1, TimeUnit.MILLISECONDS); fail("Expected timeout"); } catch (TimeoutException e) { - assertThat(e.getMessage()) - .isEqualTo("Timed out waiting for Foo [STARTING] to reach the RUNNING state."); + assertThat(e).hasMessage("Timed out waiting for Foo [STARTING] to reach the RUNNING state."); } } diff --git a/guava-tests/test/com/google/common/util/concurrent/AbstractServiceTest.java b/guava-tests/test/com/google/common/util/concurrent/AbstractServiceTest.java index 1fdac3853799..a6eeaa9d4da0 100644 --- a/guava-tests/test/com/google/common/util/concurrent/AbstractServiceTest.java +++ b/guava-tests/test/com/google/common/util/concurrent/AbstractServiceTest.java @@ -16,6 +16,7 @@ package com.google.common.util.concurrent; +import static com.google.common.truth.Truth.assertThat; import static com.google.common.util.concurrent.MoreExecutors.directExecutor; import static java.lang.Thread.currentThread; import static java.util.concurrent.TimeUnit.SECONDS; @@ -380,7 +381,7 @@ public void testAwaitTerminated_FailedService() throws Exception { assertEquals(State.FAILED, service.state()); waiter.join(LONG_TIMEOUT_MILLIS); assertFalse(waiter.isAlive()); - assertTrue(exception.get() instanceof IllegalStateException); + assertThat(exception.get()).isInstanceOf(IllegalStateException.class); assertEquals(EXCEPTION, exception.get().getCause()); } @@ -460,12 +461,12 @@ public void testManualServiceFailureIdempotence() { service.startAsync(); service.notifyFailed(new Exception("1")); service.notifyFailed(new Exception("2")); - assertEquals("1", service.failureCause().getMessage()); + assertThat(service.failureCause()).hasMessage("1"); try { service.awaitRunning(); fail(); } catch (IllegalStateException e) { - assertEquals("1", e.getCause().getMessage()); + assertThat(e.getCause()).hasMessage("1"); } } diff --git a/guava-tests/test/com/google/common/util/concurrent/FutureCallbackTest.java b/guava-tests/test/com/google/common/util/concurrent/FutureCallbackTest.java index 9b93ccde7aaa..a98f4a6944d9 100644 --- a/guava-tests/test/com/google/common/util/concurrent/FutureCallbackTest.java +++ b/guava-tests/test/com/google/common/util/concurrent/FutureCallbackTest.java @@ -16,6 +16,8 @@ package com.google.common.util.concurrent; +import static com.google.common.truth.Truth.assertThat; + import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import com.google.common.base.Preconditions; @@ -68,6 +70,7 @@ public void testCancel() { FutureCallback callback = new FutureCallback() { private boolean called = false; + @Override public void onSuccess(String result) { fail("Was not expecting onSuccess() to be called."); @@ -76,7 +79,7 @@ public void onSuccess(String result) { @Override public synchronized void onFailure(Throwable t) { assertFalse(called); - assertTrue(t instanceof CancellationException); + assertThat(t).isInstanceOf(CancellationException.class); called = true; } }; diff --git a/guava-tests/test/com/google/common/util/concurrent/FuturesGetCheckedTest.java b/guava-tests/test/com/google/common/util/concurrent/FuturesGetCheckedTest.java index e8e665cb785a..11a9844f05d1 100644 --- a/guava-tests/test/com/google/common/util/concurrent/FuturesGetCheckedTest.java +++ b/guava-tests/test/com/google/common/util/concurrent/FuturesGetCheckedTest.java @@ -66,7 +66,7 @@ public void testGetCheckedUntimed_interrupted() { getChecked(future, TwoArgConstructorException.class); fail(); } catch (TwoArgConstructorException expected) { - assertTrue(expected.getCause() instanceof InterruptedException); + assertThat(expected.getCause()).isInstanceOf(InterruptedException.class); assertTrue(Thread.currentThread().isInterrupted()); } finally { Thread.interrupted(); @@ -170,7 +170,7 @@ public void testGetCheckedTimed_interrupted() { getChecked(future, TwoArgConstructorException.class, 0, SECONDS); fail(); } catch (TwoArgConstructorException expected) { - assertTrue(expected.getCause() instanceof InterruptedException); + assertThat(expected.getCause()).isInstanceOf(InterruptedException.class); assertTrue(Thread.currentThread().isInterrupted()); } finally { Thread.interrupted(); @@ -238,7 +238,7 @@ public void testGetCheckedTimed_TimeoutException() { getChecked(future, TwoArgConstructorException.class, 0, SECONDS); fail(); } catch (TwoArgConstructorException expected) { - assertTrue(expected.getCause() instanceof TimeoutException); + assertThat(expected.getCause()).isInstanceOf(TimeoutException.class); } } diff --git a/guava-tests/test/com/google/common/util/concurrent/FuturesTest.java b/guava-tests/test/com/google/common/util/concurrent/FuturesTest.java index 4bb3892c80d4..73290646067d 100644 --- a/guava-tests/test/com/google/common/util/concurrent/FuturesTest.java +++ b/guava-tests/test/com/google/common/util/concurrent/FuturesTest.java @@ -167,7 +167,7 @@ public void testImmediateCancelledFuture() throws Exception { assertFalse(Iterables.any(stackTrace, hasClassName(CallerClass1.class))); assertTrue(Iterables.any(stackTrace, hasClassName(CallerClass2.class))); - assertTrue(e.getCause() instanceof CancellationException); + assertThat(e.getCause()).isInstanceOf(CancellationException.class); stackTrace = ImmutableList.copyOf(e.getCause().getStackTrace()); assertTrue(Iterables.any(stackTrace, hasClassName(CallerClass1.class))); assertFalse(Iterables.any(stackTrace, hasClassName(CallerClass2.class))); @@ -449,7 +449,7 @@ public void testTransform_rejectionPropagatesToOutput() transformed.get(5, TimeUnit.SECONDS); fail(); } catch (ExecutionException expected) { - assertTrue(expected.getCause() instanceof RejectedExecutionException); + assertThat(expected.getCause()).isInstanceOf(RejectedExecutionException.class); } } @@ -1258,7 +1258,7 @@ public void testCatching_customTypeNoMatch() throws Exception { faultTolerantFuture.get(); fail(); } catch (ExecutionException expected) { - assertTrue(expected.getCause() instanceof RuntimeException); + assertThat(expected.getCause()).isInstanceOf(RuntimeException.class); } } @@ -1289,7 +1289,7 @@ public void testCatchingAsync_customTypeNoMatch() throws Exception { faultTolerantFuture.get(); fail(); } catch (ExecutionException expected) { - assertTrue(expected.getCause() instanceof RuntimeException); + assertThat(expected.getCause()).isInstanceOf(RuntimeException.class); } } @@ -1305,7 +1305,7 @@ public void testCatchingAsync_rejectionPropagatesToOutput() throws Exception { transformed.get(5, TimeUnit.SECONDS); fail(); } catch (ExecutionException expected) { - assertTrue(expected.getCause() instanceof RejectedExecutionException); + assertThat(expected.getCause()).isInstanceOf(RejectedExecutionException.class); } } @@ -1910,9 +1910,9 @@ public void testAllAsList_logging_exception() throws Exception { Futures.allAsList(immediateFailedFuture(new MyException())).get(); fail(); } catch (ExecutionException e) { - assertTrue(e.getCause() instanceof MyException); - assertEquals("Nothing should be logged", 0, - aggregateFutureLogHandler.getStoredLogRecords().size()); + assertThat(e.getCause()).isInstanceOf(MyException.class); + assertEquals( + "Nothing should be logged", 0, aggregateFutureLogHandler.getStoredLogRecords().size()); } } @@ -1925,10 +1925,10 @@ public void testAllAsList_logging_error() throws Exception { Futures.allAsList(immediateFailedFuture(new MyError())).get(); fail(); } catch (ExecutionException e) { - assertTrue(e.getCause() instanceof MyError); + assertThat(e.getCause()).isInstanceOf(MyError.class); List logged = aggregateFutureLogHandler.getStoredLogRecords(); - assertEquals(1, logged.size()); // errors are always logged - assertTrue(logged.get(0).getThrown() instanceof MyError); + assertThat(logged).hasSize(1); // errors are always logged + assertThat(logged.get(0).getThrown()).isInstanceOf(MyError.class); } } @@ -1942,10 +1942,10 @@ public void testAllAsList_logging_multipleExceptions_alreadyDone() throws Except immediateFailedFuture(new MyException())).get(); fail(); } catch (ExecutionException e) { - assertTrue(e.getCause() instanceof MyException); + assertThat(e.getCause()).isInstanceOf(MyException.class); List logged = aggregateFutureLogHandler.getStoredLogRecords(); - assertEquals(1, logged.size()); // the second failure is logged - assertTrue(logged.get(0).getThrown() instanceof MyException); + assertThat(logged).hasSize(1); // the second failure is logged + assertThat(logged.get(0).getThrown()).isInstanceOf(MyException.class); } } @@ -1967,9 +1967,9 @@ public void testAllAsList_logging_multipleExceptions_doneLater() throws Exceptio all.get(); } catch (ExecutionException e) { List logged = aggregateFutureLogHandler.getStoredLogRecords(); - assertEquals(2, logged.size()); // failures are the first are logged - assertTrue(logged.get(0).getThrown() instanceof MyException); - assertTrue(logged.get(1).getThrown() instanceof MyException); + assertThat(logged).hasSize(2); // failures after the first are logged + assertThat(logged.get(0).getThrown()).isInstanceOf(MyException.class); + assertThat(logged.get(1).getThrown()).isInstanceOf(MyException.class); } } @@ -1984,9 +1984,9 @@ public void testAllAsList_logging_same_exception() throws Exception { immediateFailedFuture(sameInstance)).get(); fail(); } catch (ExecutionException e) { - assertTrue(e.getCause() instanceof MyException); - assertEquals("Nothing should be logged", 0, - aggregateFutureLogHandler.getStoredLogRecords().size()); + assertThat(e.getCause()).isInstanceOf(MyException.class); + assertEquals( + "Nothing should be logged", 0, aggregateFutureLogHandler.getStoredLogRecords().size()); } } @@ -2013,7 +2013,7 @@ public void run() { bulkFuture.get(); fail(); } catch (ExecutionException expected) { - assertTrue(expected.getCause() instanceof MyException); + assertThat(expected.getCause()).isInstanceOf(MyException.class); assertThat(aggregateFutureLogHandler.getStoredLogRecords()).isEmpty(); } } @@ -2064,9 +2064,9 @@ public void testAllAsList_logging_same_cause() throws Exception { immediateFailedFuture(exception3)).get(); fail(); } catch (ExecutionException e) { - assertTrue(e.getCause() instanceof MyException); - assertEquals("Nothing should be logged", 0, - aggregateFutureLogHandler.getStoredLogRecords().size()); + assertThat(e.getCause()).isInstanceOf(MyException.class); + assertEquals( + "Nothing should be logged", 0, aggregateFutureLogHandler.getStoredLogRecords().size()); } } @@ -2606,22 +2606,21 @@ public void testSuccessfulAsList_resultCancelledRacingInputDone() * ExecutionList and logged rather than allowed to propagate. We need to * turn that back into a failure. */ - Handler throwingHandler = new Handler() { - @Override - public void publish(@Nullable LogRecord record) { - AssertionFailedError error = new AssertionFailedError(); - error.initCause(record.getThrown()); - throw error; - } + Handler throwingHandler = + new Handler() { + @Override + public void publish(LogRecord record) { + AssertionFailedError error = new AssertionFailedError(); + error.initCause(record.getThrown()); + throw error; + } - @Override - public void flush() { - } + @Override + public void flush() {} - @Override - public void close() { - } - }; + @Override + public void close() {} + }; ExecutionList.log.addHandler(throwingHandler); try { @@ -2749,8 +2748,8 @@ public void testSuccessfulAsList_logging_error() throws Exception { Futures.successfulAsList( immediateFailedFuture(new MyError())).get()); List logged = aggregateFutureLogHandler.getStoredLogRecords(); - assertEquals(1, logged.size()); // errors are always logged - assertTrue(logged.get(0).getThrown() instanceof MyError); + assertThat(logged).hasSize(1); // errors are always logged + assertThat(logged.get(0).getThrown()).isInstanceOf(MyError.class); } @GwtIncompatible("nonCancellationPropagating") @@ -2844,28 +2843,28 @@ public void testMakeChecked_mapsExecutionExceptions() throws Exception { checked.get(); fail(); } catch (ExecutionException e) { - assertTrue(e.getCause() instanceof IOException); + assertThat(e.getCause()).isInstanceOf(IOException.class); } try { checked.get(5, TimeUnit.SECONDS); fail(); } catch (ExecutionException e) { - assertTrue(e.getCause() instanceof IOException); + assertThat(e.getCause()).isInstanceOf(IOException.class); } try { checked.checkedGet(); fail(); } catch (TestException e) { - assertTrue(e.getCause() instanceof IOException); + assertThat(e.getCause()).isInstanceOf(IOException.class); } try { checked.checkedGet(5, TimeUnit.SECONDS); fail(); } catch (TestException e) { - assertTrue(e.getCause() instanceof IOException); + assertThat(e.getCause()).isInstanceOf(IOException.class); } } @@ -2900,7 +2899,7 @@ public void testMakeChecked_mapsInterruption() throws Exception { checked.checkedGet(); fail(); } catch (TestException e) { - assertTrue(e.getCause() instanceof InterruptedException); + assertThat(e.getCause()).isInstanceOf(InterruptedException.class); } Thread.currentThread().interrupt(); @@ -2909,7 +2908,7 @@ public void testMakeChecked_mapsInterruption() throws Exception { checked.checkedGet(5, TimeUnit.SECONDS); fail(); } catch (TestException e) { - assertTrue(e.getCause() instanceof InterruptedException); + assertThat(e.getCause()).isInstanceOf(InterruptedException.class); } } @@ -2938,14 +2937,14 @@ public void testMakeChecked_mapsCancellation() throws Exception { checked.checkedGet(); fail(); } catch (TestException expected) { - assertTrue(expected.getCause() instanceof CancellationException); + assertThat(expected.getCause()).isInstanceOf(CancellationException.class); } try { checked.checkedGet(5, TimeUnit.SECONDS); fail(); } catch (TestException expected) { - assertTrue(expected.getCause() instanceof CancellationException); + assertThat(expected.getCause()).isInstanceOf(CancellationException.class); } } @@ -3090,7 +3089,7 @@ public void testCompletionOrderExceptionThrown() throws Exception { fail(); } catch (ExecutionException e) { // Expected - assertEquals("2L", e.getCause().getMessage()); + assertThat(e.getCause()).hasMessage("2L"); } } expected++; diff --git a/guava-tests/test/com/google/common/util/concurrent/ListenableFutureTester.java b/guava-tests/test/com/google/common/util/concurrent/ListenableFutureTester.java index cb10fc8922f4..d9e100c6eaae 100644 --- a/guava-tests/test/com/google/common/util/concurrent/ListenableFutureTester.java +++ b/guava-tests/test/com/google/common/util/concurrent/ListenableFutureTester.java @@ -17,6 +17,7 @@ package com.google.common.util.concurrent; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.truth.Truth.assertThat; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; @@ -104,7 +105,7 @@ public void testFailedFuture(@Nullable String message) future.get(); fail("Future should rethrow the exception."); } catch (ExecutionException e) { - assertEquals(message, e.getCause().getMessage()); + assertThat(e.getCause()).hasMessage(message); } } } diff --git a/guava-tests/test/com/google/common/util/concurrent/MoreExecutorsTest.java b/guava-tests/test/com/google/common/util/concurrent/MoreExecutorsTest.java index 94096e2354e5..994d5d9455c9 100644 --- a/guava-tests/test/com/google/common/util/concurrent/MoreExecutorsTest.java +++ b/guava-tests/test/com/google/common/util/concurrent/MoreExecutorsTest.java @@ -309,7 +309,7 @@ public void testListeningExecutorServiceInvokeAllJavadocCodeCompiles() ListeningExecutorService executor = newDirectExecutorService(); List> tasks = ImmutableList.of(); @SuppressWarnings("unchecked") // guaranteed by invokeAll contract - List> futures = (List) executor.invokeAll(tasks); + List> unused = (List) executor.invokeAll(tasks); } public void testListeningDecorator() throws Exception { @@ -519,7 +519,7 @@ public void testInvokeAnyImpl_noTaskCompletes() throws Exception { invokeAnyImpl(e, l, false, 0); shouldThrow(); } catch (ExecutionException success) { - assertTrue(success.getCause() instanceof NullPointerException); + assertThat(success.getCause()).isInstanceOf(NullPointerException.class); } finally { joinPool(e); } diff --git a/guava-tests/test/com/google/common/util/concurrent/ServiceManagerTest.java b/guava-tests/test/com/google/common/util/concurrent/ServiceManagerTest.java index 1ea6a4bd4303..9fecf0a7bda3 100644 --- a/guava-tests/test/com/google/common/util/concurrent/ServiceManagerTest.java +++ b/guava-tests/test/com/google/common/util/concurrent/ServiceManagerTest.java @@ -247,8 +247,8 @@ public void testToString() throws Exception { Service b = new FailStartService(); ServiceManager manager = new ServiceManager(asList(a, b)); String toString = manager.toString(); - assertTrue(toString.contains("NoOpService")); - assertTrue(toString.contains("FailStartService")); + assertThat(toString).contains("NoOpService"); + assertThat(toString).contains("FailStartService"); } public void testTimeouts() throws Exception { @@ -367,7 +367,7 @@ public void testEmptyServiceManager() { } }; for (LogRecord record : logHandler.getStoredLogRecords()) { - assertFalse(logFormatter.format(record).contains("NoOpService")); + assertThat(logFormatter.format(record)).doesNotContain("NoOpService"); } } @@ -502,7 +502,7 @@ public void testPartiallyConstructedManager_transitionAfterAddListenerBeforeStat new ServiceManager(Arrays.asList(service1, service2)); fail(); } catch (IllegalArgumentException expected) { - assertTrue(expected.getMessage().contains("started transitioning asynchronously")); + assertThat(expected.getMessage()).contains("started transitioning asynchronously"); } } diff --git a/guava-tests/test/com/google/common/util/concurrent/ThreadFactoryBuilderTest.java b/guava-tests/test/com/google/common/util/concurrent/ThreadFactoryBuilderTest.java index cb1689cdf152..18cb51c9e6ab 100644 --- a/guava-tests/test/com/google/common/util/concurrent/ThreadFactoryBuilderTest.java +++ b/guava-tests/test/com/google/common/util/concurrent/ThreadFactoryBuilderTest.java @@ -91,7 +91,7 @@ public void testThreadFactoryBuilder_defaults() throws InterruptedException { } private static void checkThreadPoolName(Thread thread, int threadId) { - assertTrue(thread.getName().matches("^pool-\\d+-thread-" + threadId + "$")); + assertThat(thread.getName()).matches("^pool-\\d+-thread-" + threadId + "$"); } public void testNameFormatWithPercentS_custom() { diff --git a/guava-tests/test/com/google/common/util/concurrent/WrappingExecutorServiceTest.java b/guava-tests/test/com/google/common/util/concurrent/WrappingExecutorServiceTest.java index 900bd5d78a54..cb6d72360aa3 100644 --- a/guava-tests/test/com/google/common/util/concurrent/WrappingExecutorServiceTest.java +++ b/guava-tests/test/com/google/common/util/concurrent/WrappingExecutorServiceTest.java @@ -16,6 +16,7 @@ package com.google.common.util.concurrent; +import static com.google.common.truth.Truth.assertThat; import static com.google.common.util.concurrent.MoreExecutors.newDirectExecutorService; import static com.google.common.util.concurrent.Runnables.doNothing; @@ -271,28 +272,28 @@ public List shutdownNow() { @Override public Future submit(Callable task) { lastMethodCalled = "submit"; - assertTrue(task instanceof WrappedCallable); + assertThat(task).isInstanceOf(WrappedCallable.class); return inline.submit(task); } @Override public Future submit(Runnable task) { lastMethodCalled = "submit"; - assertTrue(task instanceof WrappedRunnable); + assertThat(task).isInstanceOf(WrappedRunnable.class); return inline.submit(task); } @Override public Future submit(Runnable task, T result) { lastMethodCalled = "submit"; - assertTrue(task instanceof WrappedRunnable); + assertThat(task).isInstanceOf(WrappedRunnable.class); return inline.submit(task, result); } @Override public void execute(Runnable command) { lastMethodCalled = "execute"; - assertTrue(command instanceof WrappedRunnable); + assertThat(command).isInstanceOf(WrappedRunnable.class); inline.execute(command); } diff --git a/guava-tests/test/com/google/common/util/concurrent/WrappingScheduledExecutorServiceTest.java b/guava-tests/test/com/google/common/util/concurrent/WrappingScheduledExecutorServiceTest.java index 9beadb487ea5..24c35f013d30 100644 --- a/guava-tests/test/com/google/common/util/concurrent/WrappingScheduledExecutorServiceTest.java +++ b/guava-tests/test/com/google/common/util/concurrent/WrappingScheduledExecutorServiceTest.java @@ -16,6 +16,8 @@ package com.google.common.util.concurrent; +import static com.google.common.truth.Truth.assertThat; + import junit.framework.TestCase; import java.util.Collection; @@ -122,26 +124,28 @@ void assertLastMethodCalled(String method, long initialDelay, long delay, TimeUn assertEquals(unit, lastUnit); } - @Override public ScheduledFuture schedule(Runnable command, long delay, TimeUnit unit) { - assertTrue(command instanceof WrappedRunnable); + @Override + public ScheduledFuture schedule(Runnable command, long delay, TimeUnit unit) { + assertThat(command).isInstanceOf(WrappedRunnable.class); lastMethodCalled = "scheduleRunnable"; lastDelay = delay; lastUnit = unit; return null; } - @Override public ScheduledFuture schedule( - Callable callable, long delay, TimeUnit unit) { - assertTrue(callable instanceof WrappedCallable); + @Override + public ScheduledFuture schedule(Callable callable, long delay, TimeUnit unit) { + assertThat(callable).isInstanceOf(WrappedCallable.class); lastMethodCalled = "scheduleCallable"; lastDelay = delay; lastUnit = unit; return null; } - @Override public ScheduledFuture scheduleAtFixedRate( + @Override + public ScheduledFuture scheduleAtFixedRate( Runnable command, long initialDelay, long period, TimeUnit unit) { - assertTrue(command instanceof WrappedRunnable); + assertThat(command).isInstanceOf(WrappedRunnable.class); lastMethodCalled = "scheduleAtFixedRate"; lastInitialDelay = initialDelay; lastDelay = period; @@ -149,9 +153,10 @@ void assertLastMethodCalled(String method, long initialDelay, long delay, TimeUn return null; } - @Override public ScheduledFuture scheduleWithFixedDelay( + @Override + public ScheduledFuture scheduleWithFixedDelay( Runnable command, long initialDelay, long delay, TimeUnit unit) { - assertTrue(command instanceof WrappedRunnable); + assertThat(command).isInstanceOf(WrappedRunnable.class); lastMethodCalled = "scheduleWithFixedDelay"; lastInitialDelay = initialDelay; lastDelay = delay;