-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathArgumentConverterTest.java
83 lines (63 loc) · 2.03 KB
/
ArgumentConverterTest.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
package org.codefx.demo.junit5.parameterized;
import org.codefx.demo.junit5.parameterized.CustomArgumentConverterTest.Point;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;
import java.time.LocalDateTime;
import java.time.Year;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class ArgumentConverterTest {
@ParameterizedTest
@ValueSource(strings = { "x" })
void testSimpleCharConversion(char c) {
assertNotNull(c);
}
@ParameterizedTest
@ValueSource(strings = { "☺️" })
void testUtfCharConversion_errors(char c) {
assertNotNull(c);
}
@ParameterizedTest
@CsvSource({ "true, 3.14159265359, JUNE, 2017, 2017-06-21T22:00:00" })
void testDefaultConverters(
boolean b, double d, Summer s, Year y, LocalDateTime dt) {
}
enum Summer {
JUNE, JULY, AUGUST, SEPTEMBER;
}
@ParameterizedTest
@ValueSource(strings = { "x️" })
void testTypeWithOneFactory(TypeWithOneFactory o) {
assertNotNull(o);
}
static class TypeWithOneFactory {
static TypeWithOneFactory of(String s) {
return new TypeWithOneFactory();
}
}
@ParameterizedTest
@ValueSource(strings = { "x️" })
void testTypeWithTwoFactories_constructorCalled(TypeWithTwoFactories o) {
assertNotNull(o);
}
static class TypeWithTwoFactories {
TypeWithTwoFactories(String s) {
System.out.println("Constructor called with " + s);
}
static TypeWithTwoFactories of(String s) {
System.out.println("Factory `of` called with " + s);
return new TypeWithTwoFactories(s);
}
static TypeWithTwoFactories from(String s) {
System.out.println("Factory `from` called with " + s);
return new TypeWithTwoFactories(s);
}
}
@ParameterizedTest
@CsvSource({ "(0/0), 0", "(0/1), 1", "(1/0), 1", "(1/1), 1.414", "(2/1), 2.236" })
// works because Point::from is suitable factory
void testPointNorm(Point point, double norm) {
assertEquals(norm, point.norm(), 0.01);
}
}