Skip to content
Snippets Groups Projects
Commit 941439d6 authored by Inseo Kim's avatar Inseo Kim
Browse files

JUNIT5 has been added in dependencies in all gradle files. Implemented two...

JUNIT5 has been added in dependencies in all gradle files. Implemented two unit tests for file management. Fixed bug.
parent 09fb2b97
No related branches found
No related tags found
1 merge request!8JUNIT5 has been added in dependencies in all gradle files. Implemented two...
Pipeline #83682 failed
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/modules/utilities/notes-multi.utilities.test.iml" filepath="$PROJECT_DIR$/.idea/modules/utilities/notes-multi.utilities.test.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$/../../../utilities/src/test">
<sourceFolder url="file://$MODULE_DIR$/../../../utilities/src/test/kotlin" isTestSource="true" />
</content>
</component>
</module>
\ No newline at end of file
...@@ -9,9 +9,14 @@ plugins { ...@@ -9,9 +9,14 @@ plugins {
dependencies { dependencies {
implementation 'org.apache.commons:commons-text' implementation 'org.apache.commons:commons-text'
implementation project(':utilities') implementation project(':utilities')
testImplementation 'org.jetbrains.kotlin:kotlin-test'
} }
application { application {
// Define the main class for the application. // Define the main class for the application.
mainClass = 'notes.multi.app.AppKt' mainClass = 'notes.multi.app.AppKt'
} }
test {
useJUnitPlatform()
}
...@@ -9,9 +9,14 @@ plugins { ...@@ -9,9 +9,14 @@ plugins {
dependencies { dependencies {
implementation 'org.apache.commons:commons-text' implementation 'org.apache.commons:commons-text'
implementation project(':utilities') implementation project(':utilities')
testImplementation 'org.jetbrains.kotlin:kotlin-test'
} }
application { application {
// Define the main class for the application. // Define the main class for the application.
mainClass = 'notes.multi.console.ConsoleKt' mainClass = 'notes.multi.console.ConsoleKt'
} }
test {
useJUnitPlatform()
}
...@@ -9,6 +9,6 @@ fun main() { ...@@ -9,6 +9,6 @@ fun main() {
// thesea re test functions feel free to use // thesea re test functions feel free to use
val f = Filemanager("${System.getProperty("user.dir")}/test/", "hello.txt") val f = Filemanager("${System.getProperty("user.dir")}/test/", "hello.txt")
f.writefile("hello world") f.writefile("hello world")
println(f.openfile())
f.deletefile() f.deletefile()
println(f.openfile())
} }
...@@ -8,4 +8,9 @@ plugins { ...@@ -8,4 +8,9 @@ plugins {
dependencies { dependencies {
api project(':list') api project(':list')
testImplementation 'org.jetbrains.kotlin:kotlin-test'
}
test {
useJUnitPlatform()
} }
...@@ -24,7 +24,9 @@ class Filemanager(private val dir: String, private val name: String) { ...@@ -24,7 +24,9 @@ class Filemanager(private val dir: String, private val name: String) {
// create and write to that file // create and write to that file
fun writefile(line:String) { fun writefile(line:String) {
filepath.writeText(line) filepath.writeText(line)
listfiles.add(filepath) if (!listfiles.contains(filepath)) {
listfiles.add(filepath)
}
} }
// opens and read the existing file // opens and read the existing file
...@@ -39,6 +41,9 @@ class Filemanager(private val dir: String, private val name: String) { ...@@ -39,6 +41,9 @@ class Filemanager(private val dir: String, private val name: String) {
fun deletefile():Boolean { fun deletefile():Boolean {
listfiles.remove(filepath) listfiles.remove(filepath)
for (i in listfiles) {
println("Not Deleted!")
}
return filepath.delete() return filepath.delete()
} }
......
import notes.multi.utilities.Filemanager
import kotlin.test.Test
import kotlin.test.assertEquals
internal class FilemanagerTest {
private val testmanager: Filemanager = Filemanager("${System.getProperty("user.dir")}/testfolder/", "hello.txt")
@Test
fun createreadfile() {
val expected = "hello from the moon"
testmanager.writefile(expected)
assertEquals(expected, testmanager.openfile())
}
@Test
fun ReadNoneExistingFile() {
val expected = ""
testmanager.writefile("walking to the mooon")
testmanager.deletefile()
assertEquals(expected, testmanager.openfile())
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment