Skip to content
Snippets Groups Projects
Commit 1434b4c3 authored by Sören Henning's avatar Sören Henning
Browse files

Merge branch 'master' into concepts-docs

parents 9d37f3be b15061bb
Branches
Tags
1 merge request!205Add docs for fundamental concepts
...@@ -11,6 +11,7 @@ import org.junit.jupiter.api.Test ...@@ -11,6 +11,7 @@ import org.junit.jupiter.api.Test
import org.junit.rules.TemporaryFolder import org.junit.rules.TemporaryFolder
import org.junitpioneer.jupiter.ClearEnvironmentVariable import org.junitpioneer.jupiter.ClearEnvironmentVariable
import org.junitpioneer.jupiter.SetEnvironmentVariable import org.junitpioneer.jupiter.SetEnvironmentVariable
import java.util.stream.Collectors
const val FOLDER_URL = "Test-Folder" const val FOLDER_URL = "Test-Folder"
...@@ -42,12 +43,13 @@ internal class IOHandlerTest { ...@@ -42,12 +43,13 @@ internal class IOHandlerTest {
temporaryFolder.create() temporaryFolder.create()
val folder = temporaryFolder.newFolder(FOLDER_URL) val folder = temporaryFolder.newFolder(FOLDER_URL)
val columns = listOf("Fruit", "Color")
val testContent = listOf( val testContent = listOf(
listOf("apples", "red"), listOf("apples", "red"),
listOf("bananas", "yellow"), listOf("bananas", "yellow"),
listOf("avocado", "brown") listOf("avocado", "brown")
) )
val columns = listOf("Fruit", "Color")
IOHandler().writeToCSVFile( IOHandler().writeToCSVFile(
fileURL = "${folder.absolutePath}/test-file", fileURL = "${folder.absolutePath}/test-file",
...@@ -65,6 +67,49 @@ internal class IOHandlerTest { ...@@ -65,6 +67,49 @@ internal class IOHandlerTest {
) )
} }
/**
* Tests if values with commas and quotation marks are surrounded with additional quotation marks.
*/
@Test
fun testWriteToCSVFileWithComma() {
temporaryFolder.create()
val folder = temporaryFolder.newFolder(FOLDER_URL)
val columns = listOf("Fruit, Fruit2", "Color")
val expectedColumns = listOf("\"Fruit, Fruit2\"", "Color")
val testContent = listOf(
listOf("apples, "+ '"' + "paprika" + '"', "red"),
listOf("bananas, pineapple", "yellow"),
listOf("avocado, coconut", "brown")
)
val expectedContent = listOf(
listOf("\"apples, " + '"' + '"' + "paprika" + '"' + '"' + '"', "red"),
listOf("\"bananas, pineapple\"", "yellow"),
listOf("\"avocado, coconut\"", "brown")
)
IOHandler().writeToCSVFile(
fileURL = "${folder.absolutePath}/test-file",
data = testContent,
columns = columns
)
// construct string from the columns
var expected = expectedColumns.stream().collect(Collectors.joining(","))
// add values from the expectedContent to expected string
expectedContent.forEach{
expected += "\n" + it.joinToString(separator = ",")
}
assertEquals(
expected,
IOHandler().readFileAsString("${folder.absolutePath}/test-file.csv")
)
}
@Test @Test
fun testWriteToJSONFile() { fun testWriteToJSONFile() {
temporaryFolder.create() temporaryFolder.create()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment