I’m working with an application using Apache XMLBeans (interfaces for XML structure elements extending org.apache.xmlbeans.XmlObject, implementations for those interfaces extending org.apache.xmlbeans.impl.values.XmlComplexContentImpl)
I got following kind of functionality:
- An XML object is passed to a method with some data
- Based on this data, subcontent is generated for this XML object
- using XML objects’ addFoo() to add elements etc
Now I’d like to have a test for this functionality but I’m not sure what is the best way to have this XML object for testing (I’d like the stub/mock object to maintain the subtree state to be easily tested). Some options:
- I tried instantiating these FooImpl implementation objects but they require reference to org.apache.xmlbeans.SchemaType sType
- Is there some way to instantiate these?
- Giving null / mocked SchemaType ends up with NPE when something is added
- Generating a stub classes with the few needed methods would work but ends up with many (> 100) methods to generate
- Using Mockito works otherwise, but to have the xml tree structure state easily tested, I need to use doAnswer() etc
Some ideas?
br, Touko
Found myself that the answer was pretty easy : The xmlbeans interfaces have factory classes for instantiating the beans, for example: