1 package junitparams.custom; 2 3 import java.lang.annotation.Retention; 4 import java.lang.annotation.RetentionPolicy; 5 6 import org.junit.Test; 7 import org.junit.runner.RunWith; 8 9 import junitparams.JUnitParamsRunner; 10 11 import static org.assertj.core.api.Assertions.*; 12 13 @RunWith(JUnitParamsRunner.class) 14 public class CustomParametersProviderTest { 15 16 @Test 17 @CustomParameters(provider = SimpleHelloProvider.class) runWithParametersFromCustomProvider(String param)18 public void runWithParametersFromCustomProvider(String param) { 19 assertThat(param).isEqualTo("hello"); 20 } 21 22 @Test 23 @HelloParameters(hello = "Hi") runWithParametersFromCustomAnnotation(String param)24 public void runWithParametersFromCustomAnnotation(String param) { 25 assertThat(param).isEqualTo("Hi"); 26 } 27 28 29 @Retention(RetentionPolicy.RUNTIME) 30 @CustomParameters(provider = CustomHelloProvider.class) 31 public @interface HelloParameters { hello()32 String hello(); 33 } 34 35 public static class SimpleHelloProvider implements ParametersProvider<CustomParameters> { 36 @Override initialize(CustomParameters parametersAnnotation)37 public void initialize(CustomParameters parametersAnnotation) { 38 } 39 40 @Override getParameters()41 public Object[] getParameters() { 42 return new Object[]{"hello", "hello"}; 43 } 44 } 45 46 public static class CustomHelloProvider implements ParametersProvider<HelloParameters> { 47 48 private String hello; 49 50 @Override initialize(HelloParameters parametersAnnotation)51 public void initialize(HelloParameters parametersAnnotation) { 52 hello = parametersAnnotation.hello(); 53 } 54 55 @Override getParameters()56 public Object[] getParameters() { 57 return new Object[]{hello, hello}; 58 } 59 } 60 } 61 62