Class TestParametersValuesProvider.Context

  • Enclosing class:
    TestParametersValuesProvider

    public static final class TestParametersValuesProvider.Context
    extends Object
    An immutable value class that contains extra information about the context of the parameter for which values are being provided.
    • Method Detail

      • getOtherAnnotation

        public <A extends Annotation> A getOtherAnnotation​(Class<A> annotationType)
        Returns the only annotation with the given type on the method or constructor that was annotated with @TestParameters.

        For example, if the test code is as follows:

           @Test
           @TestParameters("{updateRequest: {country_code: BE}, expectedResultType: SUCCESS}")
           @TestParameters("{updateRequest: {country_code: XYZ}, expectedResultType: FAILURE}")
           @CustomAnnotation(123)
           public void update(UpdateRequest updateRequest, ResultType expectedResultType) {
             ...
           }
         
        then context.getOtherAnnotation(CustomAnnotation.class).value() will equal 123.
        Throws:
        NoSuchElementException - if this there is no annotation with the given type
        IllegalArgumentException - if there are multiple annotations with the given type
        IllegalArgumentException - if the argument it TestParameters.class because it is already handled by the TestParameterInjector framework.
      • getOtherAnnotations

        public <A extends Annotation> com.google.common.collect.ImmutableList<A> getOtherAnnotations​(Class<A> annotationType)
        Returns all annotations with the given type on the method or constructor that was annotated with @TestParameter.
           @Test
           @TestParameters("{updateRequest: {country_code: BE}, expectedResultType: SUCCESS}")
           @TestParameters("{updateRequest: {country_code: XYZ}, expectedResultType: FAILURE}")
           @CustomAnnotation(123)
           @CustomAnnotation(456)
           public void update(UpdateRequest updateRequest, ResultType expectedResultType) {
             ...
           }
         
        then context.getOtherAnnotations(CustomAnnotation.class) will return the annotations with 123 and 456.

        Returns an empty list if this there is no annotation with the given type.

        Throws:
        IllegalArgumentException - if the argument it TestParameters.class because it is already handled by the TestParameterInjector framework.
      • testClass

        public Class<?> testClass()
        The class that contains the test that is currently being run.

        Having this can be useful when sharing providers between tests that have the same base class. In those cases, an abstract method can be called as follows:

           ((MyBaseClass) context.testClass().newInstance()).myAbstractMethod()