MergingLog { public MergingLog(@NonNull File outputFolder) { mOutputFolder = outputFolder; } MergingLog(@NonNull File outputFolder); void logCopy(@NonNull SourceFile source, @NonNull SourceFile destination); void logCopy(@NonNull File source, @NonNull File destination); void logRemove(@NonNull SourceFile merged); void logSource(
            @NonNull SourceFile mergedFile,
            @NonNull Map<SourcePosition, SourceFilePosition> map); @NonNull SourceFile find(@NonNull SourceFile mergedFile); @NonNull SourceFilePosition find(@NonNull final SourceFilePosition mergedFilePosition); void write(); @NonNull SourceFile destinationFor(@NonNull SourceFile original);  }
@Test public void testMergingLog() throws IOException { final SourceFilePosition position1 = new SourceFilePosition( new SourceFile(absoluteFile("exploded/a/values/values.xml")), new SourcePosition(7, 8, 20)); final SourceFilePosition position2 = new SourceFilePosition( new SourceFile(absoluteFile("exploded/b/values/values.xml")), new SourcePosition(2, 3, 14)); File tempDir = mTemporaryFolder.newFolder(); MergingLog mergingLog = new MergingLog(tempDir); mergingLog.logCopy(absoluteFile("exploded/layout/a"), absoluteFile("merged/layout/a")); mergingLog.logCopy(absoluteFile("exploded/layout-land/a"), absoluteFile("merged/layout-land/a")); Map<SourcePosition, SourceFilePosition> map = Maps.newLinkedHashMap(); map.put(new SourcePosition(1, 2, 3, 7, 1, 120), position1); map.put(new SourcePosition(4, 1, 34, 6, 20, 100), position2); mergingLog.logSource(new SourceFile(absoluteFile("merged/values/values.xml")), map); Map<SourcePosition, SourceFilePosition> map2 = Maps.newLinkedHashMap(); map2.put( new SourcePosition(3, 4, 34), new SourceFilePosition( new SourceFile(absoluteFile("exploded/values-de/values.xml")), new SourcePosition(0, 5, 5))); mergingLog.logSource(new SourceFile(absoluteFile("merged/values-de/values.xml")), map2); mergingLog.write(); mergingLog = new MergingLog(tempDir); mergingLog.logRemove(new SourceFile(absoluteFile("merged/layout/a"))); mergingLog.write(); mergingLog = new MergingLog(tempDir); Assert.assertEquals("", new SourceFile(absoluteFile("exploded/layout-land/a")), mergingLog.find(new SourceFile(absoluteFile("merged/layout-land/a")))); Assert.assertEquals("", position2, mergingLog.find(new SourceFilePosition( new SourceFile(absoluteFile("merged/values/values.xml")), new SourcePosition(4, 1, 35, 4, 2, 36)))); Assert.assertEquals("", position1, mergingLog.find(new SourceFilePosition( new SourceFile(absoluteFile("merged/values/values.xml")), new SourcePosition(5, 20, 35, 6, 25, 105)))); SourceFilePosition noMatch1 = new SourceFilePosition( new SourceFile(absoluteFile("unknownFile")), new SourcePosition(1, 2, 3)); Assert.assertEquals("", noMatch1, mergingLog.find(noMatch1)); SourceFilePosition noMatch2 = new SourceFilePosition( new SourceFile(absoluteFile("merged/values/values.xml")), new SourcePosition(100, 0, 3000)); Assert.assertEquals("", noMatch2, mergingLog.find(noMatch2)); mergingLog.write(); }