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

This package provides exposed API of TestWithResources JUnit Jupiter extension.

This API consists of four parts:

  • @TestWithResources - adds this extension to a test class.
  • Annotations @Given*Resource - a.k.a resource annotations. Request content of resource.
  • Annotations @With* - a.k.a parser annotations. Declared parser objects.
  • @TestsAdvice - defines Tests Advice, a class that provides globally available parsers.

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.
  • Class Summary 
    Class Description
    TestWithResourcesExtension  
  • Annotation Types Summary 
    Annotation Type Description
    GivenBinaryResource
    Annotates field or test parameter that must be injected with content of binary resource file with path 'from'.
    GivenJsonLinesResource
    Annotates field or test parameter that must be injected with parsed content of JSONL resource file with path 'from'.
    GivenJsonResource
    Annotates field or test parameter that must be injected with parsed content of JSON resource file with path 'from'.
    GivenPropertiesResource
    Annotates field or test parameter that must be injected with content of properties resource file with path 'from'.
    GivenTextResource
    Annotates field or test parameter that must be injected with content of text resource file with path 'from'.
    GivenYamlDocumentsResource
    Annotates field or test parameter that must be injected with parsed content of YAML resource file containing multiple documents (separated by three hyphens '---') with path 'from'.
    GivenYamlResource
    Annotates field or test parameter that must be injected with parsed content of YAML resource file with path 'from'.
    TestsAdvice
    Annotates public final class that becomes tests advice.
    TestWithResources
    TestWithResources is a JUnit Jupiter extension that supplies your tests with loaded and parsed content of resource files.
    WithGson
    Annotates field or method of a test class or of a tests advice class (see TestsAdvice) that defines Gson object used to parse JSON/JSONL resources.
    WithJacksonMapper
    Annotates field or method of a test class or of a tests advice class (see TestsAdvice) that defines ObjectMapper object used to parse JSON/JSONL resources.
    WithSnakeYaml
    Annotates field or method of a test class or of a tests advice class (see TestsAdvice) that defines Yaml object used to parse YAML resources.