Migrate Java tests to Truth.
RELNOTES: None.

PiperOrigin-RevId: 157446717
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java
index 2be126b..2b91668 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java
@@ -15,10 +15,6 @@
 package com.google.devtools.build.lib.skylark;
 
 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.assertSame;
-import static org.junit.Assert.assertTrue;
 
 import com.google.common.base.Joiner;
 import com.google.common.collect.ImmutableList;
@@ -109,8 +105,9 @@
           + "There is already a built-in attribute 'tags' which cannot be overridden"
           + "' but got no error");
     } catch (AssertionError e) {
-      assertThat(e.getMessage()).contains(
-          "There is already a built-in attribute 'tags' which cannot be overridden");
+      assertThat(e)
+          .hasMessageThat()
+          .contains("There is already a built-in attribute 'tags' which cannot be overridden");
     }
   }
 
@@ -124,8 +121,9 @@
           + "There is already a built-in attribute 'name' which cannot be overridden"
           + "' but got no error");
     } catch (AssertionError e) {
-      assertThat(e.getMessage()).contains(
-          "There is already a built-in attribute 'name' which cannot be overridden");
+      assertThat(e)
+          .hasMessageThat()
+          .contains("There is already a built-in attribute 'name' which cannot be overridden");
     }
   }
 
@@ -137,8 +135,8 @@
         "  pass",
         "exec_rule = rule(implementation = _impl, executable = True)",
         "non_exec_rule = rule(implementation = _impl)");
