de.codecentric.hikaku.extensions.PathExtensions.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hikaku-core Show documentation
Show all versions of hikaku-core Show documentation
A library that tests if the implementation of a REST-API meets its specification. This module contains the core elements which can be used to create additional converters and reporters.
package de.codecentric.hikaku.extensions
import java.nio.file.Files
import java.nio.file.Path
fun Path.nameWithoutExtension() = fileName.toString().substringBeforeLast(".")
fun Path.extension() = fileName.toString().substringAfterLast(".")
fun Path.checkFileValidity(vararg extensions: String) {
if (!Files.exists(this)) {
throw IllegalArgumentException("Given file does not exist.")
}
if (!Files.isRegularFile(this)) {
throw IllegalArgumentException("Given file is not a regular file.")
}
if (extensions.isNotEmpty()) {
extensions.map {it.substringAfter('.') }
.filter { this.extension() == it }
.ifEmpty { throw IllegalArgumentException("Given file is not of type ${extensions.joinToString()}") }
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy