Search in sources :

Example 56 with XmlElement

use of com.android.aapt.Resources.XmlElement in project bundletool by google.

the class XmlProtoElementBuilderTest method getChildrenElement_matchingPredicate.

@Test
public void getChildrenElement_matchingPredicate() {
    XmlElement childElement = XmlElement.newBuilder().setName("hello").build();
    XmlElement matchingElement = XmlElement.newBuilder().setName("foo").build();
    XmlElement protoElement = XmlElement.newBuilder().addChild(XmlNode.newBuilder().setElement(childElement)).addChild(XmlNode.newBuilder().setElement(matchingElement)).build();
    XmlProtoElementBuilder element = new XmlProtoElementBuilder(protoElement.toBuilder());
    ImmutableList<XmlProtoElementBuilder> fetchedElements = element.getChildrenElements(el -> el.getName().equals("foo")).collect(toImmutableList());
    assertThat(fetchedElements).hasSize(1);
    XmlProtoElementBuilder fetchedElement = fetchedElements.get(0);
    assertThat(fetchedElement.getProto().build()).isEqualTo(matchingElement);
}
Also used : ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) XmlAttribute(com.android.aapt.Resources.XmlAttribute) ANDROID_NAMESPACE_URI(com.android.tools.build.bundletool.model.AndroidManifest.ANDROID_NAMESPACE_URI) SourcePosition(com.android.aapt.Resources.SourcePosition) ProtoTruth.assertThat(com.google.common.truth.extensions.proto.ProtoTruth.assertThat) XmlNode(com.android.aapt.Resources.XmlNode) ImmutableList(com.google.common.collect.ImmutableList) XmlNamespace(com.android.aapt.Resources.XmlNamespace) XmlElement(com.android.aapt.Resources.XmlElement) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) XmlElement(com.android.aapt.Resources.XmlElement) Test(org.junit.Test)

Example 57 with XmlElement

use of com.android.aapt.Resources.XmlElement in project bundletool by google.

the class XmlProtoElementBuilderTest method addChildElement.

@Test
public void addChildElement() {
    XmlElement protoElement = XmlElement.getDefaultInstance();
    XmlElement childElement = XmlElement.newBuilder().addAttribute(XmlAttribute.newBuilder().setName("attribute")).build();
    XmlProtoElementBuilder element = new XmlProtoElementBuilder(protoElement.toBuilder());
    element.addChildElement(new XmlProtoElementBuilder(childElement.toBuilder()));
    assertThat(element.getProto().build()).isEqualTo(protoElement.toBuilder().addChild(XmlNode.newBuilder().setElement(childElement)).build());
}
Also used : XmlElement(com.android.aapt.Resources.XmlElement) Test(org.junit.Test)

Example 58 with XmlElement

use of com.android.aapt.Resources.XmlElement in project bundletool by google.

the class XmlProtoElementBuilderTest method getChildrenElement_noMatchingPredicate.

@Test
public void getChildrenElement_noMatchingPredicate() {
    XmlElement childElement = XmlElement.newBuilder().setName("hello").build();
    XmlElement matchingElement = XmlElement.newBuilder().setName("foo").build();
    XmlElement protoElement = XmlElement.newBuilder().addChild(XmlNode.newBuilder().setElement(childElement)).addChild(XmlNode.newBuilder().setElement(matchingElement)).build();
    XmlProtoElementBuilder element = new XmlProtoElementBuilder(protoElement.toBuilder());
    ImmutableList<XmlProtoElementBuilder> fetchedElements = element.getChildrenElements(el -> el.getName().equals("bye")).collect(toImmutableList());
    assertThat(fetchedElements).isEmpty();
}
Also used : ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) XmlAttribute(com.android.aapt.Resources.XmlAttribute) ANDROID_NAMESPACE_URI(com.android.tools.build.bundletool.model.AndroidManifest.ANDROID_NAMESPACE_URI) SourcePosition(com.android.aapt.Resources.SourcePosition) ProtoTruth.assertThat(com.google.common.truth.extensions.proto.ProtoTruth.assertThat) XmlNode(com.android.aapt.Resources.XmlNode) ImmutableList(com.google.common.collect.ImmutableList) XmlNamespace(com.android.aapt.Resources.XmlNamespace) XmlElement(com.android.aapt.Resources.XmlElement) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) XmlElement(com.android.aapt.Resources.XmlElement) Test(org.junit.Test)

Example 59 with XmlElement

use of com.android.aapt.Resources.XmlElement in project bundletool by google.

the class XmlProtoElementBuilderTest method getOrCreateChildElement_withNamespace_childExists.

@Test
public void getOrCreateChildElement_withNamespace_childExists() {
    XmlElement childElement = XmlElement.newBuilder().setName("hello").setNamespaceUri("namespace").build();
    XmlElement protoElement = XmlElement.newBuilder().addChild(XmlNode.newBuilder().setElement(childElement)).build();
    XmlProtoElementBuilder element = new XmlProtoElementBuilder(protoElement.toBuilder());
    XmlProtoElementBuilder fetchedElement = element.getOrCreateChildElement("namespace", "hello");
    assertThat(fetchedElement.getProto().build()).isEqualTo(childElement);
    assertThat(element.getProto().build()).isEqualTo(protoElement);
}
Also used : XmlElement(com.android.aapt.Resources.XmlElement) Test(org.junit.Test)

Example 60 with XmlElement

use of com.android.aapt.Resources.XmlElement in project bundletool by google.

the class XmlProtoElementTest method getOptionalChildElement_manyElements_throws.

@Test
public void getOptionalChildElement_manyElements_throws() {
    XmlElement childElement = XmlElement.newBuilder().setName("child").build();
    XmlProtoElement element = new XmlProtoElement(XmlElement.newBuilder().setName("hello").addChild(XmlNode.newBuilder().setElement(childElement)).addChild(XmlNode.newBuilder().setElement(childElement)).build());
    assertThrows(XmlProtoException.class, () -> element.getOptionalChildElement("child"));
}
Also used : XmlElement(com.android.aapt.Resources.XmlElement) Test(org.junit.Test)

Aggregations

XmlElement (com.android.aapt.Resources.XmlElement)67 Test (org.junit.Test)65 XmlNode (com.android.aapt.Resources.XmlNode)27 XmlAttribute (com.android.aapt.Resources.XmlAttribute)10 BundleModule (com.android.tools.build.bundletool.model.BundleModule)4 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)4 BundleModuleBuilder (com.android.tools.build.bundletool.testing.BundleModuleBuilder)4 ImmutableList (com.google.common.collect.ImmutableList)4 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)4 Truth.assertThat (com.google.common.truth.Truth.assertThat)4 Truth8.assertThat (com.google.common.truth.Truth8.assertThat)4 ProtoTruth.assertThat (com.google.common.truth.extensions.proto.ProtoTruth.assertThat)4 RunWith (org.junit.runner.RunWith)4 JUnit4 (org.junit.runners.JUnit4)4 SourcePosition (com.android.aapt.Resources.SourcePosition)3 XmlNamespace (com.android.aapt.Resources.XmlNamespace)2 TestData (com.android.tools.build.bundletool.TestData)2 AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)2 ACTIVITY_ELEMENT_NAME (com.android.tools.build.bundletool.model.AndroidManifest.ACTIVITY_ELEMENT_NAME)2 ALLOW_BACKUP_ATTRIBUTE_NAME (com.android.tools.build.bundletool.model.AndroidManifest.ALLOW_BACKUP_ATTRIBUTE_NAME)2