TreeUtil { public static List<Tree> getEffectiveType(Tree tree, Tree typeRoot) { List<Tree> types = newArrayList(); String primary = getName(tree, JCR_PRIMARYTYPE); if (primary != null) { Tree type = typeRoot.getChild(primary); if (type.exists()) { types.add(type); } } for (String mixin : getNames(tree, JCR_MIXINTYPES)) { Tree type = typeRoot.getChild(mixin); if (type.exists()) { types.add(type); } } return types; } private  TreeUtil(); @Nullable static String getPrimaryTypeName(@NotNull Tree tree); @Nullable static String getPrimaryTypeName(@NotNull Tree tree, @NotNull LazyValue<Tree> readOnlyTree); @NotNull static Iterable<String> getMixinTypeNames(@NotNull Tree tree); @NotNull static Iterable<String> getMixinTypeNames(@NotNull Tree tree, @NotNull LazyValue<Tree> readOnlyTree); @Nullable static Iterable<String> getStrings(@NotNull Tree tree, @NotNull String propertyName); @Nullable static String getString(@NotNull Tree tree, @NotNull String propertyName); @Nullable static String getString(@NotNull Tree tree, @NotNull String name, @Nullable String defaultValue); static boolean getBoolean(@NotNull Tree tree, @NotNull String propertyName); @Nullable static String getName(@NotNull Tree tree, @NotNull String name); @NotNull static Iterable<String> getNames(@NotNull Tree tree, @NotNull String name); static long getLong(@NotNull Tree tree, @NotNull String name, long defaultValue); @Nullable static Tree getTree(@NotNull Tree tree, @NotNull String path); static Tree addChild(
            @NotNull Tree parent, @NotNull String name,
            @Nullable String typeName, @NotNull Tree typeRoot,
            @Nullable String userID); @NotNull static Tree addChild(@NotNull Tree tree, @NotNull String childName, @NotNull String primaryTypeName); @NotNull static Tree getOrAddChild(@NotNull Tree tree, @NotNull String childName, @NotNull String primaryTypeName); static void addMixin(@NotNull Tree tree, @NotNull String mixinName, @NotNull Tree typeRoot, @Nullable String userID); static void autoCreateItems(@NotNull Tree tree, @NotNull Tree type, @NotNull Tree typeRoot, @Nullable String userID); static PropertyState autoCreateProperty(@NotNull String name,
                                                   @NotNull Tree definition,
                                                   @Nullable String userID); static String getDefaultChildType(
            Tree typeRoot, Tree parent, String childName); static List<Tree> getEffectiveType(Tree tree, Tree typeRoot); static String findDefaultPrimaryType(Tree definitions, boolean sns); static boolean isNodeType(Tree tree, String typeName, Tree typeRoot); static boolean isReadOnlyTree(@NotNull Tree tree);  }
@Test public void testGetEffectiveTypeNoPrimary() { assertTrue(TreeUtil.getEffectiveType(rootTree.getChild("x"), typeRoot).isEmpty()); }
@Test public void testGetEffectiveTypeNoMixins() { assertEquals(ImmutableList.of(ntDef), TreeUtil.getEffectiveType(z, typeRoot)); }
@Test public void testGetEffectiveType() { assertEquals(ImmutableList.of(ntDef, ntDef, ntDef), TreeUtil.getEffectiveType(child, typeRoot)); }
@Test public void testGetEffectiveTypeNonExistingPrimaryDef() { assertEquals(ImmutableList.of(), TreeUtil.getEffectiveType(mockTree("/anotherTree", rootTree, false, "rep:NonExistingType"), typeRoot)); }
@Test public void testGetEffectiveTypeNonExistingMixinDef() { Tree tree = mockTree("/anotherTree", rootTree, false); when(tree.getProperty(JCR_MIXINTYPES)).thenReturn(PropertyStates.createProperty(JCR_MIXINTYPES, ImmutableList.of("rep:NonExistingType"), Type.NAMES)); assertEquals(ImmutableList.of(), TreeUtil.getEffectiveType(tree, typeRoot)); }