use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.
the class ResourceTableValidatorTest method validateModule_nonReferencedFile_throws.
@Test
public void validateModule_nonReferencedFile_throws() throws Exception {
BundleModule module = new BundleModuleBuilder("module").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResource("icon", "res/drawable/icon.png").build()).setManifest(androidManifest("com.test.app")).build();
InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new ResourceTableValidator().validateModule(module));
assertThat(exception).hasMessageThat().contains("contains references to non-existing files: [res/drawable/icon.png]");
}
use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.
the class ResourceTableValidatorTest method validateModule_fileOutsideRes_throws.
@Test
public void validateModule_fileOutsideRes_throws() throws Exception {
BundleModule module = new BundleModuleBuilder("module").addFile("assets/icon.png").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResource("icon", "assets/icon.png").build()).setManifest(androidManifest("com.test.app")).build();
InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new ResourceTableValidator().validateModule(module));
assertThat(exception).hasMessageThat().contains("references file 'assets/icon.png' outside of the 'res/' directory");
}
use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.
the class BundleConfigValidatorTest method masterResources_valid_ok.
@Test
public void masterResources_valid_ok() throws Exception {
ResourceTable resourceTable = new ResourceTableBuilder().addPackage("com.test.app").addStringResource("label", "Hello World").build();
int resourceId = ResourcesUtils.entries(resourceTable).findFirst().get().getResourceId().getFullResourceId();
AppBundle appBundle = createAppBundleBuilder(BundleConfigBuilder.create().addResourcePinnedToMasterSplit(resourceId)).addModule("feature", module -> module.setResourceTable(resourceTable).setManifest(androidManifest("com.test.app"))).build();
new BundleConfigValidator().validateBundle(appBundle);
}
use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.
the class ResourceTableValidatorTest method validateModule_validWithResources_succeeds.
@Test
public void validateModule_validWithResources_succeeds() throws Exception {
BundleModule module = new BundleModuleBuilder("module").addFile("res/drawable/icon.png").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResource("icon", "res/drawable/icon.png").build()).setManifest(androidManifest("com.test.app")).build();
new ResourceTableValidator().validateModule(module);
}
use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.
the class ModuleSplitTest method forArchive_filtersResources.
@Test
public void forArchive_filtersResources() throws Exception {
BundleModule module = new BundleModuleBuilder("testModule").setManifest(androidManifest("com.test.app")).addFile("res/drawable/icon.jpg", DUMMY_CONTENT).addFile("res/drawable/background.jpg", DUMMY_CONTENT).build();
AndroidManifest archivedManifest = AndroidManifest.create(androidManifest("com.test.app", ManifestProtoUtils.withVersionCode(123)));
ResourceTable archivedResourceTable = new ResourceTableBuilder().addPackage("com.test.app").addDrawableResource("icon", "res/drawable/icon.jpg").build();
Path archivedClassesDexFile = createTempClassesDexFile(DUMMY_CONTENT);
ModuleSplit split = ModuleSplit.forArchive(module, archivedManifest, Optional.of(archivedResourceTable), archivedClassesDexFile);
assertThat(split.getResourceTable().get()).isEqualTo(archivedResourceTable);
assertThat(extractPaths(split.getEntries())).containsExactly("res/drawable/icon.jpg", "dex/classes.dex");
}
Aggregations