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.building;
20  
21  import org.apache.maven.building.Problem.Severity;
22  import org.junit.Test;
23  
24  import static org.junit.Assert.*;
25  
26  public class DefaultProblemCollectorTest {
27  
28      @Test
29      public void testGetProblems() {
30          DefaultProblemCollector collector = new DefaultProblemCollector(null);
31          assertNotNull(collector.getProblems());
32          assertEquals(0, collector.getProblems().size());
33  
34          collector.add(null, "MESSAGE1", -1, -1, null);
35  
36          Exception e2 = new Exception();
37          collector.add(Severity.WARNING, null, 42, 127, e2);
38  
39          assertEquals(2, collector.getProblems().size());
40  
41          Problem p1 = collector.getProblems().get(0);
42          assertEquals(Severity.ERROR, p1.getSeverity());
43          assertEquals("MESSAGE1", p1.getMessage());
44          assertEquals(-1, p1.getLineNumber());
45          assertEquals(-1, p1.getColumnNumber());
46          assertEquals(null, p1.getException());
47  
48          Problem p2 = collector.getProblems().get(1);
49          assertEquals(Severity.WARNING, p2.getSeverity());
50          assertEquals("", p2.getMessage());
51          assertEquals(42, p2.getLineNumber());
52          assertEquals(127, p2.getColumnNumber());
53          assertEquals(e2, p2.getException());
54      }
55  
56      @Test
57      public void testSetSource() {
58          DefaultProblemCollector collector = new DefaultProblemCollector(null);
59  
60          collector.add(null, "PROBLEM1", -1, -1, null);
61  
62          collector.setSource("SOURCE_PROBLEM2");
63          collector.add(null, "PROBLEM2", -1, -1, null);
64  
65          collector.setSource("SOURCE_PROBLEM3");
66          collector.add(null, "PROBLEM3", -1, -1, null);
67  
68          assertEquals("", collector.getProblems().get(0).getSource());
69          assertEquals("SOURCE_PROBLEM2", collector.getProblems().get(1).getSource());
70          assertEquals("SOURCE_PROBLEM3", collector.getProblems().get(2).getSource());
71      }
72  }