-    assertTrue(getRuleClass("exec_rule").hasAttr("args", Type.STRING_LIST));
-    assertFalse(getRuleClass("non_exec_rule").hasAttr("args", Type.STRING_LIST));
+    assertThat(getRuleClass("exec_rule").hasAttr("args", Type.STRING_LIST)).isTrue();
+    assertThat(getRuleClass("non_exec_rule").hasAttr("args", Type.STRING_LIST)).isFalse();
   }
 
   private RuleClass getRuleClass(String name) throws Exception {
@@ -152,7 +150,7 @@
   @Test
   public void testAttrWithOnlyType() throws Exception {
     Attribute attr = buildAttribute("a1", "attr.string_list()");
-    assertEquals(Type.STRING_LIST, attr.getType());
+    assertThat(attr.getType()).isEqualTo(Type.STRING_LIST);
   }
 
   private Attribute buildAttribute(String name, String... lines) throws Exception {
@@ -166,37 +164,37 @@
   @Test
   public void testOutputListAttr() throws Exception {
     Attribute attr = buildAttribute("a1", "attr.output_list()");
-    assertEquals(BuildType.OUTPUT_LIST, attr.getType());
+    assertThat(attr.getType()).isEqualTo(BuildType.OUTPUT_LIST);
   }
 
   @Test
   public void testIntListAttr() throws Exception {
     Attribute attr = buildAttribute("a1", "attr.int_list()");
-    assertEquals(Type.INTEGER_LIST, attr.getType());
+    assertThat(attr.getType()).isEqualTo(Type.INTEGER_LIST);
   }
 
   @Test
   public void testOutputAttr() throws Exception {
     Attribute attr = buildAttribute("a1", "attr.output()");
-    assertEquals(BuildType.OUTPUT, attr.getType());
+    assertThat(attr.getType()).isEqualTo(BuildType.OUTPUT);
   }
 
   @Test
   public void testStringDictAttr() throws Exception {
     Attribute attr = buildAttribute("a1", "attr.string_dict(default = {'a': 'b'})");
-    assertEquals(Type.STRING_DICT, attr.getType());
+    assertThat(attr.getType()).isEqualTo(Type.STRING_DICT);
   }
 
   @Test
   public void testStringListDictAttr() throws Exception {
     Attribute attr = buildAttribute("a1", "attr.string_list_dict(default = {'a': ['b', 'c']})");
-    assertEquals(Type.STRING_LIST_DICT, attr.getType());
+    assertThat(attr.getType()).isEqualTo(Type.STRING_LIST_DICT);
   }
 
   @Test
   public void testAttrAllowedFileTypesAnyFile() throws Exception {
     Attribute attr = buildAttribute("a1", "attr.label_list(allow_files = True)");
-    assertEquals(FileTypeSet.ANY_FILE, attr.getAllowedFileTypesPredicate());
+    assertThat(attr.getAllowedFileTypesPredicate()).isEqualTo(FileTypeSet.ANY_FILE);
   }
 
   @Test
@@ -216,24 +214,24 @@
   @Test
   public void testAttrWithList() throws Exception {
     Attribute attr = buildAttribute("a1", "attr.label_list(allow_files = ['.xml'])");
-    assertTrue(attr.getAllowedFileTypesPredicate().apply("a.xml"));
-    assertFalse(attr.getAllowedFileTypesPredicate().apply("a.txt"));
-    assertFalse(attr.isSingleArtifact());
+    assertThat(attr.getAllowedFileTypesPredicate().apply("a.xml")).isTrue();
+    assertThat(attr.getAllowedFileTypesPredicate().apply("a.txt")).isFalse();
+    assertThat(attr.isSingleArtifact()).isFalse();
   }
 
   @Test
   public void testAttrSingleFileWithList() throws Exception {
     Attribute attr = buildAttribute("a1", "attr.label(allow_single_file = ['.xml'])");
-    assertTrue(attr.getAllowedFileTypesPredicate().apply("a.xml"));
-    assertFalse(attr.getAllowedFileTypesPredicate().apply("a.txt"));
-    assertTrue(attr.isSingleArtifact());
+    assertThat(attr.getAllowedFileTypesPredicate().apply("a.xml")).isTrue();
+    assertThat(attr.getAllowedFileTypesPredicate().apply("a.txt")).isFalse();
+    assertThat(attr.isSingleArtifact()).isTrue();
   }
 
   @Test
   public void testAttrWithSkylarkFileType() throws Exception {
     Attribute attr = buildAttribute("a1", "attr.label_list(allow_files = FileType(['.xml']))");
-    assertTrue(attr.getAllowedFileTypesPredicate().apply("a.xml"));
-    assertFalse(attr.getAllowedFileTypesPredicate().apply("a.txt"));
+    assertThat(attr.getAllowedFileTypesPredicate().apply("a.xml")).isTrue();
+    assertThat(attr.getAllowedFileTypesPredicate().apply("a.txt")).isFalse();
   }
 
   private static SkylarkProviderIdentifier legacy(String legacyId) {
@@ -435,13 +433,13 @@
   public void testAttrAllowedRuleClassesSpecificRuleClasses() throws Exception {
     Attribute attr = buildAttribute("a",
         "attr.label_list(allow_rules = ['java_binary'], allow_files = True)");
-    assertTrue(attr.getAllowedRuleClassesPredicate().apply(ruleClass("java_binary")));
-    assertFalse(attr.getAllowedRuleClassesPredicate().apply(ruleClass("genrule")));
+    assertThat(attr.getAllowedRuleClassesPredicate().apply(ruleClass("java_binary"))).isTrue();
+    assertThat(attr.getAllowedRuleClassesPredicate().apply(ruleClass("genrule"))).isFalse();
   }
   @Test
   public void testAttrDefaultValue() throws Exception {
     Attribute attr = buildAttribute("a1", "attr.string(default = 'some value')");
-    assertEquals("some value", attr.getDefaultValueForTesting());
+    assertThat(attr.getDefaultValueForTesting()).isEqualTo("some value");
   }
 
   @Test
@@ -456,22 +454,22 @@
   @Test
   public void testAttrMandatory() throws Exception {
     Attribute attr = buildAttribute("a1", "attr.string(mandatory=True)");
-    assertTrue(attr.isMandatory());
-    assertFalse(attr.isNonEmpty());
+    assertThat(attr.isMandatory()).isTrue();
+    assertThat(attr.isNonEmpty()).isFalse();
   }
 
   @Test
   public void testAttrNonEmpty() throws Exception {
     Attribute attr = buildAttribute("a1", "attr.string_list(non_empty=True)");
-    assertTrue(attr.isNonEmpty());
-    assertFalse(attr.isMandatory());
+    assertThat(attr.isNonEmpty()).isTrue();
+    assertThat(attr.isMandatory()).isFalse();
   }
 
   @Test
   public void testAttrAllowEmpty() throws Exception {
     Attribute attr = buildAttribute("a1", "attr.string_list(allow_empty=False)");
-    assertTrue(attr.isNonEmpty());
-    assertFalse(attr.isMandatory());
+    assertThat(attr.isNonEmpty()).isTrue();
+    assertThat(attr.isMandatory()).isFalse();
   }
 
   @Test
@@ -483,19 +481,19 @@
   @Test
   public void testAttrCfg() throws Exception {
     Attribute attr = buildAttribute("a1", "attr.label(cfg = 'host', allow_files = True)");
-    assertEquals(ConfigurationTransition.HOST, attr.getConfigurationTransition());
+    assertThat(attr.getConfigurationTransition()).isEqualTo(ConfigurationTransition.HOST);
   }
 
   @Test
   public void testAttrCfgData() throws Exception {
     Attribute attr = buildAttribute("a1", "attr.label(cfg = 'data', allow_files = True)");
-    assertEquals(ConfigurationTransition.DATA, attr.getConfigurationTransition());
+    assertThat(attr.getConfigurationTransition()).isEqualTo(ConfigurationTransition.DATA);
   }
 
   @Test
   public void testAttrCfgTarget() throws Exception {
     Attribute attr = buildAttribute("a1", "attr.label(cfg = 'target', allow_files = True)");
-    assertEquals(ConfigurationTransition.NONE, attr.getConfigurationTransition());
+    assertThat(attr.getConfigurationTransition()).isEqualTo(ConfigurationTransition.NONE);
   }
 
   @Test
@@ -518,7 +516,7 @@
   public void testRuleImplementation() throws Exception {
     evalAndExport("def impl(ctx): return None", "rule1 = rule(impl)");
     RuleClass c = ((RuleFunction) lookup("rule1")).getRuleClass();
-    assertEquals("impl", c.getConfiguredTargetFunction().getName());
+    assertThat(c.getConfiguredTargetFunction().getName()).isEqualTo("impl");
   }
 
   @Test
@@ -537,7 +535,7 @@
   public void testRuleAddAttribute() throws Exception {
     evalAndExport("def impl(ctx): return None", "r1 = rule(impl, attrs={'a1': attr.string()})");
     RuleClass c = ((RuleFunction) lookup("r1")).getRuleClass();
-    assertTrue(c.hasAttr("a1", Type.STRING));
+    assertThat(c.hasAttr("a1", Type.STRING)).isTrue();
   }
 
   protected void evalAndExport(String... lines) throws Exception {
@@ -577,7 +575,7 @@
   public void testOutputToGenfiles() throws Exception {
     evalAndExport("def impl(ctx): pass", "r1 = rule(impl, output_to_genfiles=True)");
     RuleClass c = ((RuleFunction) lookup("r1")).getRuleClass();
-    assertFalse(c.hasBinaryOutput());
+    assertThat(c.hasBinaryOutput()).isFalse();
   }
 
   @Test
@@ -590,8 +588,8 @@
         "            'a2': attr.int()",
         "})");
     RuleClass c = ((RuleFunction) lookup("r1")).getRuleClass();
-    assertTrue(c.hasAttr("a1", BuildType.LABEL_LIST));
-    assertTrue(c.hasAttr("a2", Type.INTEGER));
+    assertThat(c.hasAttr("a1", BuildType.LABEL_LIST)).isTrue();
+    assertThat(c.hasAttr("a2", Type.INTEGER)).isTrue();
   }
   @Test
   public void testRuleAttributeFlag() throws Exception {
@@ -599,7 +597,7 @@
         "def impl(ctx): return None",
         "r1 = rule(impl, attrs = {'a1': attr.string(mandatory=True)})");
     RuleClass c = ((RuleFunction) lookup("r1")).getRuleClass();
-    assertTrue(c.getAttributeByName("a1").isMandatory());
+    assertThat(c.getAttributeByName("a1").isMandatory()).isTrue();
   }
 
   @Test
@@ -609,7 +607,7 @@
         "r1 = rule(impl, outputs = {'a': 'a.txt'})");
     RuleClass c = ((RuleFunction) lookup("r1")).getRuleClass();
     ImplicitOutputsFunction function = c.getDefaultImplicitOutputsFunction();
