diff options
author | Jens Nyman <jnyman@google.com> | 2024-01-17 10:14:53 +0000 |
---|---|---|
committer | Jens Nyman <jnyman@google.com> | 2024-01-17 10:14:53 +0000 |
commit | e83226da9478f6efe2b15e12614c0a8605ad0d68 (patch) | |
tree | 91ef7825621c805b63d1bcb528d1ccdb4b1a4d81 | |
parent | 25cf9ffd9ca74a49da627401f859e3f7c0c788d2 (diff) | |
download | TestParameterInjector-e83226da9478f6efe2b15e12614c0a8605ad0d68.tar.gz |
Update README with the new context aware values provider
https://github.com/google/TestParameterInjector/issues/44
-rw-r--r-- | README.md | 15 |
1 files changed, 11 insertions, 4 deletions
@@ -331,15 +331,17 @@ Instead of providing a list of parsable strings, you can implement your own `TestParameterValuesProvider` as follows: ```java +import com.google.testing.junit.testparameterinjector.TestParameterValuesProvider; + @Test public void matchesAllOf_throwsOnNull( @TestParameter(valuesProvider = CharMatcherProvider.class) CharMatcher charMatcher) { assertThrows(NullPointerException.class, () -> charMatcher.matchesAllOf(null)); } -private static final class CharMatcherProvider implements TestParameterValuesProvider { +private static final class CharMatcherProvider extends TestParameterValuesProvider { @Override - public List<CharMatcher> provideValues() { + public List<CharMatcher> provideValues(Context context) { return ImmutableList.of(CharMatcher.any(), CharMatcher.ascii(), CharMatcher.whitespace()); } } @@ -356,9 +358,9 @@ Notes: want to customize the value names, you can do that as follows: ``` - private static final class FruitProvider implements TestParameterValuesProvider { + private static final class FruitProvider extends TestParameterValuesProvider { @Override - public List<?> provideValues() { + public List<?> provideValues(Context context) { return ImmutableList.of( value(new Apple()).withName("apple"), value(new Banana()).withName("banana")); @@ -366,6 +368,11 @@ Notes: } ``` +- The given `Context` contains the test class and other annotations on the + `@TestParameter`-annotated parameter/field. This allows more generic + providers that take into account custom annotations with extra data, or the + implementation of abstract methods on a base test class. + ### Dynamic parameter generation for `@TestParameters` Instead of providing a YAML mapping of parameters, you can implement your own |