1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.shared.utils.logging;
20
21 import java.io.ByteArrayOutputStream;
22 import java.io.PrintStream;
23 import java.nio.charset.StandardCharsets;
24
25 import org.fusesource.jansi.AnsiColors;
26 import org.fusesource.jansi.AnsiConsole;
27 import org.fusesource.jansi.AnsiMode;
28 import org.fusesource.jansi.AnsiPrintStream;
29 import org.fusesource.jansi.AnsiType;
30 import org.fusesource.jansi.io.AnsiOutputStream;
31 import org.junit.Test;
32
33 import static org.hamcrest.CoreMatchers.not;
34 import static org.hamcrest.CoreMatchers.sameInstance;
35 import static org.hamcrest.MatcherAssert.assertThat;
36 import static org.junit.Assert.assertEquals;
37 import static org.junit.Assume.assumeNoException;
38
39 public class MessageUtilsTest {
40 @Test
41 public void testSystem() {
42 PrintStream currentOut = System.out;
43 try {
44 MessageUtils.systemInstall();
45 assertThat(System.out, not(sameInstance(currentOut)));
46 } catch (LinkageError e) {
47 assumeNoException("JAnsi not supported for this platform", e);
48 } finally {
49 try {
50
51
52 MessageUtils.systemUninstall();
53 } catch (Throwable t) {
54
55 }
56 }
57 assertThat(System.out, sameInstance(currentOut));
58 }
59
60 @Test
61 public void testTerminalWidth() {
62 AnsiOutputStream.WidthSupplier width = new AnsiOutputStream.WidthSupplier() {
63 @Override
64 public int getTerminalWidth() {
65 return 33;
66 }
67 };
68 AnsiOutputStream aos = new AnsiOutputStream(
69 new ByteArrayOutputStream(),
70 width,
71 AnsiMode.Default,
72 null,
73 AnsiType.Emulation,
74 AnsiColors.Colors256,
75 StandardCharsets.UTF_8,
76 null,
77 null,
78 false);
79 try {
80 AnsiConsole.systemInstall();
81 AnsiConsole.out = new AnsiPrintStream(aos, true);
82 assertEquals(33, MessageUtils.getTerminalWidth());
83 } catch (LinkageError e) {
84 assumeNoException("JAnsi not supported for this platform", e);
85 } finally {
86 try {
87
88
89 AnsiConsole.systemUninstall();
90 } catch (Throwable t) {
91
92 }
93 }
94 }
95 }