• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package junitparams;
2 
3 import static org.assertj.core.api.Assertions.assertThat;
4 import static org.junit.Assert.fail;
5 
6 import org.junit.*;
7 import org.junit.runner.*;
8 
9 @SuppressWarnings("unused")
10 @RunWith(JUnitParamsRunner.class)
11 public class ParametersReaderForMethodTest {
12 
13     @Test
14     @Parameters
oneParamDifferentTypes(int number, String a)15     public void oneParamDifferentTypes(int number, String a) {
16         assertThat(number).isEqualTo(1);
17         assertThat(a).isEqualTo("a");
18     }
19 
parametersForOneParamDifferentTypes()20     private Object[] parametersForOneParamDifferentTypes() {
21         return new Object[]{1, "a"};
22     }
23 
24     @Test
25     @Parameters
oneParamSetOneNull(String a, String b)26     public void oneParamSetOneNull(String a, String b) {
27         assertThat(a).isNull();
28         assertThat(b).isEqualTo("b");
29     }
30 
parametersForOneParamSetOneNull()31     private Object[] parametersForOneParamSetOneNull() {
32         return new Object[]{null, "b"};
33     }
34 
35     @Test
36     @Parameters
noToString(NoToStringObject o)37     public void noToString(NoToStringObject o) {
38         assertThat(o).isNotNull();
39     }
40 
parametersForNoToString()41     private Object[] parametersForNoToString() {
42         return new Object[]{new NoToStringObject()};
43     }
44 
45     public class NoToStringObject {
46     }
47 
48     @Test
49     @Parameters
shouldIgnoreWhenEmptyParamset()50     public void shouldIgnoreWhenEmptyParamset() {
51         fail();
52     }
53 
parametersForShouldIgnoreWhenEmptyParamset()54     private Object[] parametersForShouldIgnoreWhenEmptyParamset() {
55         return new Object[] {};
56     }
57 
58     @Test
59     @Parameters({ "a \n \\,\\|b", "\\,a(asdf)\\|", "\\,", "", "\r\n" })
escapedSpecialCharsInParam(String a)60     public void escapedSpecialCharsInParam(String a) {
61         assertThat(a).
62                 isIn("a \n ,|b", ",a(asdf)|", ",", "").
63                 isNotIn("a \n \\,\\|b", "\\,a(asdf)\\|", "\\,", "\r\n");
64     }
65 }
66