/** * Will parse an XML tag using the passed {@link Parser} * This can be used when you want to parse attributes as well as the body into your object * * @param parser The parser you wish to parse the XML with * @param <T> The type you wish to create from the XML body * @return {@link ElementFinder} */ public <T> ElementFinder<T> getTypeFinder(Parser<T> parser) { return new BasicElementFinder<T>(parser); }
@Override public T popResultOrThrow() { validateResult(); return popResult(); }
@Test public void allow_null_results_when_get_result_is_popped() throws Exception { Object result = elementCreator.popResult(); assertThat(result).isNull(); }
@Test public void get_child_elements_using_namspace_when_a_namespace_is_provided() throws Exception { String tag = "tag"; String namespace = "namespace"; elementCreator.find(mockElement, namespace, tag); verify(mockElement).getChild(namespace, tag); }
@Override public T getResultOrThrow() { validateResult(); return result; }
@Test(expected = BasicElementFinder.ResultNotFoundException.class) public void throw_exception_when_result_has_not_been_parsed_or_found_and_a_required_result_is_asked_for() throws Exception { elementCreator.getResultOrThrow(); }
@Test(expected = BasicElementFinder.ResultNotFoundException.class) public void throw_exception_when_result_has_not_been_parsed_or_found_and_a_result_is_popped() throws Exception { elementCreator.popResultOrThrow(); }
@Test public void allow_null_results_when_get_result_is_used() throws Exception { Object result = elementCreator.getResult(); assertThat(result).isNull(); }
@Test public void callParser_whenCreated() { String tag = "tag"; stub(mockElement.getChild(tag)).toReturn(mockElement); elementCreator.find(mockElement, tag); verify(mockParser).parse(mockElement, elementCreator); }
@Before public void setUp() throws Exception { initMocks(this); elementCreator = new BasicElementFinder<Object>(mockParser); }