Add a few extra tests for XcodeProvider.

--
MOS_MIGRATED_REVID=114431043
diff --git a/src/test/java/com/google/devtools/build/lib/BUILD b/src/test/java/com/google/devtools/build/lib/BUILD
index 83120b6..366fd6b 100644
--- a/src/test/java/com/google/devtools/build/lib/BUILD
+++ b/src/test/java/com/google/devtools/build/lib/BUILD
@@ -965,6 +965,7 @@
     test_class = "com.google.devtools.build.lib.rules.objc.XcodeProviderTest",
     deps = [
         "//src/main/java/com/google/devtools/build/lib:cmdline",
+        "//src/main/java/com/google/devtools/build/lib:vfs",
         "//src/main/java/com/google/devtools/build/lib/rules/objc",
         "//third_party:junit4",
         "//third_party:truth",
diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/XcodeProviderTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/XcodeProviderTest.java
index 551e35d..e858598 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/objc/XcodeProviderTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/objc/XcodeProviderTest.java
@@ -16,8 +16,12 @@
 
 import static com.google.common.truth.Truth.assertThat;
 import static com.google.devtools.build.lib.rules.objc.XcodeProvider.xcodeTargetName;
+import static org.junit.Assert.fail;
 
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
 import com.google.devtools.build.lib.cmdline.Label;
+import com.google.devtools.build.lib.vfs.PathFragment;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -25,6 +29,9 @@
 
 /**
  * Tests for XcodeProvider.
+ *
+ * <p>We test {@code rootEach} individually. Because it is used as test utility code, any wrong
+ * behavior may go undetected otherwise.
  */
 @RunWith(JUnit4.class)
 public class XcodeProviderTest {
@@ -39,4 +46,37 @@
     assertThat(xcodeTargetName(Label.parseAbsolute("@repo_name//foo:bar")))
         .isEqualTo("bar_external_repo_name_foo");
   }
+
+  private static Iterable<PathFragment> fragments(String... paths) {
+    return Iterables.transform(ImmutableList.copyOf(paths), PathFragment.TO_PATH_FRAGMENT);
+  }
+
+  @Test
+  public void testRootEach_nonEmptySequence() {
+    assertThat(XcodeProvider.rootEach("$(prefix)", fragments("a", "b/c")))
+        .containsExactly("$(prefix)/a", "$(prefix)/b/c")
+        .inOrder();
+  }
+
+  @Test
+  public void testRootEach_emptyFragment() {
+    assertThat(XcodeProvider.rootEach("$(foo)", fragments("", "bar", ".")))
+        .containsExactly("$(foo)", "$(foo)/bar", "$(foo)")
+        .inOrder();
+  }
+
+  @Test
+  public void testRootEach_noElements() {
+    assertThat(XcodeProvider.rootEach("$(prefix)", fragments()))
+        .isEmpty();
+  }
+
+  @Test
+  public void testRootEach_errorForTrailingSlash() {
+    try {
+      XcodeProvider.rootEach("$(prefix)/", fragments("a"));
+      fail("should have thrown");
+    } catch (IllegalArgumentException expected) {
+    }
+  }
 }