### Question:
BranchedMirrorProjector extends ProjectorWithPlaceholders { static BranchedMirrorProjector with( ExecutionContext context, List<Projection> projections ) { assert projections != null; assert context != null; if (projections.size() != 2) return null; Projection first = projections.get(0); Projection second = projections.get(1); if (first.getRules().size() != 1) return null; if (second.getRules().size() != 1) return null; Rule firstRule = first.getRules().get(0); Rule secondRule = second.getRules().get(0); assert firstRule != null; assert secondRule != null; PathFactory pathFactory = context.getValueFactories().getPathFactory(); List<Path> firstTopLevelPaths = first.getRules().get(0).getTopLevelPathsInRepository(pathFactory); if (firstTopLevelPaths.size() != 1) return null; List<Path> secondTopLevelPaths = second.getRules().get(0).getTopLevelPathsInRepository(pathFactory); if (secondTopLevelPaths.size() != 1) return null; Path firstTopLevelPath = firstTopLevelPaths.get(0); Path secondTopLevelPath = secondTopLevelPaths.get(0); if (firstTopLevelPath.isRoot()) { return new BranchedMirrorProjector(context, projections, first, second, secondTopLevelPath, secondRule.getPathInSource(secondTopLevelPath, pathFactory)); } if (!secondTopLevelPath.isRoot()) return null; return new BranchedMirrorProjector(context, projections, second, first, firstTopLevelPath, firstRule.getPathInSource(firstTopLevelPath, pathFactory)); } BranchedMirrorProjector( ExecutionContext context,
                             List<Projection> projections,
                             Projection mirrorProjection,
                             Projection branchProjection,
                             Path branchFederatedPath,
                             Path branchSourcePath ); ProjectedNode project( ExecutionContext context,
                                  Location location,
                                  boolean requiresUpdate );  }### Answer:
@Test public void shouldAlwaysReturnProxyNodeForLocationInBranchMultipleLevelsDeepWithOneForOneMapping() { projections.clear(); addProjection(mirrorSourceName, mirrorWorkspaceName, "/ => /"); addProjection(branchSourceName, branchWorkspaceName, "/a/b/c => /a/b/c"); this.projector = BranchedMirrorProjector.with(context, projections); assertProjectedIntoBranch("/a/b/c"); assertProjectedIntoBranch("/a/b/c/d"); }
@Test public void shouldAlwaysReturnProxyNodeForLocationInBranchMultipleLevelsDeepWithDissimilarMapping() { projections.clear(); addProjection(mirrorSourceName, mirrorWorkspaceName, "/ => /"); addProjection(branchSourceName, branchWorkspaceName, "/a/b/c => /d/e"); this.projector = BranchedMirrorProjector.with(context, projections); assertProjectedIntoBranch("/a/b/c", "/d/e"); assertProjectedIntoBranch("/a/b/c/f", "/d/e/f"); }
@Test public void shouldAlwaysReturnProxyNodeForLocationInBranchMultipleLevelsDeepWithRootMapping() { projections.clear(); addProjection(mirrorSourceName, mirrorWorkspaceName, "/ => /"); addProjection(branchSourceName, branchWorkspaceName, "/a/b/c => /"); this.projector = BranchedMirrorProjector.with(context, projections); assertProjectedIntoBranch("/a/b/c", "/"); assertProjectedIntoBranch("/a/b/c/f", "/f"); }