File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments