-
Notifications
You must be signed in to change notification settings - Fork 5
/
FactoryTest.groovy
106 lines (91 loc) · 2.3 KB
/
FactoryTest.groovy
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
/*
* © 2023. TU Dortmund University,
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
* Research group Distribution grid planning and operation
*/
package edu.ie3.datamodel.io.factory
import edu.ie3.datamodel.exceptions.FactoryException
import edu.ie3.datamodel.utils.Try
import spock.lang.Shared
import spock.lang.Specification
class FactoryTest extends Specification {
@Shared
private final DummyFactory factory = new DummyFactory(String)
def "A Factory can return unused fields correctly"() {
when:
def unused = factory.getUnusedFields(actualFields as Set<String>, validFieldSets)
then:
unused == expected as Set<String>
where:
actualFields | validFieldSets | expected
[
"uuid",
"id",
"time",
"value_1"
] | [
["uuid", "value_1"] as Set<String>,
["id", "time", "value_1"] as Set<String>
] | ["uuid"]
[
"uuid",
"id",
"time",
"value_1",
"value_2",
"value_3"
] | [
["uuid", "value_1", "value_3"] as Set<String>,
["id", "time", "value_1"] as Set<String>
] | ["id", "time", "value_2"]
[
"uuid",
"id",
"time",
"value_1"
] | [
[
"uuid",
"id",
"time",
"value_1",
"value_2"
] as Set<String>,
[
"uuid",
"id",
"time",
"value_1",
"value_3"
] as Set<String>
] | []
}
def "A Factory should allow additional fields"() {
given:
def actualFields = DummyFactory.newSet("uuid", "id", "time", "value_1", "value_2", "value_3")
when:
def result = Try.ofVoid(() -> factory.validate(actualFields, String), FactoryException)
then:
result.success
}
private class DummyFactory extends Factory<String, SimpleFactoryData, String> {
protected DummyFactory(Class<? extends String>... supportedClasses) {
super(supportedClasses)
}
@Override
protected String buildModel(SimpleFactoryData data) {
return ""
}
@Override
List<Set<String>> getUniqueFields() {
return []
}
@Override
protected List<Set<String>> getFields(Class<?> entityClass) {
return [
["uuid", "value1", "value3"] as Set<String>,
["id", "time", "value1"] as Set<String>
]
}
}
}