View Javadoc
1   package org.apache.maven.toolchain.building;
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 static org.junit.Assert.assertEquals;
23  
24  import java.util.Collections;
25  
26  import org.apache.maven.building.Problem;
27  import org.apache.maven.building.ProblemCollector;
28  import org.apache.maven.building.ProblemCollectorFactory;
29  import org.junit.Test;
30  
31  public class ToolchainsBuildingExceptionTest
32  {
33      private static final String LS = System.getProperty( "line.separator" );
34  
35      @Test
36      public void testNoProblems()
37      {
38          ToolchainsBuildingException e = new ToolchainsBuildingException( Collections.<Problem>emptyList() );
39          assertEquals( "0 problems were encountered while building the effective toolchains" + LS, e.getMessage() );
40      }
41  
42      @Test
43      public void testOneProblem()
44      {
45          ProblemCollector problemCollector = ProblemCollectorFactory.newInstance( null );
46          problemCollector.add( Problem.Severity.ERROR, "MESSAGE", 3, 5, new Exception() );
47          ToolchainsBuildingException e = new ToolchainsBuildingException( problemCollector.getProblems() );
48          assertEquals( "1 problem was encountered while building the effective toolchains" + LS +
49                        "[ERROR] MESSAGE @ line 3, column 5" + LS, e.getMessage() );
50      }
51  
52      @Test
53      public void testUnknownPositionAndSource()
54      {
55          ProblemCollector problemCollector = ProblemCollectorFactory.newInstance( null );
56          problemCollector.add( Problem.Severity.ERROR, "MESSAGE", -1, -1, new Exception() );
57          ToolchainsBuildingException e = new ToolchainsBuildingException( problemCollector.getProblems() );
58          assertEquals( "1 problem was encountered while building the effective toolchains" + LS +
59                        "[ERROR] MESSAGE" + LS, e.getMessage() );
60      }
61  
62      @Test
63      public void testUnknownPosition()
64      {
65          ProblemCollector problemCollector = ProblemCollectorFactory.newInstance( null );
66          problemCollector.setSource( "SOURCE" );
67          problemCollector.add( Problem.Severity.ERROR, "MESSAGE", -1, -1, new Exception() );
68          ToolchainsBuildingException e = new ToolchainsBuildingException( problemCollector.getProblems() );
69          assertEquals( "1 problem was encountered while building the effective toolchains" + LS +
70                        "[ERROR] MESSAGE @ SOURCE" + LS, e.getMessage() );
71      }
72  
73  }