WorkspaceFacade implements Workspace { @SuppressWarnings("WeakerAccess") public static <S extends Session> @Nullable Workspace findBestWrapper(final @Nullable Workspace workspace, final @NotNull SessionFacade<S> sessionFacade) { if (workspace instanceof JackrabbitWorkspace) { return new JackrabbitWorkspaceFacade<>((JackrabbitWorkspace) workspace, sessionFacade); } else if (workspace != null) { return new JcrWorkspaceFacade<>(workspace, sessionFacade); } else { return null; } } @SuppressWarnings("WeakerAccess")  WorkspaceFacade(final @NotNull W delegate, final @NotNull SessionFacade<S> session); @SuppressWarnings("WeakerAccess") static Workspace findBestWrapper(final @Nullable Workspace workspace,
                    final @NotNull SessionFacade<S> sessionFacade); @Override final Session getSession(); @Override final String getName(); @Override final String[] getAccessibleWorkspaceNames(); @Override final LockManager getLockManager(); @Override final QueryManager getQueryManager(); @Override final NamespaceRegistry getNamespaceRegistry(); @Override final NodeTypeManager getNodeTypeManager(); @Override final ObservationManager getObservationManager(); @Override final VersionManager getVersionManager(); @Override final void copy(String srcAbsPath, String destAbsPath); @Override final void copy(String srcWorkspace, String srcAbsPath, String destAbsPath); @Override final void clone(String srcWorkspace, String srcAbsPath, String destAbsPath, boolean removeExisting); @Override final void move(String srcAbsPath, String destAbsPath); @Override final void restore(Version[] versions, boolean removeExisting); @Override final ContentHandler getImportContentHandler(String parentAbsPath, int uuidBehavior); @Override final void importXML(String parentAbsPath, InputStream in, int uuidBehavior); @Override final void createWorkspace(String name); @Override final void createWorkspace(String name, String srcWorkspace); @Override final void deleteWorkspace(String name);  }
@Test public void testFindBestWrapper() { final SessionFacade<Session> jcrSession = new SessionFacade<>(mock(Session.class), false); final Workspace jcrFacade = WorkspaceFacade.findBestWrapper(mock(Workspace.class), jcrSession); assertTrue("should be JcrWorkspaceFacade", jcrFacade instanceof JcrWorkspaceFacade); final SessionFacade<JackrabbitSession> jackSession = new SessionFacade<>(mock(JackrabbitSession.class), false); final Workspace jackFacade = WorkspaceFacade.findBestWrapper(mock(JackrabbitWorkspace.class), jackSession); assertTrue("should be JackrabbitWorkspaceFacade", jackFacade instanceof JackrabbitWorkspaceFacade); assertNull("null should return null", WorkspaceFacade.findBestWrapper(null, jcrSession)); }