-    assertEquals("a.txt", Iterables.getOnlyElement(function.getImplicitOutputs(null)));
+    assertThat(function.getImplicitOutputs(null)).containsExactly("a.txt");
   }
 
   @Test
@@ -649,7 +647,7 @@
   public void testLabel() throws Exception {
     Object result = evalRuleClassCode("Label('//foo/foo:foo')");
     assertThat(result).isInstanceOf(Label.class);
-    assertEquals("//foo/foo:foo", result.toString());
+    assertThat(result.toString()).isEqualTo("//foo/foo:foo");
   }
 
   @Test
@@ -657,16 +655,16 @@
     Object l1 = evalRuleClassCode("Label('//foo/foo:foo')");
     // Implicitly creates a new pkgContext and environment, yet labels should be the same.
     Object l2 = evalRuleClassCode("Label('//foo/foo:foo')");
-    assertSame(l2, l1);
+    assertThat(l1).isSameAs(l2);
   }
 
   @Test
   public void testLabelNameAndPackage() throws Exception {
     Object result = evalRuleClassCode("Label('//foo/bar:baz').name");
-    assertEquals("baz", result);
+    assertThat(result).isEqualTo("baz");
     // NB: implicitly creates a new pkgContext and environments, yet labels should be the same.
     result = evalRuleClassCode("Label('//foo/bar:baz').package");
-    assertEquals("foo/bar", result);
+    assertThat(result).isEqualTo("foo/bar");
   }
 
   @Test
