Last active
October 27, 2022 14:29
-
-
Save michmzr/bec858eb65038269a4c4cff43d5ab051 to your computer and use it in GitHub Desktop.
Spock test utils
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.json.JSONObject | |
import spock.lang.Specification | |
import java.nio.charset.StandardCharsets | |
import java.nio.file.Files | |
import java.nio.file.Path | |
import java.nio.file.Paths | |
class BaseTestSpec extends Specification { | |
String loadFile(String classPath) throws IOException { | |
Path resourceDirectory = Paths.get("src", "test", "resources"); | |
String absolutePath = resourceDirectory.toFile().getAbsolutePath() | |
Files.readString(Paths.get(absolutePath, classPath), StandardCharsets.UTF_8) | |
} | |
String loadJsonFile(String classPath) { | |
parseJSONFile(classPath).toString() | |
} | |
JSONObject parseJSONFile(String classPath) throws IOException { | |
parseJsonString(loadFile(classPath)) | |
} | |
JSONObject parseJsonString(String string) { | |
new JSONObject(string) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment