Skip to content

Commit 30718d8

Browse files
committed
showWarning test and showTrace test
1 parent c17d540 commit 30718d8

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

app/test/processing/app/MessagesTest.kt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,24 @@ class MessagesTest {
2323

2424
@Test
2525
fun showWarning() {
26+
val baseMock = mockStatic(Base::class.java)
2627

28+
baseMock.`when`<Boolean> { Base.isCommandLine() }.thenReturn(true)
29+
30+
val out = ByteArrayOutputStream()
31+
val err = ByteArrayOutputStream()
32+
33+
System.setOut(PrintStream(out))
34+
System.setErr(PrintStream(err))
35+
36+
val ex = RuntimeException("test")
37+
38+
Messages.showWarning("Warning", "Something happened", ex)
39+
40+
assertTrue(out.toString().contains("Warning: Something happened"))
41+
assertTrue(err.toString().contains("test"))
42+
43+
baseMock.close()
2744
}
2845

2946
@Test
@@ -44,6 +61,21 @@ class MessagesTest {
4461

4562
@Test
4663
fun showTrace() {
64+
mockStatic(Base::class.java).use { baseMock ->
65+
baseMock.`when`<Boolean> { Base.isCommandLine() }.thenReturn(true)
66+
67+
val err = ByteArrayOutputStream()
68+
System.setErr(PrintStream(err))
69+
70+
val ex = RuntimeException("boom")
71+
72+
Messages.showTrace("Title", "Something broke", ex, false)
73+
74+
val output = err.toString()
75+
76+
assertTrue(output.contains("Title: Something broke"))
77+
assertTrue(output.contains("boom"))
78+
}
4779
}
4880

4981
@Test

0 commit comments

Comments
 (0)