/** * Will parse an XML tag into {@link Object} then inform the {@link ParseWatcher} * The idea is to have a callback for a number of elements to create a {@link java.util.List} * This can be used when you want to parse attributes as well as the XML body into your object * * @param parser The parser you wish to parse the XML with * @param watcher The watcher on elements to be informed of object creation * @param <T> The type you wish to create from the XML body * @return {@link ElementFinder} */ public <T> ElementFinder<T> getListElementFinder(Parser<T> parser, ParseWatcher<T> watcher) { return new ListElementFinder<T>(parser, watcher); }
@Test(expected = UnsupportedOperationException.class) public void notSupportGetResultOrThrow_asListCreatorWillCallbackAfterEveryListItemIsParsed() throws Exception { elementCreator.getResultOrThrow(); }
@Test(expected = UnsupportedOperationException.class) public void notSupportPopResult_asListCreatorWillCallbackAfterEveryListItemIsParsed() throws Exception { elementCreator.popResult(); }
@Test(expected = UnsupportedOperationException.class) public void notSupportPopResultOrThrow_asListCreatorWillCallbackAfterEveryListItemIsParsed() throws Exception { elementCreator.popResultOrThrow(); }
@Test(expected = UnsupportedOperationException.class) public void notSupportGetResult_asListCreatorWillCallbackAfterEveryListItemIsParsed() throws Exception { elementCreator.getResult(); }
@Test public void callWatcher_afterEachItemForTheListIsParsed() throws Exception { String result = "result"; elementCreator.onParsed(result); verify(mockWatcher).onParsed(result); }
@Test public void callParser_whenCreated() { String tag = "tag"; stub(mockElement.getChild(tag)).toReturn(mockElement); elementCreator.find(mockElement, tag); verify(mockParser).parse(mockElement, elementCreator); }
/** * Will parse the attributes off an XML tag, into {@link Object} then inform the {@link ParseWatcher} * The idea is to have a callback for a number of elements to create a {@link java.util.List} * * @param attributeMarshaller The marshaller to parse the attributes into your required type * @param watcher The watcher on elements to be informed of object creation * @param attrTags The tags of the attributes you wish to parse * @param <T> The type you wish to create from the XML body * @return {@link ElementFinder} */ public <T> ElementFinder<T> getListAttributeFinder(AttributeMarshaller<T> attributeMarshaller, ParseWatcher<T> watcher, String... attrTags) { return new ListElementFinder<T>(new BasicAttributeParser<T>(attributeMarshaller, attrTags), watcher); }
@Before public void setUp() throws Exception { initMocks(this); elementCreator = new ListElementFinder<Object>(mockParser, mockWatcher); }