001package org.apache.maven.toolchain.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.assertEquals;
023
024import java.util.Collections;
025
026import org.apache.maven.building.Problem;
027import org.apache.maven.building.ProblemCollector;
028import org.apache.maven.building.ProblemCollectorFactory;
029import org.junit.Test;
030
031public class ToolchainsBuildingExceptionTest
032{
033    private static final String LS = System.getProperty( "line.separator" );
034
035    @Test
036    public void testNoProblems()
037    {
038        ToolchainsBuildingException e = new ToolchainsBuildingException( Collections.<Problem>emptyList() );
039        assertEquals( "0 problems were encountered while building the effective toolchains" + LS, e.getMessage() );
040    }
041
042    @Test
043    public void testOneProblem()
044    {
045        ProblemCollector problemCollector = ProblemCollectorFactory.newInstance( null );
046        problemCollector.add( Problem.Severity.ERROR, "MESSAGE", 3, 5, new Exception() );
047        ToolchainsBuildingException e = new ToolchainsBuildingException( problemCollector.getProblems() );
048        assertEquals( "1 problem was encountered while building the effective toolchains" + LS +
049                      "[ERROR] MESSAGE @ line 3, column 5" + LS, e.getMessage() );
050    }
051
052    @Test
053    public void testUnknownPositionAndSource()
054    {
055        ProblemCollector problemCollector = ProblemCollectorFactory.newInstance( null );
056        problemCollector.add( Problem.Severity.ERROR, "MESSAGE", -1, -1, new Exception() );
057        ToolchainsBuildingException e = new ToolchainsBuildingException( problemCollector.getProblems() );
058        assertEquals( "1 problem was encountered while building the effective toolchains" + LS +
059                      "[ERROR] MESSAGE" + LS, e.getMessage() );
060    }
061
062    @Test
063    public void testUnknownPosition()
064    {
065        ProblemCollector problemCollector = ProblemCollectorFactory.newInstance( null );
066        problemCollector.setSource( "SOURCE" );
067        problemCollector.add( Problem.Severity.ERROR, "MESSAGE", -1, -1, new Exception() );
068        ToolchainsBuildingException e = new ToolchainsBuildingException( problemCollector.getProblems() );
069        assertEquals( "1 problem was encountered while building the effective toolchains" + LS +
070                      "[ERROR] MESSAGE @ SOURCE" + LS, e.getMessage() );
071    }
072
073}