• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package junitparams;
2 
3 import static org.assertj.core.api.Assertions.assertThat;
4 
5 import java.util.*;
6 
7 import org.junit.*;
8 import org.junit.runner.*;
9 
10 import junitparams.usage.person_example.*;
11 
12 @RunWith(JUnitParamsRunner.class)
13 public class CastingParamsTest {
14 
15     @Test
16     @Parameters
wrapWithTypeBySingleArgConstructor(PersonTest.Person person)17     public void wrapWithTypeBySingleArgConstructor(PersonTest.Person person) {
18         assertThat(person.getAge()).isGreaterThan(0);
19     }
parametersForWrapWithTypeBySingleArgConstructor()20     List<Integer> parametersForWrapWithTypeBySingleArgConstructor() {
21         return Arrays.asList(1, 2);
22     }
23 
24     @Test
25     @Parameters
wrapWithTypeByMultiArgConstructor(PersonTest.Person person)26     public void wrapWithTypeByMultiArgConstructor(PersonTest.Person person) {
27         assertThat(person.getAge()).isGreaterThan(0);
28     }
parametersForWrapWithTypeByMultiArgConstructor()29     Object parametersForWrapWithTypeByMultiArgConstructor() {
30         return new Object[]{new Object[]{"first", 1}, new Object[]{"second", 2}};
31     }
32 
33     @Test
34     @Parameters
cartoonCharacters(PersonTest.Person character)35     public void cartoonCharacters(PersonTest.Person character) {
36         assertThat(character.getName()).isIn("Tarzan", "Jane");
37         assertThat(character.getAge()).isIn(0, 20);
38     }
39 
parametersForCartoonCharacters()40     private List<?> parametersForCartoonCharacters() {
41         return Arrays.asList(
42                 new Object[]{"Tarzan", 0},
43                 new Object[]{"Jane", 20}
44             );
45     }
46 
47     @Test
48     @Parameters(method = "strings")
stringArrayFromMethod(String... values)49     public void stringArrayFromMethod(String... values) {
50         assertThat(values).containsOnlyOnce("1", "2");
51     }
strings()52     private Object strings() {
53         return new Object[]{new Object[]{"1", "2"}, new Object[]{"2", "1"}};
54     }
55 
56     @Test
57     @Parameters({"a,b", "b,a"})
stringArrayFromAnnotation(String... values)58     public void stringArrayFromAnnotation(String... values) {
59         assertThat(values).containsOnlyOnce("a","b");
60     }
61 
62 }
63