Skip to content

Commit

Permalink
Directory String to Path
Browse files Browse the repository at this point in the history
  • Loading branch information
augustearth committed Nov 11, 2022
1 parent 542bcfd commit 0b9c719
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ class VineConfiguration {
static public VineConfiguration defaultConfiguration() {
Path currentRelativePath = Paths.get("");
Path cachePath = currentRelativePath.resolve(CACHE_PATH_DEFAULT)
String cachePathString = cachePath.toAbsolutePath().toString()

VineConfiguration config = new VineConfiguration()
config.cache.directory = cachePathString
config.cache.directory = cachePath

return config
}
Expand All @@ -39,7 +38,7 @@ class VineConfiguration {
@ToString(includeNames=true)
static class Cache {
CacheMode mode = CacheMode.IGNORE
String directory
Path directory
Boolean directoryCreateIfNotPresent = true
}
Cache cache = new Cache()
Expand Down Expand Up @@ -67,9 +66,7 @@ class VineConfiguration {
*
*/
public File getCacheDirectory() {
String dirPathString = cache.directory
assert dirPathString != null
Path relativePath = Paths.get(dirPathString.trim())
return relativePath.toFile()
assert cache.directory != null
return cache.directory.toFile()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ abstract class VineMethod {
}

void _cacheDirectoryInitialize() {
Path cachePath = Paths.get(vineConfiguration.cache.directory)
Path cachePath = vineConfiguration.cache.directory
if (cachePath == null) throw new RuntimeException("cachePath is null")

def assertDirectoryAttributes = { Path dirPath ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,11 @@ class JsonVineSpec extends Specification {
def "custom cache directory"() {
when:
def vine = new JvsTestVineDefault()
vine.vineConfiguration.cache.directory += "2"
Path cacheDirPath = Paths.get(vine.vineConfiguration.cache.directory)
vine.vineConfiguration.cache.directory = Paths.get(vine.vineConfiguration.cache.directory.toString() + "2")
Path cacheDirPath = vine.vineConfiguration.cache.directory

then:
vine.vineConfiguration.cache.directory.endsWith("2")
vine.vineConfiguration.cache.directory.toString().endsWith("2")
!Files.exists(cacheDirPath)

when:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SomeVineMethod extends VineMethod {
static VineConfiguration EXAMPLE_CONFIG = new VineConfiguration(
cache: new VineConfiguration.Cache(
mode: CacheMode.REQUIRED,
directory: '/path/to/directory',
directory: Paths.get('/path/to/directory'),
directoryCreateIfNotPresent: false
)
)
Expand Down Expand Up @@ -44,7 +44,7 @@ class VineMethodSpec extends Specification {
then:
vm.vineConfiguration == SomeVineMethod.EXAMPLE_CONFIG
vm.vineConfiguration.cache.mode == CacheMode.REQUIRED
vm.vineConfiguration.cache.directory == '/path/to/directory'
vm.vineConfiguration.cache.directory == Paths.get('/path/to/directory')
vm.vineConfiguration.cache.directoryCreateIfNotPresent == false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ class VsVineWithConfig implements Vine {
static VineConfiguration EXAMPLE_CONFIG = new VineConfiguration(
cache: new VineConfiguration.Cache(
mode: CacheMode.REQUIRED,
directory: '/path/to/directory',
directory: Paths.get('/path/to/directory'),
directoryCreateIfNotPresent: false
)
)

VineConfiguration vineConfiguration = EXAMPLE_CONFIG
public VsVineWithConfig() {
this.vineConfiguration = EXAMPLE_CONFIG
}

@ToString(includeNames=true)
static class Person { String name }
Expand All @@ -45,7 +47,7 @@ class VineSpec extends Specification {
then:
vine.vineConfiguration == VsVineWithConfig.EXAMPLE_CONFIG
vine.vineConfiguration.cache.mode == CacheMode.REQUIRED
vine.vineConfiguration.cache.directory == '/path/to/directory'
vine.vineConfiguration.cache.directory == Paths.get('/path/to/directory')
vine.vineConfiguration.cache.directoryCreateIfNotPresent == false
}

Expand Down

0 comments on commit 0b9c719

Please sign in to comment.