Search in sources :

Example 1 with ResourceParseException

use of com.facebook.buck.android.aapt.MiniAapt.ResourceParseException in project buck by facebook.

the class MiniAaptTest method testInvalidDefinition.

@Test
public void testInvalidDefinition() throws XPathExpressionException, IOException {
    ImmutableList<String> lines = ImmutableList.<String>builder().add("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "<LinearLayout>", "<Button android:id=\"@+string/button1\" ", "android:layout_toLeftOf=\"@id/button2\" ", "android:text=\"@string/text\" />", "</LinearLayout>").build();
    Path resource = Paths.get("resource.xml");
    filesystem.writeLinesToPath(lines, resource);
    MiniAapt aapt = new MiniAapt(resolver, filesystem, new FakeSourcePath(filesystem, "res"), Paths.get("R.txt"), ImmutableSet.of());
    try {
        aapt.processXmlFile(filesystem, resource, ImmutableSet.builder());
        fail("MiniAapt should throw parsing '@+string/button1'");
    } catch (ResourceParseException e) {
        assertThat(e.getMessage(), containsString("Invalid definition of a resource"));
    }
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Matchers.containsString(org.hamcrest.Matchers.containsString) ResourceParseException(com.facebook.buck.android.aapt.MiniAapt.ResourceParseException) Test(org.junit.Test)

Example 2 with ResourceParseException

use of com.facebook.buck.android.aapt.MiniAapt.ResourceParseException in project buck by facebook.

the class MiniAaptTest method testInvalidReference.

@Test
public void testInvalidReference() throws IOException, XPathExpressionException {
    ImmutableList<String> lines = ImmutableList.<String>builder().add("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "<LinearLayout>", "<Button android:id=\"@+id/button1\" ", "android:layout_toLeftOf=\"@someresource/button2\" ", "android:text=\"@string/text\" />", "</LinearLayout>").build();
    Path resource = Paths.get("resource.xml");
    filesystem.writeLinesToPath(lines, resource);
    MiniAapt aapt = new MiniAapt(resolver, filesystem, new FakeSourcePath(filesystem, "res"), Paths.get("R.txt"), ImmutableSet.of());
    try {
        aapt.processXmlFile(filesystem, resource, ImmutableSet.builder());
        fail("MiniAapt should throw parsing '@someresource/button2'");
    } catch (ResourceParseException e) {
        assertThat(e.getMessage(), containsString("Invalid reference '@someresource/button2'"));
    }
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Matchers.containsString(org.hamcrest.Matchers.containsString) ResourceParseException(com.facebook.buck.android.aapt.MiniAapt.ResourceParseException) Test(org.junit.Test)

Aggregations

ResourceParseException (com.facebook.buck.android.aapt.MiniAapt.ResourceParseException)2 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)2 Path (java.nio.file.Path)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Test (org.junit.Test)2