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