Home | History | Annotate | Download | only in combined
      1 package junitparams.custom.combined;
      2 
      3 import java.util.LinkedList;
      4 import java.util.List;
      5 
      6 import org.junit.AfterClass;
      7 import org.junit.Test;
      8 import org.junit.runner.RunWith;
      9 
     10 import junitparams.JUnitParamsRunner;
     11 
     12 import static org.assertj.core.api.Assertions.*;
     13 
     14 @RunWith(JUnitParamsRunner.class)
     15 public class CombinedParametersProviderTest {
     16 
     17     private static Verifier verifier = new Verifier();
     18 
     19     @Test
     20     @CombinedParameters({"a,b", "1,2"})
     21     public void calledWithCartesianProduct(String character, String number) {
     22         verifier.called(character, number);
     23     }
     24 
     25     @AfterClass
     26     public static void verify() {
     27         assertThat(verifier.getCalls()).containsOnly(
     28                 new Verifier.Call("a", "1"),
     29                 new Verifier.Call("b", "1"),
     30                 new Verifier.Call("a", "2"),
     31                 new Verifier.Call("b", "2")
     32         );
     33     }
     34 
     35     private static class Verifier {
     36 
     37         private List<Call> calls = new LinkedList<Call>();
     38 
     39         void called(String firstParam, String anotherParam){
     40             calls.add(new Call(firstParam, anotherParam));
     41         }
     42 
     43         List<Call> getCalls() {
     44             return calls;
     45         }
     46 
     47         private static class Call {
     48 
     49             private final String firstParam;
     50             private final String anotherParam;
     51 
     52             Call(String firstParam, String anotherParam) {
     53                 this.firstParam = firstParam;
     54                 this.anotherParam = anotherParam;
     55             }
     56 
     57             @Override
     58             public String toString() {
     59                 return "Call{" +
     60                         "'" + firstParam + '\'' +
     61                         ",'" + anotherParam + '\'' +
     62                         '}';
     63             }
     64 
     65             @Override
     66             public boolean equals(Object o) {
     67                 if (this == o) {
     68                     return true;
     69                 }
     70                 if (o == null || getClass() != o.getClass()) {
     71                     return false;
     72                 }
     73 
     74                 Call call = (Call) o;
     75 
     76                 return firstParam.equals(call.firstParam) && anotherParam.equals(call.anotherParam);
     77 
     78             }
     79 
     80             @Override
     81             public int hashCode() {
     82                 int result = firstParam.hashCode();
     83                 result = 31 * result + anotherParam.hashCode();
     84                 return result;
     85             }
     86         }
     87     }
     88 }
     89