-
Notifications
You must be signed in to change notification settings - Fork 5
/
FileDefinitionTest.groovy
83 lines (66 loc) · 2.28 KB
/
FileDefinitionTest.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
/*
* © 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.csv
import edu.ie3.datamodel.io.IoUtil
import spock.lang.Shared
import spock.lang.Specification
import java.nio.file.Path
class FileDefinitionTest extends Specification {
@Shared
String fileName
@Shared
Path directory
def setupSpec() {
fileName = "node_input.csv"
directory = Path.of("test", "grid")
}
def "A file definition is et up correctly, if an empty path is given" () {
when:
def file = FileDefinition.of("name", path)
then:
file.fullPath == expectedPath
where:
path || expectedPath
IoUtil.pathOption("") || Path.of("name")
IoUtil.pathOption("/") || Path.of("name")
}
def "A file definition of a csv file is set up correctly, if the directory path has corrupt file separator" () {
when:
def file = FileDefinition.ofCsvFile(fileName, manipulatedDirectory)
then:
file.with {
assert it.directoryPath == this.directory
assert it.fileName == this.fileName
assert it.fullPath == this.directory.resolve(this.fileName)
}
where:
manipulatedDirectory || expected
Path.of("/").resolve(this.directory) || this.directory
Path.of(this.directory.toString(), "/") || this.directory
Path.of(this.directory.toString().replaceAll("[\\\\/]", File.separator == "/" ? "\\\\" : "/")) || this.directory
}
def "A file definition of a csv file is set up correctly, if the directory path is null" () {
when:
def file = FileDefinition.ofCsvFile(fileName, null)
then:
file.with {
assert it.fileName == this.fileName
assert it.directoryPath == Path.of("")
}
}
def "A file definition returns correct file path"() {
given:
def file = FileDefinition.ofCsvFile(fileName, manipulatedDirectory)
when:
def actual = file.fullPath
then:
actual == expected
where:
manipulatedDirectory || expected
Path.of("") || Path.of(this.fileName)
Path.of("test", "grid") || Path.of("test", "grid", this.fileName)
}
}