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