View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.shared.utils.logging;
20  
21  import org.junit.Before;
22  import org.junit.Test;
23  
24  import static org.hamcrest.CoreMatchers.equalTo;
25  import static org.hamcrest.MatcherAssert.assertThat;
26  
27  public class AnsiMessageBuilderTest {
28  
29      private AnsiMessageBuilder ansiMessageBuilder;
30  
31      @Before
32      public void initializeAnsiMessageBuffer() {
33          this.ansiMessageBuilder = new AnsiMessageBuilder();
34      }
35  
36      @Test
37      public void should_color_debug() {
38          ansiMessageBuilder.debug("DEBUG");
39  
40          assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[1;36mDEBUG\u001B[m"));
41      }
42  
43      @Test
44      public void should_color_info() {
45          ansiMessageBuilder.info("INFO");
46  
47          assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[1;34mINFO\u001B[m"));
48      }
49  
50      @Test
51      public void should_color_warning_and_reset() {
52          ansiMessageBuilder.warning("WARNING");
53  
54          assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[1;33mWARNING\u001B[m"));
55      }
56  
57      @Test
58      public void should_color_error() {
59          ansiMessageBuilder.error("ERROR");
60  
61          assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[1;31mERROR\u001B[m"));
62      }
63  
64      @Test
65      public void should_color_success_with_message() {
66          ansiMessageBuilder.success("a success message");
67  
68          assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[1;32ma success message\u001B[m"));
69      }
70  
71      @Test
72      public void should_color_failure_and_reset() {
73          ansiMessageBuilder.failure("a failure message");
74  
75          assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[1;31ma failure message\u001B[m"));
76      }
77  
78      @Test
79      public void should_color_strong_and_reset() {
80          ansiMessageBuilder.strong("a strong message");
81  
82          assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[1ma strong message\u001B[m"));
83      }
84  
85      @Test
86      public void should_color_mojo_and_reset() {
87          ansiMessageBuilder.mojo("a mojo");
88  
89          assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[32ma mojo\u001B[m"));
90      }
91  
92      @Test
93      public void should_color_project_and_reset() {
94          ansiMessageBuilder.project("a project");
95  
96          assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[36ma project\u001B[m"));
97      }
98  }