Home | History | Annotate | Download | only in junitparams
      1 package junitparams;
      2 
      3 import java.math.BigDecimal;
      4 
      5 import org.junit.Test;
      6 import org.junit.runner.RunWith;
      7 
      8 import static org.assertj.core.api.Assertions.*;
      9 
     10 @RunWith(JUnitParamsRunner.class)
     11 public class ParamsInAnnotationTest {
     12 
     13     @Test
     14     @Parameters({"1", "2"})
     15     public void singleParam(int number) {
     16         assertThat(number).isGreaterThan(0);
     17     }
     18 
     19     @Test
     20     @Parameters({"1, true", "2, false"})
     21     public void multipleParamsCommaSeparated(int number, boolean isOne) throws Exception {
     22         if (isOne)
     23             assertThat(number).isEqualTo(1);
     24         else
     25             assertThat(number).isNotEqualTo(1);
     26     }
     27 
     28     @Test
     29     @Parameters({"1 | true", "2 | false"})
     30     public void multipleParamsPipeSeparated(int number, boolean isOne) throws Exception {
     31         if (isOne)
     32             assertThat(number).isEqualTo(1);
     33         else
     34             assertThat(number).isNotEqualTo(1);
     35     }
     36 
     37     @Test
     38     @Parameters({"a \n b", "a(asdf)", "a \r a"})
     39     public void specialCharsInParam(String a) throws Exception {
     40         assertThat(a).isIn("a \n b", "a(asdf)", "a \r a");
     41     }
     42 
     43     @Test
     44     @Parameters({",1"})
     45     public void emptyFirstParam(String empty, int number) {
     46         assertThat(empty).isEmpty();
     47         assertThat(number).isEqualTo(1);
     48     }
     49 
     50     @Test
     51     @Parameters({"1,"})
     52     public void emptyLastParam(int number, String empty) {
     53         assertThat(empty).isEmpty();
     54         assertThat(number).isEqualTo(1);
     55     }
     56 
     57     @Test
     58     @Parameters({"1,,1"})
     59     public void emptyMiddleParam(int number1, String empty, int number2) {
     60         assertThat(empty).isEmpty();
     61         assertThat(number1).isEqualTo(1);
     62         assertThat(number2).isEqualTo(1);
     63     }
     64 
     65     @Test
     66     @Parameters({","})
     67     public void allParamsEmpty(String empty1, String empty2) {
     68         assertThat(empty1).isEmpty();
     69         assertThat(empty2).isEmpty();
     70     }
     71 
     72     @Test
     73     @Parameters({
     74             "1, 1, 1",
     75             "1.1, 1.1, 2",
     76             "11, 11, 2",
     77             "1.11, 1.11, 3"
     78     })
     79     public void convertToBigDecimal(BigDecimal number, String string, int precision) {
     80         assertThat(number).isEqualByComparingTo(string);
     81         assertThat(number.precision()).isEqualTo(precision);
     82     }
     83 
     84     @Test(expected = IllegalArgumentException.class)
     85     @Parameters({" invalidNumber "})
     86     public void cannotConvertToBigDecimalForInvalidInput(BigDecimal number) {
     87     }
     88 }
     89