@Override public TypedResource getValue(@Nonnull ResName resName, ResTable_config config) { return pickFor(resName).getValue(resName, config); }
@Test public void shouldReturnRawResourcesWithExtensions() throws Exception { String f = (String) resourceTable.getValue(R.raw.raw_resource, new ResTable_config()).getData(); assertThat(f) .isEqualTo( TestUtil.testResources() .getResourceBase() .resolve("raw") .resolve("raw_resource.txt") .toString()); }
@Test public void shouldReturnRawResourcesWithoutExtensions() throws Exception { String f = (String) resourceTable.getValue(R.raw.raw_no_ext, new ResTable_config()).getData(); assertThat(f) .isEqualTo( TestUtil.testResources() .getResourceBase() .resolve("raw") .resolve("raw_no_ext") .toString()); } }
@Test public void testStyleDataIsLoadedCorrectly() throws Exception { TypedResource typedResource = resourceTable.getValue(new ResName("android", "style", "Theme_Holo"), new ResTable_config()); StyleData styleData = (StyleData) typedResource.getData(); assertThat(styleData.getName()).isEqualTo("Theme_Holo"); assertThat(styleData.getParent()).isEqualTo("Theme"); assertThat(styleData.getPackageName()).isEqualTo("android"); assertThat(styleData.getAttrValue(new ResName("android", "attr", "colorForeground")).value) .isEqualTo("@android:color/bright_foreground_holo_dark"); } }
@Test public void shouldFindDrawableResources() throws Exception { Path testBaseDir = temporaryFolder.newFolder("res").toPath(); temporaryFolder.newFolder("res", "drawable"); temporaryFolder.newFile("res/drawable/foo.png"); ResourcePath resourcePath = new ResourcePath(null, testBaseDir, null); DrawableResourceLoader testLoader = new DrawableResourceLoader(resourceTable); testLoader.findDrawableResources(resourcePath); assertThat(resourceTable.getValue(new ResName("org.robolectric", "drawable", "foo"), new ResTable_config()).isFile()).isTrue(); } }
@Test public void ignoresBTags() throws Exception { topLevelNodeHandler.addHandler("resources", new NodeHandler() .addHandler("item[@type='string']", new StaxValueLoader(resourceTable, "string", ResType.CHAR_SEQUENCE)) ); parse("<resources xmlns:xliff=\"urn:oasis:names:tc:xliff:document:1.2\">" + "<item type=\"string\" name=\"sms_short_code_details\">This <b>may cause charges</b> on your mobile account.</item>" + "</resources>"); assertThat(resourceTable.getValue(new ResName("pkg:string/sms_short_code_details"), new ResTable_config()).getData()) .isEqualTo("This may cause charges on your mobile account."); }
@Test public void ignoresXliffTags() throws Exception { topLevelNodeHandler.addHandler("resources", new NodeHandler() .addHandler("string", new StaxValueLoader(resourceTable, "string", ResType.CHAR_SEQUENCE)) ); parse("<resources xmlns:xliff=\"urn:oasis:names:tc:xliff:document:1.2\">" + "<string name=\"preposition_for_date\">on <xliff:g id=\"date\" example=\"May 29\">%s</xliff:g></string>" + "</resources>"); assertThat(resourceTable.getValue(new ResName("pkg:string/preposition_for_date"), new ResTable_config()).getData()) .isEqualTo("on %s"); }
@Override public TypedResource getValue(@NotNull ResName resName, String qualifiers) { return pickFor(resName).getValue(resName, qualifiers); }
@Override public TypedResource getValue(@Nonnull ResName resName, ResTable_config config) { return pickFor(resName).getValue(resName, config); }