1 package org.apache.maven.toolchain.building;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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.lineSeparator();
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 }