@@ -678,7 +676,7 @@
     RuleClass c = ((RuleFunction) lookup("r1")).getRuleClass();
     Attribute a = c.getAttributeByName("a1");
     assertThat(a.getDefaultValueForTesting()).isInstanceOf(Label.class);
-    assertEquals("//foo:foo", a.getDefaultValueForTesting().toString());
+    assertThat(a.getDefaultValueForTesting().toString()).isEqualTo("//foo:foo");
   }
 
   @Test
@@ -688,29 +686,30 @@
         "r1 = rule(impl, attrs = {'a1': attr.int(default = 40+2)})");
     RuleClass c = ((RuleFunction) lookup("r1")).getRuleClass();
     Attribute a = c.getAttributeByName("a1");
-    assertEquals(42, a.getDefaultValueForTesting());
+    assertThat(a.getDefaultValueForTesting()).isEqualTo(42);
   }
 
   @Test
   public void testFileType() throws Exception {
     Object result = evalRuleClassCode("FileType(['.css'])");
     SkylarkFileType fts = (SkylarkFileType) result;
-    assertEquals(ImmutableList.of(".css"), fts.getExtensions());
+    assertThat(fts.getExtensions()).isEqualTo(ImmutableList.of(".css"));
   }
 
   @Test
   public void testRuleInheritsBaseRuleAttributes() throws Exception {
     evalAndExport("def impl(ctx): return None", "r1 = rule(impl)");
     RuleClass c = ((RuleFunction) lookup("r1")).getRuleClass();
-    assertTrue(c.hasAttr("tags", Type.STRING_LIST));
-    assertTrue(c.hasAttr("visibility", BuildType.NODEP_LABEL_LIST));
-    assertTrue(c.hasAttr("deprecation", Type.STRING));
-    assertTrue(c.hasAttr(":action_listener", BuildType.LABEL_LIST)); // required for extra actions
+    assertThat(c.hasAttr("tags", Type.STRING_LIST)).isTrue();
+    assertThat(c.hasAttr("visibility", BuildType.NODEP_LABEL_LIST)).isTrue();
+    assertThat(c.hasAttr("deprecation", Type.STRING)).isTrue();
+    assertThat(c.hasAttr(":action_listener", BuildType.LABEL_LIST))
+        .isTrue(); // required for extra actions
   }
 
   private void checkTextMessage(String from, String... lines) throws Exception {
     Object result = evalRuleClassCode(from);
-    assertEquals(Joiner.on("\n").join(lines) + "\n", result);
+    assertThat(result).isEqualTo(Joiner.on("\n").join(lines) + "\n");
   }
 
   @Test
