Home | History | Annotate | Download | only in custom
      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)
     18     public void runWithParametersFromCustomProvider(String param) {
     19         assertThat(param).isEqualTo("hello");
     20     }
     21 
     22     @Test
     23     @HelloParameters(hello = "Hi")
     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 {
     32         String hello();
     33     }
     34 
     35     public static class SimpleHelloProvider implements ParametersProvider<CustomParameters> {
     36         @Override
     37         public void initialize(CustomParameters parametersAnnotation) {
     38         }
     39 
     40         @Override
     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
     51         public void initialize(HelloParameters parametersAnnotation) {
     52             hello = parametersAnnotation.hello();
     53         }
     54 
     55         @Override
     56         public Object[] getParameters() {
     57             return new Object[]{hello, hello};
     58         }
     59     }
     60 }
     61 
     62