/** * Will parse the body of an XML tag into {@link Object} using the supplied {@link BodyMarshaller} * * @param bodyMarshaller The marshaller to parse the body into your required type * @param <T> The type you wish to create from the XML body * @return {@link ElementFinder} */ public <T> ElementFinder<T> getTypeFinder(BodyMarshaller<T> bodyMarshaller) { return getTypeFinder(new BasicParser<T>(bodyMarshaller)); }
/** * Will parse the body of 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 bodyMarshaller The marshaller to create an object from the XML body * @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(BodyMarshaller<T> bodyMarshaller, ParseWatcher<T> watcher) { return getListElementFinder(new BasicParser<T>(bodyMarshaller), watcher); }
/** * Will parse the body of an XML tag into a simple {@link Integer} wrapper class. This is a class that * has a constructor that takes a single primitive int parameter. * * @param clazz The class of your Integer Wrapper Class * @param <T> The type you wish to create from the XML body * @return {@link ElementFinder} */ public <T> ElementFinder<T> getIntegerWrapperTypeFinder(Class<T> clazz) { return getTypeFinder(new BasicParser<T>(getIntegerWrapperMarshaller(clazz))); }
/** * Will parse the body of an XML tag into a simple {@link String} wrapper class. This is a class that * has a constructor that takes a single {@link String} parameter. * * @param clazz The class of your String Wrapper Class * @param <T> The type you wish to create from the XML body * @return {@link ElementFinder} */ public <T> ElementFinder<T> getStringWrapperTypeFinder(Class<T> clazz) { return getTypeFinder(new BasicParser<T>(getStringWrapperMarshaller(clazz))); }
@Test public void informListener_whenElementIsParsed() throws Exception { BasicParser<Object> basicParser = new BasicParser<Object>(mockMarshaller); mockParse(basicParser, mockListener); verify(mockListener).onParsed(any()); }
@Test public void listenForBodyText_whenParsing() throws Exception { BasicParser<Object> basicParser = new BasicParser<Object>(mockMarshaller); basicParser.parse(mockElement, mockListener); verify(mockElement).setEndTextElementListener(any(EndTextElementListener.class)); }
@Test public void delegateToMarshaller_whenElementIsParsed() throws Exception { BasicParser<Object> basicParser = new BasicParser<Object>(mockMarshaller); mockParse(basicParser, mockListener); verify(mockMarshaller).marshal(any(String.class)); } }