Skip to content

Commit

Permalink
Added Test Cases for CommandExecutor
Browse files Browse the repository at this point in the history
Updated kotlin_lint.yml
Fixed Lint Errors
  • Loading branch information
iammohdzaki committed Mar 9, 2024
1 parent ee1dc9e commit 4dbaaf2
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/kotlin_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: kotlin_lint

on:
push:
branches:
branches-ignore:
- "*"
pull_request:
paths:
Expand Down
6 changes: 3 additions & 3 deletions src/jvmMain/kotlin/command/CommandBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ class CommandBuilder {
fun keyAlias(alias: String) = apply { this.keyAlias = alias }
fun keyPassword(password: String) = apply { this.keyPassword = password }

fun verifyAdbPath(value: Boolean, path: String) = apply { this.adbVerifyCommandExecute = Pair(value,path) }
fun verifyAdbPath(value: Boolean, path: String) = apply { this.adbVerifyCommandExecute = Pair(value, path) }

fun getAdbVerifyCommand(): String {
val (forVerify,path) = adbVerifyCommandExecute
if (forVerify){
val (forVerify, path) = adbVerifyCommandExecute
if (forVerify) {
return "\"${path}\" version"
}
return ""
Expand Down
3 changes: 1 addition & 2 deletions src/jvmMain/kotlin/command/CommandExecutor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CommandExecutor {
onSuccess: (String) -> Unit,
onFailure: (Throwable) -> Unit
) {
coroutineScope.launch(Dispatchers.IO){
coroutineScope.launch(Dispatchers.IO) {
try {
val runtime = Runtime.getRuntime()
val startTime = System.currentTimeMillis()
Expand Down Expand Up @@ -51,5 +51,4 @@ class CommandExecutor {
}
}
}

}
2 changes: 1 addition & 1 deletion src/jvmMain/kotlin/local/FileStorageHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class FileStorageHelper {
init {
initializeDir()
}

private fun getKryo(): Kryo {
return if (this::kryo.isInitialized) {
kryo
Expand Down Expand Up @@ -71,5 +72,4 @@ class FileStorageHelper {
false
}
}

}
1 change: 0 additions & 1 deletion src/jvmMain/kotlin/local/KiteDbException.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ class KiteDbException : RuntimeException {
constructor(detailMessage: String?) : super(detailMessage)

constructor(detailMessage: String?, throwable: Throwable?) : super(detailMessage, throwable)

}
6 changes: 3 additions & 3 deletions src/jvmMain/kotlin/ui/Typography.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import androidx.compose.ui.unit.sp

val codeFontFamily = FontFamily(
Font(resource = "fonts/sans_regular.ttf", weight = FontWeight.Light),
Font( resource = "fonts/sans_thin.ttf", weight = FontWeight.Normal),
Font( resource = "fonts/sans_medium.ttf", weight = FontWeight.Medium),
Font( resource = "fonts/sans_bold.ttf", weight = FontWeight.Bold)
Font(resource = "fonts/sans_thin.ttf", weight = FontWeight.Normal),
Font(resource = "fonts/sans_medium.ttf", weight = FontWeight.Medium),
Font(resource = "fonts/sans_bold.ttf", weight = FontWeight.Bold)
)

val typography = Typography(
Expand Down
11 changes: 7 additions & 4 deletions src/jvmMain/kotlin/ui/components/LoadingDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ package ui.components

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.Surface
Expand Down Expand Up @@ -45,13 +50,11 @@ fun LoadingDialog(text: String) {
Text(
text = text,
style = Styles.TextStyleBold(20.sp),
modifier = Modifier.padding(start = 8.dp,end = 8.dp, bottom = 8.dp)
modifier = Modifier.padding(start = 8.dp, end = 8.dp, bottom = 8.dp)
)
CircularProgressIndicator()
}
}
}

}

}
3 changes: 1 addition & 2 deletions src/jvmMain/kotlin/utils/Constant.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ object FileDialogType {
object SigningMode {
const val DEBUG = 1
const val RELEASE = 2
}

}
6 changes: 4 additions & 2 deletions src/jvmMain/kotlin/utils/FileHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ object FileHelper {
Log.i("CHANGED NAME\n Unzipping...")
try {
FileUtils.unzip(newFile, directory)
fileStatus.invoke(Constant.SUCCESS, "Rename and Unzip Successful\nFile Saved at ${directory.removeSuffix("\\")}.")
fileStatus.invoke(
Constant.SUCCESS,
"Rename and Unzip Successful\nFile Saved at ${directory.removeSuffix("\\")}."
)
Log.i("TRYING DELETING FILE")
val value = FileUtils.deleteFile(newFile)
Log.i("DELETE STATUS : $value")
Expand All @@ -25,5 +28,4 @@ object FileHelper {
fileStatus.invoke(Constant.FAILURE, "FAILED RENAMING THE FILE!!")
}
}

}
8 changes: 5 additions & 3 deletions src/jvmMain/kotlin/utils/FileUtils.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package utils

import java.io.*
import java.io.BufferedOutputStream
import java.io.File
import java.io.IOException
import java.io.InputStream
import java.io.FileOutputStream
import java.util.zip.ZipFile

object FileUtils {
Expand All @@ -13,7 +17,6 @@ object FileUtils {
fun deleteFile(file: File) =
file.delete()


/**
* @param oldFile
* @param newFile
Expand Down Expand Up @@ -72,5 +75,4 @@ object FileUtils {
}
bos.close()
}

}
5 changes: 2 additions & 3 deletions src/jvmMain/kotlin/utils/Utils.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package utils

import java.util.*
import java.util.Locale

object Utils {

fun isWindowsOS(): Boolean{
fun isWindowsOS(): Boolean {
return System.getProperty("os.name").lowercase(Locale.getDefault()).contains("windows")
}

}
55 changes: 55 additions & 0 deletions src/jvmTest/kotlin/command/CommandExecutorTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package command

import junit.framework.TestCase.assertTrue
import kotlinx.coroutines.runBlocking
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Before
import org.junit.Test

class CommandExecutorTest {
private lateinit var commandExecutor: CommandExecutor

@Before
fun setUp() {
commandExecutor = CommandExecutor()
}

// These test cases may not work for MAC and Linux need to verify.
@Test
fun `execute valid command successfully`() {
val expectedOutput = "openjdk 11.0.18 2023-01-17"
val cmd = "java --version"

runBlocking {
commandExecutor.executeCommand(
cmd,
this,
onSuccess = {
println("SUCCESS -> $it")
assertThat(expectedOutput, it.contains(expectedOutput))
},
onFailure = {
println("ERROR -> ${it.message}")
assertThat(expectedOutput, it.message?.contains(expectedOutput) ?: false)
}
)
}
}

@Test
fun `execute invalid command and handle failure`() {
val cmd = "invalid_command"
runBlocking {
commandExecutor.executeCommand(
cmd,
this,
onSuccess = {
assertTrue(it.isEmpty())
},
onFailure = {
assertTrue(it.message?.contains("The system cannot find the file specified") ?: false)
}
)
}
}
}
7 changes: 5 additions & 2 deletions src/jvmTest/kotlin/ui/components/CheckboxWithTextTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.test.*
import androidx.compose.ui.test.assertIsOff
import androidx.compose.ui.test.assertIsOn
import androidx.compose.ui.test.assertTextEquals
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import org.junit.Rule
import org.junit.Test
import utils.TestTags
Expand Down Expand Up @@ -57,5 +61,4 @@ class CheckboxWithTextTest {
checkbox.performClick()
checkbox.assertIsOff()
}

}

0 comments on commit 4dbaaf2

Please sign in to comment.