-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTypeIDTest.java
More file actions
70 lines (59 loc) · 2.11 KB
/
Copy pathTypeIDTest.java
File metadata and controls
70 lines (59 loc) · 2.11 KB
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
/*
* This Java source file was generated by the Gradle 'init' task.
*/
package typeid;
import static org.junit.jupiter.api.Assertions.assertEquals;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import java.io.IOException;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
class TypeIDTest {
private static final ObjectMapper MAPPER = new ObjectMapper(new YAMLFactory());
record Valid(String name, String prefix, String typeid, String uuid) {}
record Invalid(String name, String typeid, String description) {}
@ParameterizedTest
@MethodSource("validParams")
void valid(Valid valid) {
var typeId = TypeID.fromString(valid.typeid()).get();
assertEquals(valid.prefix(), typeId.prefix(), valid.name());
assertEquals(valid.uuid(), typeId.uuid().toString());
}
@ParameterizedTest
@MethodSource("invalidParams")
void invalid(Invalid invalid) {
assertEquals(Optional.empty(), TypeID.fromString(invalid.typeid()), invalid.description());
}
@Test
void twoWay() {
var in = new TypeID("test");
assertEquals(Optional.of(in), TypeID.fromString(in.toString()));
}
@Test
void fromUUID() {
var uuid = UUID.fromString("3c098018-c8b3-44f3-98b0-3bfaca73ec48");
assertEquals(
Optional.of("prefix_1w1601hj5k8ksshc1vzb577v28"),
TypeID.fromUUID("prefix", uuid).map(Objects::toString));
}
static Stream<Valid> validParams() throws IOException {
return MAPPER
.readValue(
TypeIDTest.class.getResourceAsStream("/valid.yml"), new TypeReference<List<Valid>>() {})
.stream();
}
static Stream<Invalid> invalidParams() throws IOException {
return MAPPER
.readValue(
TypeIDTest.class.getResourceAsStream("/invalid.yml"),
new TypeReference<List<Invalid>>() {})
.stream();
}
}