Package com.adelean.inject.resources.junit.jupiter

Rules of parser selection

Parsers are created in execution contexts of tests by @With* annotations. Parsers can be named or anonymous. All of @With* annotations have attribute name to specify the name of parser. Annotations @Given*Resource that relies on parsers have parameter to specify the name of parser.

When @Given*Resource requires a parser to perform resource parsing and injection, it starts to look up for a parser following those rule:

  • If resource annotation requires named parser, we are looking for the parser with that name and right type defined in the same test class.
  • If we don't found the parser with requested name in the same test class, we start to look up for a parser with that name in parent classes starting from immediate super class.
  • If named parser was not found in any of test class super classes, we look inside a class annotated with @TestsAdvice.
  • If named parser still was not found. Exception is thrown.
  • If resource annotation do not specify the name of parser, we are first looking for any parser with a right type first in the same test class, and after, if it was not found, in parent classes starting by immediate super class.
  • If none of test class super classes declare required parser, we check a class annotated with @TestsAdvice.
  • For some kind of resources, if no parser was found, we will use the default instance of parser. In other cases we will throw an exception. Check the javadoc of particular resource annotation to understand its behaviour.