### Question:
ElementManagerImpl implements ElementManager { @Override public CoreElement save(SessionContext context, ElementContext elementContext, CoreElement element, String message) { validateItemVersionExistence(context, Space.PRIVATE, elementContext.getItemId(), elementContext.getVersionId()); Namespace namespace = element.getAction() == Action.CREATE ? Namespace.ROOT_NAMESPACE : getValidatedNamespace(context, elementContext, element.getId(), ErrorCode.ZU_ELEMENT_SAVE); setElementHierarchyPosition(element, namespace); traverser.traverse(context, elementContext, Space.PRIVATE, element, collaborativeStoreVisitor); traverser.traverse(context, elementContext, Space.PRIVATE, element, indexingVisitor); getCollaborationAdaptor(context).commitElements(context, elementContext, message); getItemVersionManager(context) .updateModificationTime(context, Space.PRIVATE, elementContext.getItemId(), elementContext.getVersionId(), new Date()); return element; }  @Override Collection<CoreElementInfo> list(SessionContext context, ElementContext elementContext,
                                          Id elementId); @Override CoreElementInfo getInfo(SessionContext context, ElementContext elementContext,
                                 Id elementId); @Override CoreElement get(SessionContext context, ElementContext elementContext,
                         Id elementId); @Override CoreElementConflict getConflict(SessionContext context, ElementContext elementContext,
                                         Id elementId); @Override CoreElement save(SessionContext context, ElementContext elementContext,
                          CoreElement element, String message); @Override CoreMergeResult resolveConflict(SessionContext context, ElementContext elementContext,
                                         CoreElement element, Resolution resolution); @Override SearchResult search(SessionContext context, SearchCriteria searchCriteria); @Override void saveMergeChange(SessionContext context, Space space, ElementContext elementContext,
                              Collection<CoreElement> elements);  }### Answer:
@Test public void testSaveWithCreateRoot() throws Exception { CoreElement root = createCoreElement(null, Action.CREATE, null, null, "root", null); SessionContext context = TestUtils.createSessionContext(USER, "test"); ElementContext elementContext = new ElementContext(new Id(), new Id()); CoreElement returnedRoot = elementManager.save(context, elementContext, root, "save create root!"); Assert.assertEquals(returnedRoot.getParentId(), null); Assert.assertEquals(returnedRoot.getNamespace(), Namespace.ROOT_NAMESPACE); verify(traverserMock) .traverse(context, elementContext, Space.PRIVATE, root, collaborativeStoreVisitorMock); verify(traverserMock).traverse(context, elementContext, Space.PRIVATE, root, indexingVisitorMock); }
@Test public void testSaveWithNonCreateRoot() throws Exception { CoreElement root = createCoreElement(new Id(), Action.UPDATE, null, null, "root", null); SessionContext context = TestUtils.createSessionContext(USER, "test"); ElementContext elementContext = new ElementContext(new Id(), new Id()); Id parentElementId = new Id(); Namespace namespace = new Namespace(Namespace.ROOT_NAMESPACE, parentElementId); doReturn(new Response<>(namespace)) .when(stateAdaptorMock).getNamespace(context, elementContext.getItemId(), root.getId()); CoreElement returnedRoot = elementManager.save(context, elementContext, root, "save non-create root!"); Assert.assertEquals(returnedRoot.getId(), root.getId()); Assert.assertEquals(root.getParentId(), parentElementId); Assert.assertEquals(root.getNamespace(), namespace); verify(traverserMock) .traverse(context, elementContext, Space.PRIVATE, root, collaborativeStoreVisitorMock); verify(traverserMock).traverse(context, elementContext, Space.PRIVATE, root, indexingVisitorMock); }