@@ -771,7 +770,7 @@
 
   private void checkJson(String from, String expected) throws Exception {
     Object result = evalRuleClassCode(from);
-    assertEquals(expected, result);
+    assertThat(result).isEqualTo(expected);
   }
 
   @Test
@@ -826,8 +825,8 @@
 
   @Test
   public void testLabelGetRelative() throws Exception {
-    assertEquals("//foo:baz", eval("Label('//foo:bar').relative('baz')").toString());
-    assertEquals("//baz:qux", eval("Label('//foo:bar').relative('//baz:qux')").toString());
+    assertThat(eval("Label('//foo:bar').relative('baz')").toString()).isEqualTo("//foo:baz");
+    assertThat(eval("Label('//foo:bar').relative('//baz:qux')").toString()).isEqualTo("//baz:qux");
   }
 
   @Test
@@ -872,28 +871,28 @@
     // TODO(fwe): cannot be handled by current testing suite
     eval("x = struct(a = 1, b = 2)");
     ClassObject x = (ClassObject) lookup("x");
-    assertEquals(1, x.getValue("a"));
-    assertEquals(2, x.getValue("b"));
+    assertThat(x.getValue("a")).isEqualTo(1);
+    assertThat(x.getValue("b")).isEqualTo(2);
   }
 
   @Test
   public void testStructEquality() throws Exception {
-    assertTrue((Boolean) eval("struct(a = 1, b = 2) == struct(b = 2, a = 1)"));
-    assertFalse((Boolean) eval("struct(a = 1) == struct(a = 1, b = 2)"));
-    assertFalse((Boolean) eval("struct(a = 1, b = 2) == struct(a = 1)"));
+    assertThat((Boolean) eval("struct(a = 1, b = 2) == struct(b = 2, a = 1)")).isTrue();
+    assertThat((Boolean) eval("struct(a = 1) == struct(a = 1, b = 2)")).isFalse();
+    assertThat((Boolean) eval("struct(a = 1, b = 2) == struct(a = 1)")).isFalse();
     // Compare a recursive object to itself to make sure reference equality is checked
-    assertTrue((Boolean) eval("s = (struct(a = 1, b = [])); s.b.append(s); s == s"));
-    assertFalse((Boolean) eval("struct(a = 1, b = 2) == struct(a = 1, b = 3)"));
-    assertFalse((Boolean) eval("struct(a = 1) == [1]"));
-    assertFalse((Boolean) eval("[1] == struct(a = 1)"));
-    assertTrue((Boolean) eval("struct() == struct()"));
-    assertFalse((Boolean) eval("struct() == struct(a = 1)"));
+    assertThat((Boolean) eval("s = (struct(a = 1, b = [])); s.b.append(s); s == s")).isTrue();
+    assertThat((Boolean) eval("struct(a = 1, b = 2) == struct(a = 1, b = 3)")).isFalse();
+    assertThat((Boolean) eval("struct(a = 1) == [1]")).isFalse();
+    assertThat((Boolean) eval("[1] == struct(a = 1)")).isFalse();
+    assertThat((Boolean) eval("struct() == struct()")).isTrue();
+    assertThat((Boolean) eval("struct() == struct(a = 1)")).isFalse();
 
     eval("foo = provider(); bar = provider()");
-    assertFalse((Boolean) eval("struct(a = 1) == foo(a = 1)"));
-    assertFalse((Boolean) eval("foo(a = 1) == struct(a = 1)"));
-    assertFalse((Boolean) eval("foo(a = 1) == bar(a = 1)"));
-    assertTrue((Boolean) eval("foo(a = 1) == foo(a = 1)"));
+    assertThat((Boolean) eval("struct(a = 1) == foo(a = 1)")).isFalse();
+    assertThat((Boolean) eval("foo(a = 1) == struct(a = 1)")).isFalse();
+    assertThat((Boolean) eval("foo(a = 1) == bar(a = 1)")).isFalse();
+    assertThat((Boolean) eval("foo(a = 1) == foo(a = 1)")).isTrue();
   }
 
   @Test
