001package org.eclipse.aether.graph;
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 java.util.Arrays;
025import java.util.Collections;
026
027import org.eclipse.aether.artifact.DefaultArtifact;
028import org.eclipse.aether.graph.Dependency;
029import org.eclipse.aether.graph.Exclusion;
030import org.junit.Test;
031
032/**
033 */
034public class DependencyTest
035{
036
037    @Test
038    public void testSetScope()
039    {
040        Dependency d1 = new Dependency( new DefaultArtifact( "gid:aid:ver" ), "compile" );
041
042        Dependency d2 = d1.setScope( null );
043        assertNotSame( d2, d1 );
044        assertEquals( "", d2.getScope() );
045
046        Dependency d3 = d1.setScope( "test" );
047        assertNotSame( d3, d1 );
048        assertEquals( "test", d3.getScope() );
049    }
050
051    @Test
052    public void testSetExclusions()
053    {
054        Dependency d1 =
055            new Dependency( new DefaultArtifact( "gid:aid:ver" ), "compile", false,
056                            Collections.singleton( new Exclusion( "g", "a", "c", "e" ) ) );
057
058        Dependency d2 = d1.setExclusions( null );
059        assertNotSame( d2, d1 );
060        assertEquals( 0, d2.getExclusions().size() );
061
062        assertSame( d2, d2.setExclusions( null ) );
063        assertSame( d2, d2.setExclusions( Collections.<Exclusion> emptyList() ) );
064        assertSame( d2, d2.setExclusions( Collections.<Exclusion> emptySet() ) );
065        assertSame( d1, d1.setExclusions( Arrays.asList( new Exclusion( "g", "a", "c", "e" ) ) ) );
066
067        Dependency d3 =
068            d1.setExclusions( Arrays.asList( new Exclusion( "g", "a", "c", "e" ), new Exclusion( "g", "a", "c", "f" ) ) );
069        assertNotSame( d3, d1 );
070        assertEquals( 2, d3.getExclusions().size() );
071    }
072
073}