Class TestParametersValuesProvider.Context
- java.lang.Object
-
- com.google.testing.junit.testparameterinjector.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 Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <A extends Annotation>
AgetOtherAnnotation(Class<A> annotationType)
Returns the only annotation with the given type on the method or constructor that was annotated with @TestParameters.<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.Class<?>
testClass()
The class that contains the test that is currently being run.String
toString()
-
-
-
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) { ... }
thencontext.getOtherAnnotation(CustomAnnotation.class).value()
will equal 123.- Throws:
NoSuchElementException
- if this there is no annotation with the given typeIllegalArgumentException
- if there are multiple annotations with the given typeIllegalArgumentException
- 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) { ... }
thencontext.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()
-
-