@Test public void testNotEquals() { BuildTarget utilTarget = BuildTarget.builder(ROOT, "//src/com/facebook/buck/util", "util").build(); BuildTarget ioTarget = BuildTarget.builder(ROOT, "//src/com/facebook/buck/util", "io").build(); assertFalse(utilTarget.equals(ioTarget)); }
@Test public void testEqualsOtherBuildTarget() { BuildTarget utilTarget1 = BuildTarget.builder(ROOT, "//src/com/facebook/buck/util", "util").build(); assertEquals(utilTarget1, utilTarget1); BuildTarget utilTarget2 = BuildTarget.builder(ROOT, "//src/com/facebook/buck/util", "util").build(); assertEquals(utilTarget1, utilTarget2); }
@Test public void testBuildTargetWithoutFlavor() { BuildTarget target = BuildTarget.builder(ROOT, "//foo/bar", "baz").build(); assertEquals(target.getShortNameAndFlavorPostfix(), "baz"); assertEquals(ImmutableSortedSet.<Flavor>of(), target.getFlavors()); assertFalse(target.isFlavored()); }
@Test public void testBuildTargetWithFlavor() { BuildTarget target = BuildTarget.builder(ROOT, "//foo/bar", "baz").addFlavors(ImmutableFlavor.of("dex")).build(); assertEquals("baz#dex", target.getShortNameAndFlavorPostfix()); assertEquals(ImmutableSortedSet.of(ImmutableFlavor.of("dex")), target.getFlavors()); assertTrue(target.isFlavored()); }
@Test public void testGetUnflavoredTarget() { UnflavoredBuildTarget unflavoredTarget = UnflavoredBuildTarget.builder("//foo/bar", "baz").setCellPath(ROOT).build(); BuildTarget flavoredTarget = BuildTarget.builder(ROOT, "//foo/bar", "baz").addFlavors(ImmutableFlavor.of("biz")).build(); assertEquals(unflavoredTarget, flavoredTarget.getUnflavoredBuildTarget()); }
@Test public void testFlavorIsValid() { try { BuildTarget.builder(ROOT, "//foo/bar", "baz").addFlavors(ImmutableFlavor.of("d!x")).build(); fail("Should have thrown IllegalArgumentException."); } catch (IllegalArgumentException e) { assertEquals("Invalid characters in flavor name: d!x", e.getMessage()); } }
@Test public void testBuildTargetTwoLevelsDeep() { BuildTarget rootTarget = BuildTarget.builder(ROOT, "//java/com/facebook", "fb4a").build(); assertEquals("fb4a", rootTarget.getShortNameAndFlavorPostfix()); assertEquals("//java/com/facebook", rootTarget.getBaseName()); assertEquals("//java/com/facebook/", rootTarget.getBaseNameWithSlash()); assertEquals(Paths.get("java/com/facebook"), rootTarget.getBasePath()); assertEquals("java/com/facebook/", rootTarget.getBasePathWithSlash()); assertEquals("//java/com/facebook:fb4a", rootTarget.getFullyQualifiedName()); assertEquals("//java/com/facebook:fb4a", rootTarget.toString()); }
@Test public void testRootBuildTarget() { BuildTarget rootTarget = BuildTarget.builder(ROOT, "//", "fb4a").build(); assertEquals("fb4a", rootTarget.getShortNameAndFlavorPostfix()); assertEquals("//", rootTarget.getBaseName()); assertEquals("//", rootTarget.getBaseNameWithSlash()); assertEquals(Paths.get(""), rootTarget.getBasePath()); assertEquals("", rootTarget.getBasePathWithSlash()); assertEquals("//:fb4a", rootTarget.getFullyQualifiedName()); assertEquals("//:fb4a", rootTarget.toString()); }
@Test public void testShortNameCannotContainHashWhenFlavorSet() { try { BuildTarget.builder(ROOT, "//foo/bar", "baz#dex") .addFlavors(ImmutableFlavor.of("src-jar")) .build(); fail("Should have thrown IllegalArgumentException."); } catch (IllegalArgumentException e) { assertEquals("Build target name cannot contain '#' but was: baz#dex.", e.getMessage()); } }
@Test public void testEqualsNullReturnsFalse() { BuildTarget utilTarget = BuildTarget.builder(ROOT, "//src/com/facebook/buck/util", "util").build(); assertNotNull(utilTarget); }
@Test public void testNumbersAreValidFlavors() { BuildTarget.builder(ROOT, "//foo", "bar").addFlavors(ImmutableFlavor.of("1234")).build(); }
@Test public void testFlavorDefaultsToNoneIfNotSet() { assertEquals( ImmutableSet.<Flavor>of(), BuildTarget.builder(ROOT, "//foo/bar", "baz").build().getFlavors()); }
@Test(expected = IllegalArgumentException.class) public void testShortNamesMustNotContainTheFlavorSeparator() { BuildTarget.builder(ROOT, "//foo/bar", "baz#dex").build(); }