diff options
author | 2017-05-30 12:35:33 +0200 | |
---|---|---|
committer | 2017-05-30 12:51:57 +0200 | |
commit | aea56b36af994b269800602e36000c293cabd00b (patch) | |
tree | 794f6b3b2528353cc39bd383730d408d4ff25233 /src/test/java/com/google/devtools/build/lib/collect/CollectionUtilsTest.java | |
parent | 229f393bf460700594ae032a551879e026bd0b91 (diff) |
Migrate Java tests to Truth.
RELNOTES: None.
PiperOrigin-RevId: 157446717
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/collect/CollectionUtilsTest.java')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/collect/CollectionUtilsTest.java | 59 |
1 files changed, 26 insertions, 33 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/collect/CollectionUtilsTest.java b/src/test/java/com/google/devtools/build/lib/collect/CollectionUtilsTest.java index 769730f9c7..9f8b3770a1 100644 --- a/src/test/java/com/google/devtools/build/lib/collect/CollectionUtilsTest.java +++ b/src/test/java/com/google/devtools/build/lib/collect/CollectionUtilsTest.java @@ -14,11 +14,6 @@ package com.google.devtools.build.lib.collect; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import com.google.common.collect.ImmutableList; @@ -28,15 +23,13 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - import java.util.EnumSet; import java.util.HashSet; import java.util.List; import java.util.Set; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; /** * Tests for {@link CollectionUtils}. @@ -56,37 +49,37 @@ public class CollectionUtilsTest { } private static void assertDups(List<Integer> collection, Set<Integer> dups) { - assertEquals(dups, CollectionUtils.duplicatedElementsOf(collection)); + assertThat(CollectionUtils.duplicatedElementsOf(collection)).isEqualTo(dups); } @Test public void testIsImmutable() throws Exception { - assertTrue(CollectionUtils.isImmutable(ImmutableList.of(1, 2, 3))); - assertTrue(CollectionUtils.isImmutable(ImmutableSet.of(1, 2, 3))); + assertThat(CollectionUtils.isImmutable(ImmutableList.of(1, 2, 3))).isTrue(); + assertThat(CollectionUtils.isImmutable(ImmutableSet.of(1, 2, 3))).isTrue(); NestedSet<Integer> ns = NestedSetBuilder.<Integer>compileOrder() .add(1).add(2).add(3).build(); - assertTrue(CollectionUtils.isImmutable(ns)); + assertThat(CollectionUtils.isImmutable(ns)).isTrue(); NestedSet<Integer> ns2 = NestedSetBuilder.<Integer>linkOrder().add(1).add(2).add(3).build(); - assertTrue(CollectionUtils.isImmutable(ns2)); + assertThat(CollectionUtils.isImmutable(ns2)).isTrue(); IterablesChain<Integer> chain = IterablesChain.<Integer>builder().addElement(1).build(); - assertTrue(CollectionUtils.isImmutable(chain)); + assertThat(CollectionUtils.isImmutable(chain)).isTrue(); - assertFalse(CollectionUtils.isImmutable(Lists.newArrayList())); - assertFalse(CollectionUtils.isImmutable(Lists.newLinkedList())); - assertFalse(CollectionUtils.isImmutable(Sets.newHashSet())); - assertFalse(CollectionUtils.isImmutable(Sets.newLinkedHashSet())); + assertThat(CollectionUtils.isImmutable(Lists.newArrayList())).isFalse(); + assertThat(CollectionUtils.isImmutable(Lists.newLinkedList())).isFalse(); + assertThat(CollectionUtils.isImmutable(Sets.newHashSet())).isFalse(); + assertThat(CollectionUtils.isImmutable(Sets.newLinkedHashSet())).isFalse(); // The result of Iterables.concat() actually is immutable, but we have no way of checking if // a given Iterable comes from concat(). - assertFalse(CollectionUtils.isImmutable(Iterables.concat(ns, ns2))); + assertThat(CollectionUtils.isImmutable(Iterables.concat(ns, ns2))).isFalse(); // We can override the check by using the ImmutableIterable wrapper. - assertTrue(CollectionUtils.isImmutable( - ImmutableIterable.from(Iterables.concat(ns, ns2)))); + assertThat(CollectionUtils.isImmutable(ImmutableIterable.from(Iterables.concat(ns, ns2)))) + .isTrue(); } @Test @@ -105,12 +98,12 @@ public class CollectionUtilsTest { @Test public void testMakeImmutable() throws Exception { Iterable<Integer> immutableList = ImmutableList.of(1, 2, 3); - assertSame(immutableList, CollectionUtils.makeImmutable(immutableList)); + assertThat(CollectionUtils.makeImmutable(immutableList)).isSameAs(immutableList); Iterable<Integer> mutableList = Lists.newArrayList(1, 2, 3); Iterable<Integer> converted = CollectionUtils.makeImmutable(mutableList); - assertNotSame(mutableList, converted); - assertEquals(mutableList, ImmutableList.copyOf(converted)); + assertThat(converted).isNotSameAs(mutableList); + assertThat(ImmutableList.copyOf(converted)).isEqualTo(mutableList); } private static enum Small { ALPHA, BRAVO } @@ -139,7 +132,7 @@ public class CollectionUtilsTest { for (int i = 0; i < maxBits; i++) { EnumSet<T> set = CollectionUtils.fromBits(i, clazz); int back = CollectionUtils.toBits(set); - assertEquals(back, i); // Assert that a roundtrip is idempotent + assertThat(i).isEqualTo(back); // Assert that a roundtrip is idempotent allSets.add(set); } @@ -148,12 +141,12 @@ public class CollectionUtilsTest { @Test public void testEnumBitfields() throws Exception { - assertEquals(0, CollectionUtils.<Small>toBits()); - assertEquals(EnumSet.noneOf(Small.class), CollectionUtils.fromBits(0, Small.class)); - assertEquals(3, CollectionUtils.toBits(Small.ALPHA, Small.BRAVO)); - assertEquals(10, CollectionUtils.toBits(Medium.TWO, Medium.FOUR)); - assertEquals(EnumSet.of(Medium.SEVEN, Medium.EIGHT), - CollectionUtils.fromBits(192, Medium.class)); + assertThat(CollectionUtils.<Small>toBits()).isEqualTo(0); + assertThat(CollectionUtils.fromBits(0, Small.class)).isEqualTo(EnumSet.noneOf(Small.class)); + assertThat(CollectionUtils.toBits(Small.ALPHA, Small.BRAVO)).isEqualTo(3); + assertThat(CollectionUtils.toBits(Medium.TWO, Medium.FOUR)).isEqualTo(10); + assertThat(CollectionUtils.fromBits(192, Medium.class)) + .isEqualTo(EnumSet.of(Medium.SEVEN, Medium.EIGHT)); assertAllDifferent(Small.class); assertAllDifferent(Medium.class); |