/** * Creates a matcher that matches if the examined {@link DisplayData.Item} contains a path * matching the specified namespace. */ public static Matcher<DisplayData.Item> hasPath(String... paths) { DisplayData.Path path = (paths.length == 0) ? DisplayData.Path.root() : DisplayData.Path.absolute(paths[0], Arrays.copyOfRange(paths, 1, paths.length)); return new FeatureMatcher<DisplayData.Item, DisplayData.Path>( is(path), " with namespace", "namespace") { @Override protected DisplayData.Path featureValueOf(DisplayData.Item actual) { return actual.getPath(); } }; }
@Test public void testRootPath() { DisplayData.Path root = DisplayData.Path.root(); assertThat(root.getComponents(), empty()); }
/** * Collect the {@link DisplayData} from a component. This will traverse all subcomponents * specified via {@link Builder#include} in the given component. Data in this component will be in * a namespace derived from the component. */ public static DisplayData from(HasDisplayData component) { checkNotNull(component, "component argument cannot be null"); InternalBuilder builder = new InternalBuilder(); builder.include(Path.root(), component); return builder.build(); }
@Test public void testExtendPath() { DisplayData.Path a = DisplayData.Path.root().extend("a"); assertThat(a.getComponents(), hasItems("a")); DisplayData.Path b = a.extend("b"); assertThat(b.getComponents(), hasItems("a", "b")); }
@Test public void testPathToString() { assertEquals("root string", "[]", DisplayData.Path.root().toString()); assertEquals("single component", "[a]", DisplayData.Path.absolute("a").toString()); assertEquals("hierarchy", "[a/b/c]", DisplayData.Path.absolute("a", "b", "c").toString()); }
@Test public void testExtendNullPathValidation() { DisplayData.Path root = DisplayData.Path.root(); thrown.expect(NullPointerException.class); root.extend(null); }
@Test public void testExtendEmptyPathValidation() { DisplayData.Path root = DisplayData.Path.root(); thrown.expect(IllegalArgumentException.class); root.extend(""); }
@Test public void testPathEquality() { new EqualsTester() .addEqualityGroup(DisplayData.Path.root(), DisplayData.Path.root()) .addEqualityGroup(DisplayData.Path.root().extend("a"), DisplayData.Path.absolute("a")) .addEqualityGroup( DisplayData.Path.root().extend("a").extend("b"), DisplayData.Path.absolute("a", "b")) .testEquals(); }