@Test public void testExtractingAttribute_shouldPass() { String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<feed>" + " <title>title</title>" + " <entry attr1=\"value1\" />" + " <entry attr1=\"value2\"/>" + " <entry />" + " <entry attr1=\"value4\" />" + "</feed>"; assertThat(xml) .nodesByXPath("/feed/entry") .extractingAttribute("attr1") .containsExactly("value1", "value2", null, "value4"); }
public AbstractListAssert<?, List<? extends String>, String, ObjectAssert<String>> extractingAttribute(String attribute) { isNotNull(); List<String> values = new ArrayList<>(); for (Node node : actual) { values.add(NodeUtils.attributeValue(node, attribute)); } String extractedDescription = String.format("Extracted attribute: %s", attribute); String description = Description.mostRelevantDescription(this.info.description(), extractedDescription); return newListAssertInstance(values).as(description); }
MultipleNodeAssert extends FactoryBasedNavigableIterableAssert<MultipleNodeAssert, Iterable<Node>, Node, SingleNodeAssert> { public AbstractListAssert<?, List<? extends String>, String, ObjectAssert<String>> extractingAttribute(String attribute) { isNotNull(); List<String> values = new ArrayList<>(); for (Node node : actual) { values.add(NodeUtils.attributeValue(node, attribute)); } String extractedDescription = String.format("Extracted attribute: %s", attribute); String description = Description.mostRelevantDescription(this.info.description(), extractedDescription); return newListAssertInstance(values).as(description); } }
MultipleNodeAssert extends FactoryBasedNavigableIterableAssert<MultipleNodeAssert, Iterable<Node>, Node, SingleNodeAssert> { public AbstractListAssert<?, List<? extends String>, String, ObjectAssert<String>> extractingAttribute(String attribute) { isNotNull(); List<String> values = new ArrayList<>(); for (Node node : actual) { values.add(NodeUtils.attributeValue(node, attribute)); } String extractedDescription = String.format("Extracted attribute: %s", attribute); String description = Description.mostRelevantDescription(this.info.description(), extractedDescription); return newListAssertInstance(values).as(description); } private  MultipleNodeAssert(Iterable<Node> nodes, JAXPXPathEngine engine); }
MultipleNodeAssert extends FactoryBasedNavigableIterableAssert<MultipleNodeAssert, Iterable<Node>, Node, SingleNodeAssert> { public AbstractListAssert<?, List<? extends String>, String, ObjectAssert<String>> extractingAttribute(String attribute) { isNotNull(); List<String> values = new ArrayList<>(); for (Node node : actual) { values.add(NodeUtils.attributeValue(node, attribute)); } String extractedDescription = String.format("Extracted attribute: %s", attribute); String description = Description.mostRelevantDescription(this.info.description(), extractedDescription); return newListAssertInstance(values).as(description); } private  MultipleNodeAssert(Iterable<Node> nodes, JAXPXPathEngine engine); MultipleNodeAssert exist(); void doNotExist(); MultipleNodeAssert haveAttribute(final String attributeName); MultipleNodeAssert haveAttribute(final String attributeName, final String attributeValue); MultipleNodeAssert doNotHaveAttribute(final String attributeName); MultipleNodeAssert doNotHaveAttribute(final String attributeName, final String attributeValue); MultipleNodeAssert containsAnyNodeHavingXPath(String xPath); MultipleNodeAssert containsAllNodesHavingXPath(final String xPath); AbstractListAssert<?, List<? extends String>, String, ObjectAssert<String>> extractingAttribute(String attribute); AbstractListAssert<?, List<? extends String>, String, ObjectAssert<String>> extractingText(); }
MultipleNodeAssert extends FactoryBasedNavigableIterableAssert<MultipleNodeAssert, Iterable<Node>, Node, SingleNodeAssert> { public AbstractListAssert<?, List<? extends String>, String, ObjectAssert<String>> extractingAttribute(String attribute) { isNotNull(); List<String> values = new ArrayList<>(); for (Node node : actual) { values.add(NodeUtils.attributeValue(node, attribute)); } String extractedDescription = String.format("Extracted attribute: %s", attribute); String description = Description.mostRelevantDescription(this.info.description(), extractedDescription); return newListAssertInstance(values).as(description); } private  MultipleNodeAssert(Iterable<Node> nodes, JAXPXPathEngine engine); MultipleNodeAssert exist(); void doNotExist(); MultipleNodeAssert haveAttribute(final String attributeName); MultipleNodeAssert haveAttribute(final String attributeName, final String attributeValue); MultipleNodeAssert doNotHaveAttribute(final String attributeName); MultipleNodeAssert doNotHaveAttribute(final String attributeName, final String attributeValue); MultipleNodeAssert containsAnyNodeHavingXPath(String xPath); MultipleNodeAssert containsAllNodesHavingXPath(final String xPath); AbstractListAssert<?, List<? extends String>, String, ObjectAssert<String>> extractingAttribute(String attribute); AbstractListAssert<?, List<? extends String>, String, ObjectAssert<String>> extractingText();  }