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