-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathArgumentSourcesTest.java
86 lines (70 loc) · 2.35 KB
/
ArgumentSourcesTest.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
package org.codefx.demo.junit5.parameterized;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.TestReporter;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.CsvFileSource;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.EnumSource;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class ArgumentSourcesTest {
@ParameterizedTest
@ValueSource(longs = { 42, 63 })
void withValueSourceLong(long number) {
assertNotNull(number);
}
@ParameterizedTest
@ValueSource(strings = { "Hello", "Parameterized" })
void withOtherParams(String word, TestInfo info, TestReporter reporter) {
reporter.publishEntry(info.getDisplayName(), "Word: " + word);
assertNotNull(word);
}
@ParameterizedTest
@EnumSource(TimeUnit.class)
void withAllEnumValues(TimeUnit unit) {
assertNotNull(unit);
}
@ParameterizedTest
@EnumSource(TimeUnit.class)
void withAllEnumValuesCrossProduct_errors(TimeUnit unit, TimeUnit unit2) {
assertNotNull(unit);
}
@ParameterizedTest
@EnumSource(value = TimeUnit.class, names = { "NANOSECONDS", "MICROSECONDS" })
void withSomeEnumValues(TimeUnit unit) {
assertNotNull(unit);
}
@ParameterizedTest
@MethodSource("createWords")
void withMethodSource(String word) {
assertNotNull(word);
}
private static Stream<String> createWords() {
return Stream.of("Hello", "Parameterized");
}
@ParameterizedTest
@MethodSource("createWordsWithLength")
void testWordLength(String word, int length) {
assertEquals(length, word.length());
}
private static Stream<Arguments> createWordsWithLength() {
return Stream.of(
Arguments.of("Hello", 5),
Arguments.of("Parameterized", 13));
}
@ParameterizedTest
@CsvSource({ "Hello, 5", "Parameterized, 13", "'Hello, Parameterized!', 21" })
void withCsvSource(String word, int length) {
assertEquals(length, word.length());
}
@ParameterizedTest
@CsvFileSource(resources = "/word-lengths.csv")
void withCsvFileSource(String word, int length) {
assertEquals(length, word.length());
}
}