Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/kotlin/util/FileReader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class FileReader : Reader {
var lines: List<String> = emptyList()

try {
lines = File(fileName).readLines()
lines = File(fileName).readLines().filter { it.isNotEmpty() }
} catch (exception: Exception) {
when (exception) {
is FileNotFoundException -> println("Oops! - File not found.")
Expand Down
24 changes: 23 additions & 1 deletion src/test/kotlin/util/FileReaderTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import FileReader
import com.google.common.truth.Truth.assertThat
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.mockkStatic
import org.junit.After
import org.junit.Before
import org.junit.Test
Expand Down Expand Up @@ -56,6 +55,29 @@ class FileReaderTest {
assertThat(result).isEqualTo(expectedOutputString)
}

@Test
fun `readFile() - given file with empty lines then return list of strings of the file's contents data without empty lines`() {
// given
val fileName = "src/test/resources/test_vet_patient_file_with_empty_lines.txt"
val expectedOutputString: ArrayList<String> = arrayListOf(
"customer:1:Sam",
"customer:2:Voicu",
"customer:3:Andre",
"customer:4:Harry",
"pet:1:dog:Barney:1",
"pet:2:cat:Mr Fuzzy:1",
"pet:3:cat:Kitkat:2",
"pet:4:goldfish:Harry:3",
"pet:5:dog:Bob:4"
)

// when
val result = subject.readFile(fileName)

// then
assertThat(result).isEqualTo(expectedOutputString)
}

@Test
fun `readFile() - given file name that does not exist then file not found message is printed`() {
// given
Expand Down