-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy pathSamplesOfUsageTest.java
173 lines (141 loc) · 5.48 KB
/
SamplesOfUsageTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package junitparams.usage;
import java.util.Arrays;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import junitparams.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import junitparams.converters.Param;
import junitparams.custom.combined.CombinedParameters;
import junitparams.mappers.CsvWithHeaderMapper;
import junitparams.naming.TestCaseName;
import junitparams.usage.person_example.PersonMapper;
import junitparams.usage.person_example.PersonTest;
import junitparams.usage.person_example.PersonType;
import static junitparams.JUnitParamsRunner.*;
import static org.assertj.core.api.Assertions.*;
@RunWith(JUnitParamsRunner.class)
public class SamplesOfUsageTest {
@Test
@Parameters({"AAA,1", "BBB,2"})
public void paramsInAnnotation(String p1, Integer p2) { }
@Test
@Parameters({"AAA|1", "BBB|2"})
public void paramsInAnnotationPipeSeparated(String p1, Integer p2) { }
@Test
@Parameters
public void paramsInDefaultMethod(String p1, Integer p2) { }
private Object parametersForParamsInDefaultMethod() {
return new Object[]{new Object[]{"AAA", 1}, new Object[]{"BBB", 2}};
}
@Test
@Parameters(method = "named1")
public void paramsInNamedMethod(String p1, Integer p2) { }
private Object named1() {
return new Object[]{"AAA", 1};
}
@Test
@Parameters(named = "return 1")
public void paramsInNamedParameters(int number) { }
@NamedParameters("return 1")
private Integer[] customNamedParameters() {
return new Integer[] { 1 };
}
@Test
@Parameters(method = "named2,named3")
public void paramsInMultipleMethods(String p1, Integer p2) { }
private Object named2() {
return new Object[]{"AAA", 1};
}
private Object named3() {
return new Object[]{"BBB", 2};
}
@Test
@Parameters(method = "named4")
public void paramsWithVarargs(String... args) {
assertThat(args).isEqualTo(new String[]{"AAA", "BBB"});
}
private Object named4() { return new Object[]{new String[]{"AAA", "BBB"}}; }
@Test
@Parameters(source = ParametersReaderProvidersTest.OneIntegerProvider.class)
public void paramsFromExternalClass(int integer) { }
@Test
@Parameters
public void paramsInCollection(String p1) { }
private List<String> parametersForParamsInCollection() { return Arrays.asList("a"); }
@Test
@Parameters
public void paramsInIterator(String p1) { }
private Iterator<String> parametersForParamsInIterator() { return Arrays.asList("a").iterator(); }
@Test
@Parameters
public void paramsInIterableOfIterables(String p1, String p2) { }
private List<List<String>> parametersForParamsInIterableOfIterables() {
return Arrays.asList(
Arrays.asList("s01e01", "s01e02"),
Arrays.asList("s02e01", "s02e02")
);
}
@Test
@Parameters({"SOME_VALUE", "OTHER_VALUE"})
public void enumsAsParamInAnnotation(PersonType person) { }
@Test
@Parameters
public void enumsAsParamsInMethod(PersonType person) { }
private PersonType[] parametersForEnumsAsParamsInMethod() { return (PersonType[]) new PersonType[] {PersonType.SOME_VALUE}; }
@Test
@Parameters(source = PersonType.class)
public void enumAsSource(PersonType personType) {
}
@Test
@Parameters
public void wrapParamsWithConstructor(PersonTest.Person person) { }
private Object parametersForWrapParamsWithConstructor() {
return new Object[]{new Object[]{"first", 1}, new Object[]{"second", 2}};
}
@Test
@FileParameters("src/test/resources/test.csv")
public void loadParamsFromCsv(int age, String name) { }
@Test
@FileParameters(value = "src/test/resources/test.csv", mapper = PersonMapper.class)
public void loadParamsFromAnyFile(PersonTest.Person person) { }
@Test
@FileParameters("classpath:test.csv")
public void loadParamsFromClasspath(int age, String name) { }
@Test
@FileParameters(value = "classpath:with_header.csv", mapper = CsvWithHeaderMapper.class)
public void loadParamsFromCsvWithHeader(int id, String name) { }
@Test
@Parameters({ "01.12.2012" })
public void convertParams(@Param(converter = ParamsConverterTest.SimpleDateConverter.class) Date date) {}
@Test
@Parameters("please\\, escape commas if you use it here and don't want your parameters to be splitted")
public void commasInParametersUsage(String phrase) { }
@Test
@Parameters({ "1,1", "2,2", "3,6" })
@TestCaseName("factorial({0}) = {1}")
public void customNamesForTestCase(int argument, int result) { }
@Test
@Parameters({ "value1, value2", "value3, value4" })
@TestCaseName("[{index}] {method}: {params}")
public void predefinedMacroForTestCaseNames(String param1, String param2) { }
public Object mixedParameters() {
boolean booleanValue = true;
int[] primitiveArray = {1, 2, 3};
String stringValue = "Test";
String[] stringArray = {"one", "two", null};
return $(
$(booleanValue, primitiveArray, stringValue, stringArray)
);
}
@Test
@Parameters(method = "mixedParameters")
@TestCaseName("{0}, {1}, {2}, {3}")
public void usageOfMultipleTypesOfParameters(
boolean booleanValue, int[] primitiveArray, String stringValue, String[] stringArray) {
}
@Test
@CombinedParameters({"AAA,BBB", "1|2"})
public void combineParamsInAnnotation(String p1, Integer p2) {}
}