Skip to content

Commit c13c5d5

Browse files
committed
fix up remaining tests
1 parent 7cf1e23 commit c13c5d5

8 files changed

Lines changed: 87 additions & 42 deletions

File tree

‎src/main/kotlin/dartzee/logging/LoggingCodes.kt‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,4 @@ val CODE_PULL_ERROR = LoggingCode("pullError")
9393
val CODE_BACKUP_ERROR = LoggingCode("backupError")
9494
val CODE_RESTORE_ERROR = LoggingCode("restoreError")
9595
val CODE_DELETE_ERROR = LoggingCode("deleteError")
96-
val CODE_HYPERLINK_ERROR = LoggingCode("hyperlinkError")
9796
val CODE_EDT_FROZEN = LoggingCode("edtFrozen")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package dartzee.utils
22

3-
const val DARTS_VERSION_NUMBER = "v7.2.0"
3+
const val DARTS_VERSION_NUMBER = "v7.3.0"
44
const val DARTZEE_REPOSITORY_URL = "https://api.github.com/repos/alyssaruth/Dartzee"
55
const val DARTZEE_MANUAL_DOWNLOAD_URL = "https://github.com/alyssaruth/Dartzee/releases"

‎src/main/kotlin/dartzee/utils/CommandUtil.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ private fun execCommand(command: Array<String>, runtime: Runtime) =
3636
runtime.exec(command)
3737
true
3838
} catch (e: Exception) {
39-
logger.error(CODE_EXEC_ERROR, "Command failed", e)
39+
logger.error(CODE_EXEC_ERROR, "Command failed: ${command.joinToString(" ")}", e)
4040
false
4141
}

src/test/kotlin/dartzee/core/util/TestDialogUtil.kt renamed to src/test/kotlin/dartzee/core/util/DialogUtilTest.kt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import com.github.alyssaburlton.swingtest.clickNo
55
import com.github.alyssaburlton.swingtest.clickOk
66
import com.github.alyssaburlton.swingtest.clickYes
77
import com.github.alyssaburlton.swingtest.flushEdt
8+
import com.github.alyssaburlton.swingtest.getChild
89
import com.github.alyssaburlton.swingtest.purgeWindows
10+
import com.github.alyssaburlton.swingtest.shouldBeVisible
911
import dartzee.core.helper.TestMessageDialogFactory
1012
import dartzee.getErrorDialog
1113
import dartzee.getInfoDialog
@@ -21,9 +23,10 @@ import io.mockk.clearAllMocks
2123
import io.mockk.spyk
2224
import io.mockk.verifySequence
2325
import java.io.File
26+
import javax.swing.JLabel
2427
import org.junit.jupiter.api.Test
2528

