Migrate Java tests to Truth.
RELNOTES: None.
PiperOrigin-RevId: 157446717
diff --git a/src/test/java/com/google/devtools/build/lib/util/CommandBuilderTest.java b/src/test/java/com/google/devtools/build/lib/util/CommandBuilderTest.java
index a9e6f15..5e8c001 100644
--- a/src/test/java/com/google/devtools/build/lib/util/CommandBuilderTest.java
+++ b/src/test/java/com/google/devtools/build/lib/util/CommandBuilderTest.java
@@ -17,13 +17,11 @@
import static org.junit.Assert.fail;
import com.google.common.collect.ImmutableList;
-
+import java.util.Arrays;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-import java.util.Arrays;
-
/**
* Tests for the {@link CommandBuilder} class.
*/
@@ -39,8 +37,10 @@
}
private void assertArgv(CommandBuilder builder, String... expected) {
- assertThat(Arrays.asList(builder.build().getCommandLineElements())).containsExactlyElementsIn(
- Arrays.asList(expected)).inOrder();
+ assertThat(builder.build().getCommandLineElements())
+ .asList()
+ .containsExactlyElementsIn(Arrays.asList(expected))
+ .inOrder();
}
private void assertWinCmdArgv(CommandBuilder builder, String expected) {
diff --git a/src/test/java/com/google/devtools/build/lib/util/DependencySetTest.java b/src/test/java/com/google/devtools/build/lib/util/DependencySetTest.java
index ad05901..d8e2b27 100644
--- a/src/test/java/com/google/devtools/build/lib/util/DependencySetTest.java
+++ b/src/test/java/com/google/devtools/build/lib/util/DependencySetTest.java
@@ -23,14 +23,12 @@
import com.google.devtools.build.lib.vfs.FileSystem;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Collection;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class DependencySetTest {
@@ -187,7 +185,7 @@
newDependencySet().read(dotd);
fail();
} catch (IOException e) {
- assertThat(e.getMessage()).contains("File does not end in a newline");
+ assertThat(e).hasMessageThat().contains("File does not end in a newline");
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/util/FileTypeTest.java b/src/test/java/com/google/devtools/build/lib/util/FileTypeTest.java
index 67bdfe2..bb13d18 100644
--- a/src/test/java/com/google/devtools/build/lib/util/FileTypeTest.java
+++ b/src/test/java/com/google/devtools/build/lib/util/FileTypeTest.java
@@ -15,8 +15,6 @@
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.assertTrue;
import com.google.common.base.Joiner;
import com.google.common.base.Predicate;
@@ -26,16 +24,12 @@
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem;
-
+import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-import java.util.List;
-
-/**
- * Test for {@link FileType} and {@link FileTypeSet}.
- */
+/** Test for {@link FileType} and {@link FileTypeSet}. */
@RunWith(JUnit4.class)
public class FileTypeTest {
private static final FileType CFG = FileType.of(".cfg");
@@ -65,48 +59,48 @@
@Test
public void simpleDotMatch() {
- assertTrue(TEXT.matches("readme.txt"));
+ assertThat(TEXT.matches("readme.txt")).isTrue();
}
@Test
public void doubleDotMatches() {
- assertTrue(TEXT.matches("read.me.txt"));
+ assertThat(TEXT.matches("read.me.txt")).isTrue();
}
@Test
public void noExtensionMatches() {
- assertTrue(FileType.NO_EXTENSION.matches("hello"));
- assertTrue(FileType.NO_EXTENSION.matches("/path/to/hello"));
+ assertThat(FileType.NO_EXTENSION.matches("hello")).isTrue();
+ assertThat(FileType.NO_EXTENSION.matches("/path/to/hello")).isTrue();
}
@Test
public void picksLastExtension() {
- assertTrue(TEXT.matches("server.cfg.txt"));
+ assertThat(TEXT.matches("server.cfg.txt")).isTrue();
}
@Test
public void onlyExtensionStillMatches() {
- assertTrue(TEXT.matches(".txt"));
+ assertThat(TEXT.matches(".txt")).isTrue();
}
@Test
public void handlesPathObjects() {
Path readme = new InMemoryFileSystem().getPath("/readme.txt");
- assertTrue(TEXT.matches(readme));
+ assertThat(TEXT.matches(readme)).isTrue();
}
@Test
public void handlesPathFragmentObjects() {
PathFragment readme = PathFragment.create("some/where/readme.txt");
- assertTrue(TEXT.matches(readme));
+ assertThat(TEXT.matches(readme)).isTrue();
}
@Test
public void fileTypeSetContains() {
FileTypeSet allowedTypes = FileTypeSet.of(TEXT, HTML);
- assertTrue(allowedTypes.matches("readme.txt"));
- assertFalse(allowedTypes.matches("style.css"));
+ assertThat(allowedTypes.matches("readme.txt")).isTrue();
+ assertThat(allowedTypes.matches("style.css")).isFalse();
}
private List<HasFilename> getArtifacts() {
@@ -148,8 +142,8 @@
public void checkingSingleWithTypePredicate() throws Exception {
FileType.HasFilename item = filename("config.txt");
- assertTrue(FileType.contains(item, TEXT));
- assertFalse(FileType.contains(item, CFG));
+ assertThat(FileType.contains(item, TEXT)).isTrue();
+ assertThat(FileType.contains(item, CFG)).isFalse();
}
@Test
@@ -159,8 +153,8 @@
filename("index.html"),
filename("README.txt"));
- assertTrue(FileType.contains(unfiltered, TEXT));
- assertFalse(FileType.contains(unfiltered, CFG));
+ assertThat(FileType.contains(unfiltered, TEXT)).isTrue();
+ assertThat(FileType.contains(unfiltered, CFG)).isFalse();
}
@Test
diff --git a/src/test/java/com/google/devtools/build/lib/util/GroupedListTest.java b/src/test/java/com/google/devtools/build/lib/util/GroupedListTest.java
index 8ac5230..a260cc7 100644
--- a/src/test/java/com/google/devtools/build/lib/util/GroupedListTest.java
+++ b/src/test/java/com/google/devtools/build/lib/util/GroupedListTest.java
@@ -14,9 +14,7 @@
package com.google.devtools.build.lib.util;
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.assertTrue;
+import static com.google.common.truth.Truth.assertWithMessage;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
@@ -60,7 +58,7 @@
list.add("test" + i);
}
Object compressedList = createAndCompress(list);
- assertTrue(Iterables.elementsEqual(iterable(compressedList), list));
+ assertThat(Iterables.elementsEqual(iterable(compressedList), list)).isTrue();
assertElementsEqual(compressedList, list);
}
@@ -70,7 +68,7 @@
Object compressedList = createAndCompress(list);
ArrayList<String> reversed = new ArrayList<>(list);
Collections.reverse(reversed);
- assertFalse(elementsEqual(compressedList, reversed));
+ assertThat(elementsEqual(compressedList, reversed)).isFalse();
}
@Test
@@ -86,8 +84,10 @@
for (int i = 0; i < size2; i++) {
secondList.add("test" + i);
}
- assertEquals(GroupedList.create(array) + ", " + secondList + ", " + size1 + ", " + size2,
- size1 == size2, elementsEqual(array, secondList));
+ assertWithMessage(
+ GroupedList.create(array) + ", " + secondList + ", " + size1 + ", " + size2)
+ .that(elementsEqual(array, secondList))
+ .isEqualTo(size1 == size2);
}
}
}
@@ -122,7 +122,7 @@
@Test
public void group() {
GroupedList<String> groupedList = new GroupedList<>();
- assertTrue(groupedList.isEmpty());
+ assertThat(groupedList.isEmpty()).isTrue();
GroupedListHelper<String> helper = new GroupedListHelper<>();
List<ImmutableList<String>> elements = ImmutableList.of(
ImmutableList.of("1"),
@@ -146,8 +146,8 @@
allElts.addAll(group);
}
groupedList.append(helper);
- assertEquals(allElts.size(), groupedList.numElements());
- assertFalse(groupedList.isEmpty());
+ assertThat(groupedList.numElements()).isEqualTo(allElts.size());
+ assertThat(groupedList.isEmpty()).isFalse();
Object compressed = groupedList.compress();
assertElementsEqual(compressed, allElts);
assertElementsEqualInGroups(GroupedList.<String>create(compressed), elements);
@@ -157,7 +157,7 @@
@Test
public void singletonAndEmptyGroups() {
GroupedList<String> groupedList = new GroupedList<>();
- assertTrue(groupedList.isEmpty());
+ assertThat(groupedList.isEmpty()).isTrue();
GroupedListHelper<String> helper = new GroupedListHelper<>();
@SuppressWarnings("unchecked") // varargs
List<ImmutableList<String>> elements = Lists.newArrayList(
@@ -176,8 +176,8 @@
allElts.addAll(group);
}
groupedList.append(helper);
- assertEquals(allElts.size(), groupedList.numElements());
- assertFalse(groupedList.isEmpty());
+ assertThat(groupedList.numElements()).isEqualTo(allElts.size());
+ assertThat(groupedList.isEmpty()).isFalse();
Object compressed = groupedList.compress();
assertElementsEqual(compressed, allElts);
// Get rid of empty list -- it was not stored in groupedList.
@@ -205,7 +205,7 @@
@Test
public void removeMakesEmpty() {
GroupedList<String> groupedList = new GroupedList<>();
- assertTrue(groupedList.isEmpty());
+ assertThat(groupedList.isEmpty()).isTrue();
GroupedListHelper<String> helper = new GroupedListHelper<>();
@SuppressWarnings("unchecked") // varargs
List<List<String>> elements = Lists.newArrayList(
@@ -242,7 +242,7 @@
@Test
public void removeGroupFromSmallList() {
GroupedList<String> groupedList = new GroupedList<>();
- assertTrue(groupedList.isEmpty());
+ assertThat(groupedList.isEmpty()).isTrue();
GroupedListHelper<String> helper = new GroupedListHelper<>();
List<List<String>> elements = new ArrayList<>();
List<String> group = Lists.newArrayList("1a", "1b", "1c", "1d");
diff --git a/src/test/java/com/google/devtools/build/lib/util/LongArrayListTest.java b/src/test/java/com/google/devtools/build/lib/util/LongArrayListTest.java
index c0a3bb4..14befff 100644
--- a/src/test/java/com/google/devtools/build/lib/util/LongArrayListTest.java
+++ b/src/test/java/com/google/devtools/build/lib/util/LongArrayListTest.java
@@ -13,9 +13,7 @@
// limitations under the License.
package com.google.devtools.build.lib.util;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static com.google.common.truth.Truth.assertThat;
import org.junit.Before;
import org.junit.Test;
@@ -41,64 +39,64 @@
list.add(i);
}
for (int i = 0; i < 50; i++) {
- assertEquals(list.get(i), i);
+ assertThat(i).isEqualTo(list.get(i));
}
list.add(25, 42);
- assertEquals(42, list.get(25));
- assertEquals(25, list.get(26));
- assertEquals(49, list.get(list.size() - 1));
- assertEquals(51, list.size());
- assertEquals(23, list.indexOf(23));
- assertEquals(29, list.indexOf(28));
+ assertThat(list.get(25)).isEqualTo(42);
+ assertThat(list.get(26)).isEqualTo(25);
+ assertThat(list.get(list.size() - 1)).isEqualTo(49);
+ assertThat(list.size()).isEqualTo(51);
+ assertThat(list.indexOf(23)).isEqualTo(23);
+ assertThat(list.indexOf(28)).isEqualTo(29);
}
@Test
public void testAddAlls() throws Exception {
list.addAll(new long[] {1, 2, 3, 4, 5}, 1, 3);
- assertEquals(2, list.get(0));
- assertEquals(3, list.get(1));
- assertEquals(4, list.get(2));
- assertEquals(3, list.size());
+ assertThat(list.get(0)).isEqualTo(2);
+ assertThat(list.get(1)).isEqualTo(3);
+ assertThat(list.get(2)).isEqualTo(4);
+ assertThat(list.size()).isEqualTo(3);
list.addAll(new long[] {42, 41}, 0, 2, 1);
- assertEquals(42, list.get(1));
- assertEquals(41, list.get(2));
- assertEquals(3, list.get(3));
- assertEquals(4, list.get(4));
- assertEquals(5, list.size());
+ assertThat(list.get(1)).isEqualTo(42);
+ assertThat(list.get(2)).isEqualTo(41);
+ assertThat(list.get(3)).isEqualTo(3);
+ assertThat(list.get(4)).isEqualTo(4);
+ assertThat(list.size()).isEqualTo(5);
LongArrayList other = new LongArrayList(new long[] {5, 6, 7});
list.addAll(other, list.size());
- assertEquals(42, list.get(1));
- assertEquals(4, list.get(4));
- assertEquals(5, list.get(5));
- assertEquals(6, list.get(6));
- assertEquals(7, list.get(7));
- assertEquals(8, list.size());
+ assertThat(list.get(1)).isEqualTo(42);
+ assertThat(list.get(4)).isEqualTo(4);
+ assertThat(list.get(5)).isEqualTo(5);
+ assertThat(list.get(6)).isEqualTo(6);
+ assertThat(list.get(7)).isEqualTo(7);
+ assertThat(list.size()).isEqualTo(8);
list.addAll(new LongArrayList());
- assertEquals(8, list.size());
+ assertThat(list.size()).isEqualTo(8);
list.addAll(new long[] {});
- assertEquals(8, list.size());
+ assertThat(list.size()).isEqualTo(8);
}
@Test
public void testSet() throws Exception {
list.addAll(new long[] {1, 2, 3});
list.set(1, 42);
- assertEquals(42, list.get(1));
- assertEquals(3, list.size());
+ assertThat(list.get(1)).isEqualTo(42);
+ assertThat(list.size()).isEqualTo(3);
}
@Test
public void testSort() throws Exception {
list = new LongArrayList(new long[] {3, 2, 1});
list.sort();
- assertEquals(1, list.get(0));
- assertEquals(2, list.get(1));
- assertEquals(3, list.get(2));
+ assertThat(list.get(0)).isEqualTo(1);
+ assertThat(list.get(1)).isEqualTo(2);
+ assertThat(list.get(2)).isEqualTo(3);
list.addAll(new long[] {-5, -2});
list.sort(2, 5);
- assertEquals(-5, list.get(2));
- assertEquals(-2, list.get(3));
- assertEquals(3, list.get(4));
+ assertThat(list.get(2)).isEqualTo(-5);
+ assertThat(list.get(3)).isEqualTo(-2);
+ assertThat(list.get(4)).isEqualTo(3);
}
@Test
@@ -108,13 +106,13 @@
list.add(i);
}
long removed = list.remove(last);
- assertEquals(last, removed);
- assertEquals(last, list.size());
+ assertThat(removed).isEqualTo(last);
+ assertThat(list.size()).isEqualTo(last);
removed = list.remove(0);
- assertEquals(0, removed);
- assertEquals(1, list.get(0));
- assertEquals(last - 1, list.get(last - 2));
- assertEquals(last - 1, list.size());
+ assertThat(removed).isEqualTo(0);
+ assertThat(list.get(0)).isEqualTo(1);
+ assertThat(list.get(last - 2)).isEqualTo(last - 1);
+ assertThat(list.size()).isEqualTo(last - 1);
}
@Test
@@ -124,17 +122,17 @@
list.add(i);
}
boolean removed = list.remove((long) last);
- assertTrue(removed);
- assertEquals(last, list.size());
- assertEquals(last - 1, list.get(last - 1));
+ assertThat(removed).isTrue();
+ assertThat(list.size()).isEqualTo(last);
+ assertThat(list.get(last - 1)).isEqualTo(last - 1);
removed = list.remove(3L);
- assertTrue(removed);
- assertEquals(0, list.get(0));
- assertEquals(last - 1, list.get(last - 2));
- assertEquals(last - 1, list.size());
+ assertThat(removed).isTrue();
+ assertThat(list.get(0)).isEqualTo(0);
+ assertThat(list.get(last - 2)).isEqualTo(last - 1);
+ assertThat(list.size()).isEqualTo(last - 1);
removed = list.remove(42L);
- assertFalse(removed);
- assertEquals(last - 1, list.size());
+ assertThat(removed).isFalse();
+ assertThat(list.size()).isEqualTo(last - 1);
}
@Test
@@ -144,9 +142,9 @@
list.add(i);
}
list.ensureCapacity(512);
- assertEquals(last + 1, list.size());
- assertEquals(0, list.get(0));
- assertEquals(last, list.get(last));
+ assertThat(list.size()).isEqualTo(last + 1);
+ assertThat(list.get(0)).isEqualTo(0);
+ assertThat(list.get(last)).isEqualTo(last);
}
@Test(expected = IndexOutOfBoundsException.class)
diff --git a/src/test/java/com/google/devtools/build/lib/util/OptionsUtilsTest.java b/src/test/java/com/google/devtools/build/lib/util/OptionsUtilsTest.java
index d1761b8..f7cac8c 100644
--- a/src/test/java/com/google/devtools/build/lib/util/OptionsUtilsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/util/OptionsUtilsTest.java
@@ -13,12 +13,10 @@
// limitations under the License.
package com.google.devtools.build.lib.util;
+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.assertTrue;
import static org.junit.Assert.fail;
-import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.devtools.build.lib.util.OptionsUtils.PathFragmentListConverter;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -77,7 +75,9 @@
OptionsParser parser = OptionsParser.newOptionsParser(IntrospectionExample.class);
parser.parse("--alpha=no", "--gamma=no", "--echo=no");
assertEquals("--alpha=no --gamma=no", OptionsUtils.asShellEscapedString(parser));
- assertEquals(ImmutableList.of("--alpha=no", "--gamma=no"), OptionsUtils.asArgumentList(parser));
+ assertThat(OptionsUtils.asArgumentList(parser))
+ .containsExactly("--alpha=no", "--gamma=no")
+ .inOrder();
}
@Test
@@ -86,7 +86,9 @@
parser.parse(OptionPriority.COMMAND_LINE, null, Arrays.asList("--alpha=no"));
parser.parse(OptionPriority.COMPUTED_DEFAULT, null, Arrays.asList("--beta=no"));
assertEquals("--beta=no --alpha=no", OptionsUtils.asShellEscapedString(parser));
- assertEquals(ImmutableList.of("--beta=no", "--alpha=no"), OptionsUtils.asArgumentList(parser));
+ assertThat(OptionsUtils.asArgumentList(parser))
+ .containsExactly("--beta=no", "--alpha=no")
+ .inOrder();
}
public static class BooleanOpts extends OptionsBase {
@@ -106,14 +108,18 @@
OptionsParser parser = OptionsParser.newOptionsParser(BooleanOpts.class);
parser.parse(OptionPriority.COMMAND_LINE, null, Arrays.asList("--b_one", "--nob_two"));
assertEquals("--b_one --nob_two", OptionsUtils.asShellEscapedString(parser));
- assertEquals(ImmutableList.of("--b_one", "--nob_two"), OptionsUtils.asArgumentList(parser));
+ assertThat(OptionsUtils.asArgumentList(parser))
+ .containsExactly("--b_one", "--nob_two")
+ .inOrder();
parser = OptionsParser.newOptionsParser(BooleanOpts.class);
parser.parse(OptionPriority.COMMAND_LINE, null, Arrays.asList("--b_one=true", "--b_two=0"));
- assertTrue(parser.getOptions(BooleanOpts.class).bOne);
- assertFalse(parser.getOptions(BooleanOpts.class).bTwo);
+ assertThat(parser.getOptions(BooleanOpts.class).bOne).isTrue();
+ assertThat(parser.getOptions(BooleanOpts.class).bTwo).isFalse();
assertEquals("--b_one --nob_two", OptionsUtils.asShellEscapedString(parser));
- assertEquals(ImmutableList.of("--b_one", "--nob_two"), OptionsUtils.asArgumentList(parser));
+ assertThat(OptionsUtils.asArgumentList(parser))
+ .containsExactly("--b_one", "--nob_two")
+ .inOrder();
}
@Test
@@ -122,8 +128,9 @@
parser.parse(OptionPriority.COMMAND_LINE, null, Arrays.asList("--alpha=one"));
parser.parse(OptionPriority.COMMAND_LINE, null, Arrays.asList("--alpha=two"));
assertEquals("--alpha=one --alpha=two", OptionsUtils.asShellEscapedString(parser));
- assertEquals(
- ImmutableList.of("--alpha=one", "--alpha=two"), OptionsUtils.asArgumentList(parser));
+ assertThat(OptionsUtils.asArgumentList(parser))
+ .containsExactly("--alpha=one", "--alpha=two")
+ .inOrder();
}
private static List<PathFragment> list(PathFragment... fragments) {
diff --git a/src/test/java/com/google/devtools/build/lib/util/PairTest.java b/src/test/java/com/google/devtools/build/lib/util/PairTest.java
index 98bebbc..2dd9c80 100644
--- a/src/test/java/com/google/devtools/build/lib/util/PairTest.java
+++ b/src/test/java/com/google/devtools/build/lib/util/PairTest.java
@@ -13,9 +13,8 @@
// limitations under the License.
package com.google.devtools.build.lib.util;
+import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -32,17 +31,17 @@
Object a = new Object();
Object b = new Object();
Pair<Object, Object> p = Pair.of(a, b);
- assertSame(a, p.first);
- assertSame(b, p.second);
+ assertThat(p.first).isSameAs(a);
+ assertThat(p.second).isSameAs(b);
assertEquals(Pair.of(a, b), p);
- assertEquals(31 * a.hashCode() + b.hashCode(), p.hashCode());
+ assertThat(p.hashCode()).isEqualTo(31 * a.hashCode() + b.hashCode());
}
@Test
public void nullable() {
Pair<Object, Object> p = Pair.of(null, null);
- assertNull(p.first);
- assertNull(p.second);
+ assertThat(p.first).isNull();
+ assertThat(p.second).isNull();
p.hashCode(); // Should not throw.
assertEquals(p, p);
}
diff --git a/src/test/java/com/google/devtools/build/lib/util/PathFragmentFilterTest.java b/src/test/java/com/google/devtools/build/lib/util/PathFragmentFilterTest.java
index 3f25414..2d51434 100644
--- a/src/test/java/com/google/devtools/build/lib/util/PathFragmentFilterTest.java
+++ b/src/test/java/com/google/devtools/build/lib/util/PathFragmentFilterTest.java
@@ -13,12 +13,10 @@
// limitations under the License.
package com.google.devtools.build.lib.util;
+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.assertTrue;
import com.google.devtools.build.lib.vfs.PathFragment;
-
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -35,11 +33,11 @@
}
protected void assertIncluded(String path) {
- assertTrue(filter.isIncluded(PathFragment.create(path)));
+ assertThat(filter.isIncluded(PathFragment.create(path))).isTrue();
}
protected void assertExcluded(String path) {
- assertFalse(filter.isIncluded(PathFragment.create(path)));
+ assertThat(filter.isIncluded(PathFragment.create(path))).isFalse();
}
@Test
diff --git a/src/test/java/com/google/devtools/build/lib/util/PersistentMapTest.java b/src/test/java/com/google/devtools/build/lib/util/PersistentMapTest.java
index 473f855..8a95366 100644
--- a/src/test/java/com/google/devtools/build/lib/util/PersistentMapTest.java
+++ b/src/test/java/com/google/devtools/build/lib/util/PersistentMapTest.java
@@ -14,9 +14,6 @@
package com.google.devtools.build.lib.util;
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.assertTrue;
import com.google.devtools.build.lib.testutil.Scratch;
import com.google.devtools.build.lib.vfs.Path;
@@ -100,7 +97,7 @@
assertThat(map).containsEntry("baz", "bang");
assertThat(map).hasSize(2);
long size = map.save();
- assertEquals(mapFile.getFileSize(), size);
+ assertThat(size).isEqualTo(mapFile.getFileSize());
assertThat(map).containsEntry("foo", "bar");
assertThat(map).containsEntry("baz", "bang");
assertThat(map).hasSize(2);
@@ -117,11 +114,11 @@
map.put("foo", "bar");
map.put("baz", "bang");
long size = map.save();
- assertEquals(mapFile.getFileSize(), size);
- assertFalse(journalFile.exists());
+ assertThat(size).isEqualTo(mapFile.getFileSize());
+ assertThat(journalFile.exists()).isFalse();
map.remove("foo");
assertThat(map).hasSize(1);
- assertTrue(journalFile.exists());
+ assertThat(journalFile.exists()).isTrue();
createMap(); // create a new map
assertThat(map).hasSize(1);
}
@@ -132,12 +129,12 @@
map.put("foo", "bar");
map.put("baz", "bang");
map.save();
- assertTrue(mapFile.exists());
- assertFalse(journalFile.exists());
+ assertThat(mapFile.exists()).isTrue();
+ assertThat(journalFile.exists()).isFalse();
map.clear();
assertThat(map).isEmpty();
- assertTrue(mapFile.exists());
- assertFalse(journalFile.exists());
+ assertThat(mapFile.exists()).isTrue();
+ assertThat(journalFile.exists()).isFalse();
createMap(); // create a new map
assertThat(map).isEmpty();
}
@@ -148,14 +145,14 @@
map.put("foo", "bar");
map.put("baz", "bang");
map.save();
- assertFalse(journalFile.exists());
+ assertThat(journalFile.exists()).isFalse();
// prevent updating the journal
map.updateJournal = false;
// remove an entry
map.remove("foo");
assertThat(map).hasSize(1);
// no journal file written
- assertFalse(journalFile.exists());
+ assertThat(journalFile.exists()).isFalse();
createMap(); // create a new map
// both entries are still in the map on disk
assertThat(map).hasSize(2);
@@ -167,7 +164,7 @@
map.put("foo", "bar");
map.put("baz", "bang");
map.save();
- assertFalse(journalFile.exists());
+ assertThat(journalFile.exists()).isFalse();
// Keep the journal through the save.
map.updateJournal = false;
@@ -177,17 +174,17 @@
map.remove("foo");
assertThat(map).hasSize(1);
// no journal file written
- assertFalse(journalFile.exists());
+ assertThat(journalFile.exists()).isFalse();
long size = map.save();
assertThat(map).hasSize(1);
// The journal must be serialzed on save(), even if !updateJournal.
- assertTrue(journalFile.exists());
- assertEquals(journalFile.getFileSize() + mapFile.getFileSize(), size);
+ assertThat(journalFile.exists()).isTrue();
+ assertThat(size).isEqualTo(journalFile.getFileSize() + mapFile.getFileSize());
map.load();
assertThat(map).hasSize(1);
- assertTrue(journalFile.exists());
+ assertThat(journalFile.exists()).isTrue();
createMap(); // create a new map
assertThat(map).hasSize(1);
@@ -195,7 +192,7 @@
map.keepJournal = false;
map.save();
assertThat(map).hasSize(1);
- assertFalse(journalFile.exists());
+ assertThat(journalFile.exists()).isFalse();
}
@Test
@@ -211,11 +208,11 @@
map.save();
map.remove("baz");
map.save();
- assertThat(map).hasSize(0);
+ assertThat(map).isEmpty();
// Ensure recreating the map loads the correct state.
createMap();
- assertThat(map).hasSize(0);
- assertFalse(journalFile.exists());
+ assertThat(map).isEmpty();
+ assertThat(journalFile.exists()).isFalse();
}
@Test
@@ -223,12 +220,12 @@
createMap();
map.put("foo", "bar");
map.save();
- assertFalse(journalFile.exists());
+ assertThat(journalFile.exists()).isFalse();
// add an entry
map.put("baz", "bang");
assertThat(map).hasSize(2);
// journal file written
- assertTrue(journalFile.exists());
+ assertThat(journalFile.exists()).isTrue();
createMap(); // create a new map
// both entries are still in the map on disk
assertThat(map).hasSize(2);
@@ -236,7 +233,7 @@
map.put("baz2", "bang2");
assertThat(map).hasSize(3);
// journal file written
- assertTrue(journalFile.exists());
+ assertThat(journalFile.exists()).isTrue();
createMap(); // create a new map
// all three entries are still in the map on disk
assertThat(map).hasSize(3);
diff --git a/src/test/java/com/google/devtools/build/lib/util/RegexFilterTest.java b/src/test/java/com/google/devtools/build/lib/util/RegexFilterTest.java
index 7f732fd..503d065 100644
--- a/src/test/java/com/google/devtools/build/lib/util/RegexFilterTest.java
+++ b/src/test/java/com/google/devtools/build/lib/util/RegexFilterTest.java
@@ -15,13 +15,10 @@
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.assertTrue;
import static org.junit.Assert.fail;
import com.google.common.testing.EqualsTester;
import com.google.devtools.common.options.OptionsParsingException;
-
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -39,11 +36,11 @@
}
protected void assertIncluded(String value) {
- assertTrue(filter.isIncluded(value));
+ assertThat(filter.isIncluded(value)).isTrue();
}
protected void assertExcluded(String value) {
- assertFalse(filter.isIncluded(value));
+ assertThat(filter.isIncluded(value)).isFalse();
}
@Test
@@ -120,9 +117,11 @@
createFilter("*a");
fail(); // OptionsParsingException should be thrown.
} catch (OptionsParsingException e) {
- assertThat(e.getMessage())
- .contains("Failed to build valid regular expression: Dangling meta character '*' "
- + "near index");
+ assertThat(e)
+ .hasMessageThat()
+ .contains(
+ "Failed to build valid regular expression: Dangling meta character '*' "
+ + "near index");
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/util/StringCanonicalizerTest.java b/src/test/java/com/google/devtools/build/lib/util/StringCanonicalizerTest.java
index d25f2f4..2874b6d 100644
--- a/src/test/java/com/google/devtools/build/lib/util/StringCanonicalizerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/util/StringCanonicalizerTest.java
@@ -14,7 +14,6 @@
package com.google.devtools.build.lib.util;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertSame;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -37,6 +36,6 @@
public void twoSameStringsAreCanonicalized() {
String stringA1 = StringCanonicalizer.intern(new String("A"));
String stringA2 = StringCanonicalizer.intern(new String("A"));
- assertSame(stringA1, stringA2);
+ assertThat(stringA2).isSameAs(stringA1);
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/util/StringIndexerTest.java b/src/test/java/com/google/devtools/build/lib/util/StringIndexerTest.java
index 409b8f2..9aeb907 100644
--- a/src/test/java/com/google/devtools/build/lib/util/StringIndexerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/util/StringIndexerTest.java
@@ -15,22 +15,12 @@
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.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
import com.google.common.base.Function;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.devtools.build.lib.testutil.TestUtils;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
import java.util.List;
import java.util.SortedMap;
import java.util.concurrent.ArrayBlockingQueue;
@@ -38,6 +28,10 @@
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
/**
* Test for the StringIndexer classes.
@@ -58,26 +52,26 @@
protected abstract StringIndexer newIndexer();
protected void assertSize(int expected) {
- assertEquals(expected, indexer.size());
+ assertThat(indexer.size()).isEqualTo(expected);
}
protected void assertNoIndex(String s) {
int size = indexer.size();
- assertEquals(-1, indexer.getIndex(s));
- assertEquals(size, indexer.size());
+ assertThat(indexer.getIndex(s)).isEqualTo(-1);
+ assertThat(indexer.size()).isEqualTo(size);
}
protected void assertIndex(int expected, String s) {
// System.out.println("Adding " + s + ", expecting " + expected);
int index = indexer.getOrCreateIndex(s);
// System.out.println(csi);
- assertEquals(expected, index);
+ assertThat(index).isEqualTo(expected);
mappings.put(expected, s);
}
protected void assertContent() {
for (int i = 0; i < indexer.size(); i++) {
- assertNotNull(mappings.get(i));
+ assertThat(mappings.get(i)).isNotNull();
assertThat(mappings).containsEntry(i, indexer.getStringForIndex(i));
}
}
@@ -108,8 +102,8 @@
int index = safeIndex.get();
// Retrieve string using random existing index and validate reverse mapping.
String key = indexer.getStringForIndex(index);
- assertNotNull(key);
- assertEquals(index, indexer.getIndex(key));
+ assertThat(key).isNotNull();
+ assertThat(indexer.getIndex(key)).isEqualTo(index);
}
}
} finally {
@@ -176,8 +170,8 @@
assertContent();
indexer.clear();
assertSize(0);
- assertNull(indexer.getStringForIndex(0));
- assertNull(indexer.getStringForIndex(1000));
+ assertThat(indexer.getStringForIndex(0)).isNull();
+ assertThat(indexer.getStringForIndex(1000)).isNull();
}
@Test
@@ -241,10 +235,10 @@
@Test
public void addStringResult() {
assertSize(0);
- assertTrue(indexer.addString("abcdef"));
- assertTrue(indexer.addString("abcdgh"));
- assertFalse(indexer.addString("abcd"));
- assertTrue(indexer.addString("ab"));
+ assertThat(indexer.addString("abcdef")).isTrue();
+ assertThat(indexer.addString("abcdgh")).isTrue();
+ assertThat(indexer.addString("abcd")).isFalse();
+ assertThat(indexer.addString("ab")).isTrue();
}
}
@@ -279,18 +273,18 @@
assertContent();
indexer.clear();
assertSize(0);
- assertNull(indexer.getStringForIndex(0));
- assertNull(indexer.getStringForIndex(1000));
+ assertThat(indexer.getStringForIndex(0)).isNull();
+ assertThat(indexer.getStringForIndex(1000)).isNull();
}
@Test
public void addStringResult() {
assertSize(0);
- assertTrue(indexer.addString("abcdef"));
- assertTrue(indexer.addString("abcdgh"));
- assertTrue(indexer.addString("abcd"));
- assertTrue(indexer.addString("ab"));
- assertFalse(indexer.addString("ab"));
+ assertThat(indexer.addString("abcdef")).isTrue();
+ assertThat(indexer.addString("abcdgh")).isTrue();
+ assertThat(indexer.addString("abcd")).isTrue();
+ assertThat(indexer.addString("ab")).isTrue();
+ assertThat(indexer.addString("ab")).isFalse();
}
protected void setupTestContent() {
diff --git a/src/test/java/com/google/devtools/build/lib/util/StringTrieTest.java b/src/test/java/com/google/devtools/build/lib/util/StringTrieTest.java
index 8c8e03d..5f2faf1 100644
--- a/src/test/java/com/google/devtools/build/lib/util/StringTrieTest.java
+++ b/src/test/java/com/google/devtools/build/lib/util/StringTrieTest.java
@@ -13,8 +13,7 @@
// limitations under the License.
package com.google.devtools.build.lib.util;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import static com.google.common.truth.Truth.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -28,9 +27,9 @@
@Test
public void empty() {
StringTrie<Integer> cut = new StringTrie<>();
- assertNull(cut.get(""));
- assertNull(cut.get("a"));
- assertNull(cut.get("ab"));
+ assertThat(cut.get("")).isNull();
+ assertThat(cut.get("a")).isNull();
+ assertThat(cut.get("ab")).isNull();
}
@Test
@@ -39,32 +38,32 @@
cut.put("a", 1);
cut.put("b", 2);
- assertNull(cut.get(""));
- assertEquals(1, cut.get("a").intValue());
- assertEquals(1, cut.get("ab").intValue());
- assertEquals(1, cut.get("abc").intValue());
+ assertThat(cut.get("")).isNull();
+ assertThat(cut.get("a").intValue()).isEqualTo(1);
+ assertThat(cut.get("ab").intValue()).isEqualTo(1);
+ assertThat(cut.get("abc").intValue()).isEqualTo(1);
- assertEquals(2, cut.get("b").intValue());
+ assertThat(cut.get("b").intValue()).isEqualTo(2);
}
@Test
public void ancestors() {
StringTrie<Integer> cut = new StringTrie<>();
cut.put("abc", 3);
- assertNull(cut.get(""));
- assertNull(cut.get("a"));
- assertNull(cut.get("ab"));
- assertEquals(3, cut.get("abc").intValue());
- assertEquals(3, cut.get("abcd").intValue());
+ assertThat(cut.get("")).isNull();
+ assertThat(cut.get("a")).isNull();
+ assertThat(cut.get("ab")).isNull();
+ assertThat(cut.get("abc").intValue()).isEqualTo(3);
+ assertThat(cut.get("abcd").intValue()).isEqualTo(3);
cut.put("a", 1);
- assertEquals(1, cut.get("a").intValue());
- assertEquals(1, cut.get("ab").intValue());
- assertEquals(3, cut.get("abc").intValue());
+ assertThat(cut.get("a").intValue()).isEqualTo(1);
+ assertThat(cut.get("ab").intValue()).isEqualTo(1);
+ assertThat(cut.get("abc").intValue()).isEqualTo(3);
cut.put("", 0);
- assertEquals(0, cut.get("").intValue());
- assertEquals(0, cut.get("b").intValue());
- assertEquals(1, cut.get("a").intValue());
+ assertThat(cut.get("").intValue()).isEqualTo(0);
+ assertThat(cut.get("b").intValue()).isEqualTo(0);
+ assertThat(cut.get("a").intValue()).isEqualTo(1);
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/util/StringUtilTest.java b/src/test/java/com/google/devtools/build/lib/util/StringUtilTest.java
index b7ec9b8..5331931 100644
--- a/src/test/java/com/google/devtools/build/lib/util/StringUtilTest.java
+++ b/src/test/java/com/google/devtools/build/lib/util/StringUtilTest.java
@@ -20,22 +20,16 @@
import static com.google.devtools.build.lib.util.StringUtil.splitAndInternString;
import static com.google.devtools.build.lib.util.StringUtil.stripSuffix;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
import com.google.common.collect.ImmutableList;
-
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * A test for {@link StringUtil}.
- */
+/** A test for {@link StringUtil}. */
@RunWith(JUnit4.class)
public class StringUtilTest {
@@ -66,9 +60,9 @@
assertThat(list1).containsExactly("x", "y", "z", "z").inOrder();
assertThat(list2).containsExactly("a", "z", "c", "z").inOrder();
- assertSame(list1.get(2), list1.get(3));
- assertSame(list1.get(2), list2.get(1));
- assertSame(list2.get(1), list2.get(3));
+ assertThat(list1.get(3)).isSameAs(list1.get(2));
+ assertThat(list2.get(1)).isSameAs(list1.get(2));
+ assertThat(list2.get(3)).isSameAs(list2.get(1));
}
@Test
@@ -95,10 +89,10 @@
@Test
public void testStripSuffix() throws Exception {
assertThat(stripSuffix("", "")).isEmpty();
- assertNull(stripSuffix("", "a"));
+ assertThat(stripSuffix("", "a")).isNull();
assertEquals("a", stripSuffix("a", ""));
assertEquals("a", stripSuffix("aa", "a"));
- assertNull(stripSuffix("ab", "c"));
+ assertThat(stripSuffix("ab", "c")).isNull();
}
@Test
diff --git a/src/test/java/com/google/devtools/build/lib/util/StringUtilitiesTest.java b/src/test/java/com/google/devtools/build/lib/util/StringUtilitiesTest.java
index 4b4a554..c6ed9bf 100644
--- a/src/test/java/com/google/devtools/build/lib/util/StringUtilitiesTest.java
+++ b/src/test/java/com/google/devtools/build/lib/util/StringUtilitiesTest.java
@@ -19,23 +19,17 @@
import static com.google.devtools.build.lib.util.StringUtilities.layoutTable;
import static com.google.devtools.build.lib.util.StringUtilities.prettyPrintBytes;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import com.google.common.collect.Maps;
-
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * A test for {@link StringUtilities}.
- */
+/** A test for {@link StringUtilities}. */
@RunWith(JUnit4.class)
public class StringUtilitiesTest {
@@ -172,17 +166,23 @@
@Test
public void containsSubarray() {
- assertTrue(StringUtilities.containsSubarray("abcde".toCharArray(), "ab".toCharArray()));
- assertTrue(StringUtilities.containsSubarray("abcde".toCharArray(), "de".toCharArray()));
- assertTrue(StringUtilities.containsSubarray("abcde".toCharArray(), "bc".toCharArray()));
- assertTrue(StringUtilities.containsSubarray("abcde".toCharArray(), "".toCharArray()));
+ assertThat(StringUtilities.containsSubarray("abcde".toCharArray(), "ab".toCharArray()))
+ .isTrue();
+ assertThat(StringUtilities.containsSubarray("abcde".toCharArray(), "de".toCharArray()))
+ .isTrue();
+ assertThat(StringUtilities.containsSubarray("abcde".toCharArray(), "bc".toCharArray()))
+ .isTrue();
+ assertThat(StringUtilities.containsSubarray("abcde".toCharArray(), "".toCharArray())).isTrue();
}
@Test
public void notContainsSubarray() {
- assertFalse(StringUtilities.containsSubarray("abc".toCharArray(), "abcd".toCharArray()));
- assertFalse(StringUtilities.containsSubarray("abc".toCharArray(), "def".toCharArray()));
- assertFalse(StringUtilities.containsSubarray("abcde".toCharArray(), "bd".toCharArray()));
+ assertThat(StringUtilities.containsSubarray("abc".toCharArray(), "abcd".toCharArray()))
+ .isFalse();
+ assertThat(StringUtilities.containsSubarray("abc".toCharArray(), "def".toCharArray()))
+ .isFalse();
+ assertThat(StringUtilities.containsSubarray("abcde".toCharArray(), "bd".toCharArray()))
+ .isFalse();
}
@Test
diff --git a/src/test/java/com/google/devtools/build/lib/util/io/AnsiTerminalPrinterTest.java b/src/test/java/com/google/devtools/build/lib/util/io/AnsiTerminalPrinterTest.java
index d6423c6..886737a 100644
--- a/src/test/java/com/google/devtools/build/lib/util/io/AnsiTerminalPrinterTest.java
+++ b/src/test/java/com/google/devtools/build/lib/util/io/AnsiTerminalPrinterTest.java
@@ -15,7 +15,6 @@
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import com.google.devtools.build.lib.testutil.MoreAsserts;
import com.google.devtools.build.lib.util.io.AnsiTerminalPrinter.Mode;
@@ -82,11 +81,11 @@
assertThat(codes[i]).isNotEmpty();
assertEquals(codes[i], codes[i+4]);
}
- assertFalse(codes[0].equals(codes[1]));
- assertFalse(codes[0].equals(codes[2]));
- assertFalse(codes[0].equals(codes[3]));
- assertFalse(codes[1].equals(codes[2]));
- assertFalse(codes[1].equals(codes[3]));
- assertFalse(codes[2].equals(codes[3]));
+ assertThat(codes[0].equals(codes[1])).isFalse();
+ assertThat(codes[0].equals(codes[2])).isFalse();
+ assertThat(codes[0].equals(codes[3])).isFalse();
+ assertThat(codes[1].equals(codes[2])).isFalse();
+ assertThat(codes[1].equals(codes[3])).isFalse();
+ assertThat(codes[2].equals(codes[3])).isFalse();
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/util/io/OutErrTest.java b/src/test/java/com/google/devtools/build/lib/util/io/OutErrTest.java
index d3c0ace..0afcb31 100644
--- a/src/test/java/com/google/devtools/build/lib/util/io/OutErrTest.java
+++ b/src/test/java/com/google/devtools/build/lib/util/io/OutErrTest.java
@@ -13,18 +13,15 @@
// limitations under the License.
package com.google.devtools.build.lib.util.io;
+import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
+import java.io.ByteArrayOutputStream;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-import java.io.ByteArrayOutputStream;
-
-/**
- * Tests {@link OutErr}.
- */
+/** Tests {@link OutErr}. */
@RunWith(JUnit4.class)
public class OutErrTest {
@@ -34,8 +31,8 @@
@Test
public void testRetainsOutErr() {
- assertSame(out, outErr.getOutputStream());
- assertSame(err, outErr.getErrorStream());
+ assertThat(outErr.getOutputStream()).isSameAs(out);
+ assertThat(outErr.getErrorStream()).isSameAs(err);
}
@Test
diff --git a/src/test/java/com/google/devtools/build/lib/util/io/PositionAwareAnsiTerminalWriterTest.java b/src/test/java/com/google/devtools/build/lib/util/io/PositionAwareAnsiTerminalWriterTest.java
index ec1c809..2aef6ff 100644
--- a/src/test/java/com/google/devtools/build/lib/util/io/PositionAwareAnsiTerminalWriterTest.java
+++ b/src/test/java/com/google/devtools/build/lib/util/io/PositionAwareAnsiTerminalWriterTest.java
@@ -13,17 +13,15 @@
// limitations under the License.
package com.google.devtools.build.lib.util.io;
+import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
+import java.io.IOException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-import java.io.IOException;
-
-/**
- * Tests {@link PositionAwareAnsiTerminalWriter}.
- */
+/** Tests {@link PositionAwareAnsiTerminalWriter}. */
@RunWith(JUnit4.class)
public class PositionAwareAnsiTerminalWriterTest {
static final String NL = LoggingTerminalWriter.NEWLINE;
@@ -40,7 +38,7 @@
terminalWriter.append(sample);
- assertEquals(sample.length(), terminalWriter.getPosition());
+ assertThat(terminalWriter.getPosition()).isEqualTo(sample.length());
assertEquals(sample, loggingTerminalWriter.getTranscript());
}
@@ -54,13 +52,13 @@
new PositionAwareAnsiTerminalWriter(loggingTerminalWriter);
terminalWriter.append(firstLine);
- assertEquals(firstLine.length(), terminalWriter.getPosition());
+ assertThat(terminalWriter.getPosition()).isEqualTo(firstLine.length());
terminalWriter.newline();
- assertEquals(0, terminalWriter.getPosition());
+ assertThat(terminalWriter.getPosition()).isEqualTo(0);
terminalWriter.append(secondLine);
- assertEquals(secondLine.length(), terminalWriter.getPosition());
+ assertThat(terminalWriter.getPosition()).isEqualTo(secondLine.length());
terminalWriter.newline();
- assertEquals(0, terminalWriter.getPosition());
+ assertThat(terminalWriter.getPosition()).isEqualTo(0);
assertEquals(firstLine + NL + secondLine + NL, loggingTerminalWriter.getTranscript());
}
@@ -74,9 +72,9 @@
new PositionAwareAnsiTerminalWriter(loggingTerminalWriter);
terminalWriter.append(firstLine + "\n" + secondLine);
- assertEquals(secondLine.length(), terminalWriter.getPosition());
+ assertThat(terminalWriter.getPosition()).isEqualTo(secondLine.length());
terminalWriter.append("\n");
- assertEquals(0, terminalWriter.getPosition());
+ assertThat(terminalWriter.getPosition()).isEqualTo(0);
assertEquals(firstLine + NL + secondLine + NL, loggingTerminalWriter.getTranscript());
}
@@ -108,9 +106,9 @@
new PositionAwareAnsiTerminalWriter(loggingTerminalWriter);
terminalWriter.failStatus();
- assertEquals(0, terminalWriter.getPosition());
+ assertThat(terminalWriter.getPosition()).isEqualTo(0);
terminalWriter.append(sample);
- assertEquals(sample.length(), terminalWriter.getPosition());
+ assertThat(terminalWriter.getPosition()).isEqualTo(sample.length());
assertEquals(FAIL + sample, loggingTerminalWriter.getTranscript());
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/util/io/RecordingOutErrTest.java b/src/test/java/com/google/devtools/build/lib/util/io/RecordingOutErrTest.java
index 54309ac..435ffb5 100644
--- a/src/test/java/com/google/devtools/build/lib/util/io/RecordingOutErrTest.java
+++ b/src/test/java/com/google/devtools/build/lib/util/io/RecordingOutErrTest.java
@@ -13,9 +13,8 @@
// limitations under the License.
package com.google.devtools.build.lib.util.io;
+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.assertTrue;
import java.io.PrintWriter;
import org.junit.Test;
@@ -51,13 +50,13 @@
assertEquals("Testout1\nTestout2\n", outErr.outAsLatin1());
assertEquals("Testerr1\nTesterr2\n", outErr.errAsLatin1());
- assertTrue(outErr.hasRecordedOutput());
+ assertThat(outErr.hasRecordedOutput()).isTrue();
outErr.reset();
- assertEquals("", outErr.outAsLatin1());
- assertEquals("", outErr.errAsLatin1());
- assertFalse(outErr.hasRecordedOutput());
+ assertThat(outErr.outAsLatin1()).isEmpty();
+ assertThat(outErr.errAsLatin1()).isEmpty();
+ assertThat(outErr.hasRecordedOutput()).isFalse();
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/util/io/StreamDemultiplexerTest.java b/src/test/java/com/google/devtools/build/lib/util/io/StreamDemultiplexerTest.java
index 786eb6c..ba06bb8 100644
--- a/src/test/java/com/google/devtools/build/lib/util/io/StreamDemultiplexerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/util/io/StreamDemultiplexerTest.java
@@ -13,18 +13,17 @@
// limitations under the License.
package com.google.devtools.build.lib.util.io;
-import static org.junit.Assert.assertArrayEquals;
+import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.Random;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
/**
* Tests {@link StreamDemultiplexer}.
@@ -109,9 +108,9 @@
muxOuts[streamId].write(buffer);
muxOuts[streamId].flush();
}
- assertArrayEquals(expectedOuts[0].toByteArray(), out.toByteArray());
- assertArrayEquals(expectedOuts[1].toByteArray(), err.toByteArray());
- assertArrayEquals(expectedOuts[2].toByteArray(), ctl.toByteArray());
+ assertThat(out.toByteArray()).isEqualTo(expectedOuts[0].toByteArray());
+ assertThat(err.toByteArray()).isEqualTo(expectedOuts[1].toByteArray());
+ assertThat(ctl.toByteArray()).isEqualTo(expectedOuts[2].toByteArray());
}
private static byte[] chunk(int stream, String payload) {
diff --git a/src/test/java/com/google/devtools/build/lib/util/io/StreamMultiplexerTest.java b/src/test/java/com/google/devtools/build/lib/util/io/StreamMultiplexerTest.java
index 6d3f2c3..6fd7e2e 100644
--- a/src/test/java/com/google/devtools/build/lib/util/io/StreamMultiplexerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/util/io/StreamMultiplexerTest.java
@@ -14,21 +14,17 @@
package com.google.devtools.build.lib.util.io;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
import com.google.common.io.ByteStreams;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
/**
* Test for {@link StreamMultiplexer}.
@@ -55,7 +51,7 @@
out.flush();
err.flush();
ctl.flush();
- assertEquals(0, multiplexed.toByteArray().length);
+ assertThat(multiplexed.toByteArray()).isEmpty();
}
private static byte[] getLatin(String string)
@@ -98,13 +94,13 @@
throws Exception {
out.write(getLatin("There are no newline characters in here, so it won't" +
" get written just yet."));
- assertArrayEquals(multiplexed.toByteArray(), new byte[0]);
+ assertThat(new byte[0]).isEqualTo(multiplexed.toByteArray());
}
@Test
public void testNewlineTriggersFlush() throws Exception {
out.write(getLatin("No newline just yet, so no flushing. "));
- assertArrayEquals(multiplexed.toByteArray(), new byte[0]);
+ assertThat(new byte[0]).isEqualTo(multiplexed.toByteArray());
out.write(getLatin("OK, here we go:\nAnd more to come."));
assertMessage(
multiplexed.toByteArray(), 0, "No newline just yet, so no flushing. OK, here we go:\n");
@@ -116,7 +112,7 @@
@Test
public void testFlush() throws Exception {
out.write(getLatin("Don't forget to flush!"));
- assertArrayEquals(new byte[0], multiplexed.toByteArray());
+ assertThat(multiplexed.toByteArray()).isEqualTo(new byte[0]);
out.flush(); // now the output will appear in multiplexed.
assertStartsWith(multiplexed.toByteArray(), 1, 0, 0, 0);
assertMessage(multiplexed.toByteArray(), 0, "Don't forget to flush!");