ResourceMerger extends DataMerger<ResourceItem, ResourceFile, ResourceSet> { @Override public void addDataSet(ResourceSet resourceSet) { super.addDataSet(resourceSet); } ResourceMerger(int minSdk); @Override void addDataSet(ResourceSet resourceSet); @Override void mergeData(@NonNull MergeConsumer<ResourceItem> consumer, boolean doCleanUp);  }
@Test public void testMergeIdGeneratingResources() throws Exception { File root = TestUtils.getRoot("resources", "idGenerating"); ResourceSet resourceSet = new ResourceSet("idResources", null); resourceSet.addSource(root); ResourceMerger merger = new ResourceMerger(0); merger.addDataSet(resourceSet); RecordingLogger logger = new RecordingLogger(); File layoutDir = new File(root, "layout"); File layoutFile = new File(layoutDir, "layout_for_id_scan.xml"); resourceSet.setShouldParseResourceIds(true); final ResourceFile parsedFile = resourceSet.loadFile(root, layoutFile, logger); assertNotNull(parsedFile); assertTrue(parsedFile.getFile().equals(layoutFile)); assertEquals("", parsedFile.getQualifiers()); assertEquals(12, parsedFile.getItems().size()); Collection<ResourceItem> layoutItems = Collections2.filter(parsedFile.getItems(), new Predicate<ResourceItem>() { @Override public boolean apply(ResourceItem input) { return input.getType() == ResourceType.LAYOUT && input.getName().equals("layout_for_id_scan") && input.getSource() != null && input.getSource().equals(parsedFile); } }); assertEquals(1, layoutItems.size()); ResourceItem layoutItem = Iterables.getFirst(layoutItems, null); assertNotNull(layoutItem); ResourceValue layoutValue = layoutItem.getResourceValue(false); assertNotNull(layoutValue); assertEquals(layoutFile.getAbsolutePath(), layoutValue.getValue()); Collection<ResourceItem> idItems = Collections2.filter(parsedFile.getItems(), new Predicate<ResourceItem>() { @Override public boolean apply(ResourceItem input) { return input.getType() == ResourceType.ID && input.getSource() != null && input.getSource().equals(parsedFile); } }); assertEquals(11, idItems.size()); File folder = TestUtils.createTempDirDeletedOnExit(); folder.deleteOnExit(); merger.writeBlobTo(folder, getConsumer(), false); ResourceMerger loadedMerger = new ResourceMerger(0); assertTrue(loadedMerger.loadFromBlob(folder, true )); compareResourceMaps(merger, loadedMerger, true ); List<ResourceItem> loadedLayoutItems = loadedMerger.getDataMap().get("layout/layout_for_id_scan"); assertEquals(1, loadedLayoutItems.size()); layoutItem = Iterables.getFirst(loadedLayoutItems, null); assertNotNull(layoutItem); layoutValue = layoutItem.getResourceValue(false); assertNotNull(layoutValue); assertEquals(layoutFile.getAbsolutePath(), layoutValue.getValue()); List<ResourceItem> loadedIdItems = loadedMerger.getDataMap().get("id/title_refresh_progress"); assertEquals(1, loadedIdItems.size()); ResourceItem idItem = Iterables.getFirst(loadedIdItems, null); assertNotNull(idItem); ResourceValue idValue = idItem.getResourceValue(false); assertNotNull(idValue); assertTrue(Strings.isNullOrEmpty(idValue.getValue())); checkLogger(logger); }
@Test public void testChangedIgnoredFile() throws Exception { ResourceSet res = ResourceSetTest.getBaseResourceSet(); ResourceMerger resourceMerger = new ResourceMerger(0); resourceMerger.addDataSet(res); File root = TestUtils.getRoot("resources", "baseSet"); File changedCVSFoo = new File(root, "CVS/foo.txt"); FileValidity<ResourceSet> fileValidity = resourceMerger.findDataSetContaining( changedCVSFoo); assertEquals(FileValidity.FileStatus.IGNORED_FILE, fileValidity.status); }