@@ -950,7 +949,7 @@
         "y = struct(c = 1, d = 2)",
         "z = x + y\n");
     SkylarkClassObject z = (SkylarkClassObject) lookup("z");
-    assertEquals(ImmutableSet.of("a", "b", "c", "d"), z.getKeys());
+    assertThat(z.getKeys()).isEqualTo(ImmutableSet.of("a", "b", "c", "d"));
   }
 
   @Test
@@ -960,10 +959,10 @@
         "y = struct(c = 1, d = 2)",
         "z = x + y\n");
     SkylarkClassObject z = (SkylarkClassObject) lookup("z");
-    assertEquals(1, z.getValue("a"));
-    assertEquals(2, z.getValue("b"));
-    assertEquals(1, z.getValue("c"));
-    assertEquals(2, z.getValue("d"));
+    assertThat(z.getValue("a")).isEqualTo(1);
+    assertThat(z.getValue("b")).isEqualTo(2);
+    assertThat(z.getValue("c")).isEqualTo(1);
+    assertThat(z.getValue("d")).isEqualTo(2);
   }
 
   @Test
@@ -982,10 +981,10 @@
         "  return x",
         "x = func()");
     SkylarkClassObject x = (SkylarkClassObject) lookup("x");
-    assertEquals(1, x.getValue("a"));
-    assertEquals(2, x.getValue("b"));
-    assertEquals(1, x.getValue("c"));
-    assertEquals(2, x.getValue("d"));
+    assertThat(x.getValue("a")).isEqualTo(1);
+    assertThat(x.getValue("b")).isEqualTo(2);
+    assertThat(x.getValue("c")).isEqualTo(1);
+    assertThat(x.getValue("d")).isEqualTo(2);
   }
 
   @Test
@@ -1093,7 +1092,7 @@
 
   @Test
   public void testStructMutabilityShallow() throws Exception {
-    assertTrue(EvalUtils.isImmutable(makeStruct("a", 1)));
+    assertThat(EvalUtils.isImmutable(makeStruct("a", 1))).isTrue();
   }
 
   private static MutableList<Object> makeList(Environment env) {
@@ -1102,13 +1101,13 @@
 
   @Test
   public void testStructMutabilityDeep() throws Exception {
-    assertTrue(EvalUtils.isImmutable(Tuple.<Object>of(makeList(null))));
-    assertTrue(EvalUtils.isImmutable(makeStruct("a", makeList(null))));
-    assertTrue(EvalUtils.isImmutable(makeBigStruct(null)));
+    assertThat(EvalUtils.isImmutable(Tuple.<Object>of(makeList(null)))).isTrue();
+    assertThat(EvalUtils.isImmutable(makeStruct("a", makeList(null)))).isTrue();
+    assertThat(EvalUtils.isImmutable(makeBigStruct(null))).isTrue();
 
-    assertFalse(EvalUtils.isImmutable(Tuple.<Object>of(makeList(ev.getEnvironment()))));
-    assertFalse(EvalUtils.isImmutable(makeStruct("a", makeList(ev.getEnvironment()))));
-    assertFalse(EvalUtils.isImmutable(makeBigStruct(ev.getEnvironment())));
+    assertThat(EvalUtils.isImmutable(Tuple.<Object>of(makeList(ev.getEnvironment())))).isFalse();
+    assertThat(EvalUtils.isImmutable(makeStruct("a", makeList(ev.getEnvironment())))).isFalse();
+    assertThat(EvalUtils.isImmutable(makeBigStruct(ev.getEnvironment()))).isFalse();
   }
 
   @Test
@@ -1374,8 +1373,9 @@
       createRuleContext("//third_party/foo:main");
       Assert.fail();
     } catch (AssertionError e) {
-      assertThat(e.getMessage()).contains("cfg parameter is mandatory when executable=True is "
-          + "provided.");
+      assertThat(e)
+          .hasMessageThat()
+          .contains("cfg parameter is mandatory when executable=True is " + "provided.");
     }
   }