diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000000000000000000000000000000000..722074489e1d19681e8975994651dae27db5d04c --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ +<?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 diff --git a/.idea/modules/utilities/notes-multi.utilities.test.iml b/.idea/modules/utilities/notes-multi.utilities.test.iml new file mode 100644 index 0000000000000000000000000000000000000000..65dae19c0cb2191c9d0255b97108d2e98e82af99 --- /dev/null +++ b/.idea/modules/utilities/notes-multi.utilities.test.iml @@ -0,0 +1,8 @@ +<?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 diff --git a/app/build.gradle b/app/build.gradle index e3faad056eb2390ff78039897637542cf6a1ccf3..840aa75f42249103a31becad6046c1888ab19a28 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,9 +9,14 @@ plugins { dependencies { implementation 'org.apache.commons:commons-text' implementation project(':utilities') + testImplementation 'org.jetbrains.kotlin:kotlin-test' } application { // Define the main class for the application. mainClass = 'notes.multi.app.AppKt' } + +test { + useJUnitPlatform() +} diff --git a/console/build.gradle b/console/build.gradle index 178bd493e8aed27bce9c68c5bc14fca31348e36f..127f593824197af01f3a9e31f4d01936d3ab1075 100644 --- a/console/build.gradle +++ b/console/build.gradle @@ -9,9 +9,14 @@ plugins { dependencies { implementation 'org.apache.commons:commons-text' implementation project(':utilities') + testImplementation 'org.jetbrains.kotlin:kotlin-test' } application { // Define the main class for the application. mainClass = 'notes.multi.console.ConsoleKt' } + +test { + useJUnitPlatform() +} diff --git a/console/src/main/kotlin/notes/multi/console/Console.kt b/console/src/main/kotlin/notes/multi/console/Console.kt index 647d1178b19daebe105acb5b7707e80039ff778a..7db3c2789822e1b85a45bc11572aec029ae85610 100644 --- a/console/src/main/kotlin/notes/multi/console/Console.kt +++ b/console/src/main/kotlin/notes/multi/console/Console.kt @@ -9,6 +9,6 @@ fun main() { // thesea re test functions feel free to use val f = Filemanager("${System.getProperty("user.dir")}/test/", "hello.txt") f.writefile("hello world") - println(f.openfile()) f.deletefile() + println(f.openfile()) } diff --git a/utilities/build.gradle b/utilities/build.gradle index 7ebfb8eb68c9be1d1ee2ed7b1043ebf86be3cfa2..5a6881d1afdb290ec1fc2c78b118e800181572cb 100644 --- a/utilities/build.gradle +++ b/utilities/build.gradle @@ -8,4 +8,9 @@ plugins { dependencies { api project(':list') + testImplementation 'org.jetbrains.kotlin:kotlin-test' +} + +test { + useJUnitPlatform() } diff --git a/utilities/src/main/kotlin/notes/multi/utilities/Filemanager.kt b/utilities/src/main/kotlin/notes/multi/utilities/Filemanager.kt index 0f0e3bd365cc4f7645a5a07e41d15fd78371f4e5..2551ace5612a977214bad565de342e45c8e6c3aa 100644 --- a/utilities/src/main/kotlin/notes/multi/utilities/Filemanager.kt +++ b/utilities/src/main/kotlin/notes/multi/utilities/Filemanager.kt @@ -24,7 +24,9 @@ class Filemanager(private val dir: String, private val name: String) { // create and write to that file fun writefile(line:String) { filepath.writeText(line) - listfiles.add(filepath) + if (!listfiles.contains(filepath)) { + listfiles.add(filepath) + } } // opens and read the existing file @@ -39,6 +41,9 @@ class Filemanager(private val dir: String, private val name: String) { fun deletefile():Boolean { listfiles.remove(filepath) + for (i in listfiles) { + println("Not Deleted!") + } return filepath.delete() } diff --git a/utilities/src/test/kotlin/FilemanagerTest.kt b/utilities/src/test/kotlin/FilemanagerTest.kt new file mode 100644 index 0000000000000000000000000000000000000000..e2eb36a473a7eb30a3036eec56f87ec3471e3f7b --- /dev/null +++ b/utilities/src/test/kotlin/FilemanagerTest.kt @@ -0,0 +1,22 @@ +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 diff --git a/utilities/testfolder/idontknow b/utilities/testfolder/idontknow new file mode 100644 index 0000000000000000000000000000000000000000..6ed2b153b6c03b0dc15127d5b69aa83fb7676500 --- /dev/null +++ b/utilities/testfolder/idontknow @@ -0,0 +1 @@ +blahblah \ No newline at end of file