Annotation Type Encoding


  • @Target({FIELD,PARAMETER,METHOD,CONSTRUCTOR,TYPE,ANNOTATION_TYPE})
    @Retention(RUNTIME)
    @Inherited
    public @interface Encoding
    Encoding can be used in combination with TestResource to specify a specific encoding or charset to use.

    The encoding to use is looked up in the following order:

    1. An Encoding annotation on the field or parameter itself
    2. For parameters, an Encoding annotation on the constructor or method
    3. An Encoding annotation on the class defining the field, constructor or method
    4. An Encoding annotation on any declaring class
    5. The default encoding that is defined via the "com.github.robtimus.junit.support.extension.testresource.encoding" configuration parameter, which can be supplied via the JUnit Launcher API, build tools (e.g., Gradle and Maven), a JVM system property, or the JUnit Platform configuration file (i.e., a file named junit-platform.properties in the root of the class path). Consult the JUnit User Guide for further information.

      This configuration parameter can take a literal value, or one of the following pre-defined values:

      • DEFAULT for Charset.defaultCharset()
      • SYSTEM for system property file.encoding
      • NATIVE for system property native.encoding (since Java 17)
      The default is UTF-8.
    Author:
    Rob Spoor
    Since:
    2.0
    • Field Summary

      Fields 
      Modifier and Type Fields Description
      static String DEFAULT
      A marker that indicates the default charset should be used.
      static String DEFAULT_ENCODING_PROPERTY_NAME
      The property that can be used to define the default encoding.
      static String NATIVE
      A marker that indicates the value from the native.encoding system property should be used.
      static String SYSTEM
      A marker that indicates the value from the file.encoding system property should be used.
    • Required Element Summary

      Required Elements 
      Modifier and Type Required Element Description
      String value
      The encoding to use.
      • SYSTEM

        static final String SYSTEM
        A marker that indicates the value from the file.encoding system property should be used.
      • NATIVE

        static final String NATIVE
        A marker that indicates the value from the native.encoding system property should be used.
      • DEFAULT_ENCODING_PROPERTY_NAME

        static final String DEFAULT_ENCODING_PROPERTY_NAME
        The property that can be used to define the default encoding.
    • Element Detail

      • value

        String value
        The encoding to use.