ItemFacade implements Item { static @Nullable Item unwrap(final @Nullable Item item) { if (item instanceof ItemFacade) { return ((ItemFacade) item).delegate; } else { return item; } } @SuppressWarnings("WeakerAccess")  ItemFacade(final @NotNull J delegate, final @NotNull SessionFacade<S> session); @SuppressWarnings("WeakerAccess") static @NotNull Item ensureBestWrapper(final @NotNull Item primaryItem, final @NotNull SessionFacade<?> session); @Override final String getPath(); @Override final String getName(); @Override final Item getAncestor(int depth); @Override final Node getParent(); @Override final int getDepth(); @Override final Session getSession(); @Override final boolean isNode(); @Override final boolean isNew(); @Override final boolean isModified(); @Override final boolean isSame(Item otherItem); @Override final void accept(ItemVisitor visitor); @Override final void refresh(boolean keepChanges); @Override final void save(); @Override final void remove();  }
@SuppressWarnings("ConstantConditions") @Test public void testUnwrap() throws Exception { assertNull("unwrap null to null", ItemFacade.unwrap(null)); Item justNodeDelegate = mock(Node.class); assertSame("same Item delegate by itself", justNodeDelegate, ItemFacade.unwrap(justNodeDelegate)); Item justNodeFacade = getFacade(justNodeDelegate); assertSame("same Item delegate", justNodeDelegate, ItemFacade.unwrap(justNodeFacade)); Property propertyDelegate = mock(Property.class); Item propertyFacade = getFacade(propertyDelegate); assertSame("same Property delegate", propertyDelegate, ItemFacade.unwrap(propertyFacade)); Node versionDelegate = mock(Version.class); Item versionFacade = getFacade(versionDelegate); assertSame("same Version delegate", versionDelegate, ItemFacade.unwrap(versionFacade)); Node versionHistoryDelegate = mock(VersionHistory.class); Item versionHistoryFacade = getFacade(versionHistoryDelegate); assertSame("same VersionHistory delegate", versionHistoryDelegate, ItemFacade.unwrap(versionHistoryFacade)); }