26-
class TestDialogUtil : AbstractTest() {
29+
class DialogUtilTest : AbstractTest() {
2730
var factoryMock = spyk<TestMessageDialogFactory>()
2831

2932
@Test
@@ -178,4 +181,21 @@ class TestDialogUtil : AbstractTest() {
178181
verifyLog(CODE_DIALOG_CLOSED, Severity.INFO).message shouldBe
179182
"File selector dialog closed - selected ${f.absolutePath}"
180183
}
184+
185+
@Test
186+
fun `Should show a custom error message`() {
187+
val component = JLabel("My custom message")
188+
189+
runAsync { DialogUtil.showCustomError(component) }
190+
191+
val log = verifyLog(CODE_DIALOG_SHOWN)
192+
log.message shouldBe "CustomError dialog shown: ?"
193+
194+
val dlg = getErrorDialog()
195+
dlg.shouldBeVisible()
196+
dlg.getChild<JLabel>(text = "My custom message") shouldBe component
197+
dlg.clickOk(async = true)
198+
199+
verifyLog(CODE_DIALOG_CLOSED).message shouldBe "CustomError dialog closed"
200+
}
181201
}

src/test/kotlin/dartzee/logging/TestLogDestinationElasticsearch.kt renamed to src/test/kotlin/dartzee/logging/LogDestinationElasticsearchTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import java.util.concurrent.TimeUnit
1818
import org.junit.jupiter.api.BeforeEach
1919
import org.junit.jupiter.api.Test
2020

21-
class TestLogDestinationElasticsearch : AbstractTest() {
21+
class LogDestinationElasticsearchTest : AbstractTest() {
2222
@BeforeEach
2323
fun beforeEach() {
2424
DartsClient.devMode = false
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package dartzee.utils
2+
3+
import dartzee.core.helper.verifyNotCalled
4+
import dartzee.helper.AbstractTest
5+
import dartzee.logging.CODE_EXEC_ERROR
6+
import dartzee.logging.Severity
7+
import dartzee.`object`.DartsClient
8+
import io.kotest.matchers.shouldBe
9+
import io.mockk.every
10+
import io.mockk.mockk
11+
import io.mockk.verify
12+
import java.io.IOException
13+
import org.junit.jupiter.api.Test
14+
15+
class CommandUtilTest : AbstractTest() {
16+
@Test
17+
fun `launchUrl should execute the expected command on linux`() {
18+
DartsClient.operatingSystem = "linux"
19+
val runtime = mockk<Runtime>(relaxed = true)
20+
launchUrl("foo.bar", runtime)
21+
22+
verify { runtime.exec(arrayOf("xdg-open", "foo.bar")) }
23+
}
24+
25+
@Test
26+
fun `launchUrl should execute the expected command on Windows`() {
27+
DartsClient.operatingSystem = "windows"
28+
val runtime = mockk<Runtime>(relaxed = true)
29+
launchUrl("google.com", runtime)
30+
31+
verify { runtime.exec(arrayOf("cmd", "/c", "start", "google.com")) }
32+
}
33+
34+
@Test
35+
fun `launchUrl should log an appropriate error if launching the URL fails`() {
36+
DartsClient.operatingSystem = "linux"
37+
val error = IOException("Oops")
38+
39+
val runtime = mockk<Runtime>()
40+
every { runtime.exec(any<Array<String>>()) }.throws(error)
41+
42+
launchUrl("foo.bar", runtime)
43+
44+
val log = verifyLog(CODE_EXEC_ERROR, Severity.ERROR)
45+
log.message shouldBe "Command failed: xdg-open foo.bar"
46+
log.errorObject shouldBe error
47+
}
48+
49+
@Test
50+
fun `runCommand should error for unsupported OS`() {
51+
DartsClient.operatingSystem = "apple"
52+
val runtime = mockk<Runtime>()
53+
54+
runCommand(windows = arrayOf(), linux = arrayOf())
55+
56+
val log = verifyLog(CODE_EXEC_ERROR, Severity.ERROR)
57+
log.message shouldBe "Operating system unsupported: apple"
58+
59+
verifyNotCalled { runtime.exec(any<Array<String>>()) }
60+
}
61+
}

‎src/test/kotlin/dartzee/utils/TestUrlUtil.kt‎

Lines changed: 0 additions & 35 deletions
This file was deleted.

‎src/test/kotlin/dartzee/utils/UpdateManagerTest.kt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ import org.junit.jupiter.api.AfterEach
4646
import org.junit.jupiter.api.BeforeEach
4747
import org.junit.jupiter.api.Test
4848

49-
class UpdateManagerTest : AbstractTest() {
50-
private val TEST_JAR_FILE_NAME = "Dartzee_v7_3_0.jar"
49+
private const val TEST_JAR_FILE_NAME = "Dartzee_v7_3_0.jar"
5150

51+
class UpdateManagerTest : AbstractTest() {
5252
@BeforeEach
5353
fun beforeEach() {
5454
Unirest.config().automaticRetries(false)

0 commit comments

Comments
 (0)