Pergunta

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

Foi útil?

Solução

Found myself that the answer was pretty easy : The xmlbeans interfaces have factory classes for instantiating the beans, for example:

Address.Factory.newInstance()

Outras dicas

I know that this is not the answer you're looking but here it goes anyway:

Don't mock types you don't control

References:

A question for you: What are you trying to test? That Apache XML beans works as expected? Or are you writing an XML tool?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top