001package org.apache.maven.building;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import static org.junit.Assert.*;
023
024import org.apache.maven.building.Problem.Severity;
025import org.junit.Test;
026
027public class DefaultProblemCollectorTest
028{
029
030    @Test
031    public void testGetProblems()
032    {
033        DefaultProblemCollector collector = new DefaultProblemCollector( null );
034        assertNotNull( collector.getProblems() );
035        assertEquals( 0, collector.getProblems().size() );
036
037        collector.add( null, "MESSAGE1", -1, -1, null );
038        
039        Exception e2 = new Exception();
040        collector.add( Severity.WARNING, null, 42, 127, e2 );
041        
042        assertEquals( 2, collector.getProblems().size() );
043
044        Problem p1 = collector.getProblems().get(0);
045        assertEquals( Severity.ERROR, p1.getSeverity() );
046        assertEquals( "MESSAGE1",p1.getMessage() );
047        assertEquals( -1, p1.getLineNumber() );
048        assertEquals( -1, p1.getColumnNumber() );
049        assertEquals( null, p1.getException() );
050        
051        Problem p2 = collector.getProblems().get(1);
052        assertEquals( Severity.WARNING, p2.getSeverity() );
053        assertEquals( "",p2.getMessage() );
054        assertEquals( 42, p2.getLineNumber() );
055        assertEquals( 127, p2.getColumnNumber() );
056        assertEquals( e2, p2.getException() );
057    }
058
059    @Test
060    public void testSetSource()
061    {
062        DefaultProblemCollector collector = new DefaultProblemCollector( null );
063        
064        collector.add( null, "PROBLEM1", -1, -1, null );
065
066        collector.setSource( "SOURCE_PROBLEM2" );
067        collector.add( null, "PROBLEM2", -1, -1, null );
068
069        collector.setSource( "SOURCE_PROBLEM3" );
070        collector.add( null, "PROBLEM3", -1, -1, null );
071
072        assertEquals( "", collector.getProblems().get( 0 ).getSource() );
073        assertEquals( "SOURCE_PROBLEM2", collector.getProblems().get( 1 ).getSource() );
074        assertEquals( "SOURCE_PROBLEM3", collector.getProblems().get( 2 ).getSource() );
075    }
076}