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);
}
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());
}
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();
}
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);
}
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"));
}
Aggregations