001package org.eclipse.aether.util.filter; 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.LinkedList; 026import java.util.List; 027 028import org.eclipse.aether.graph.DependencyNode; 029import org.eclipse.aether.internal.test.util.NodeBuilder; 030import org.eclipse.aether.util.filter.ScopeDependencyFilter; 031import org.junit.Test; 032 033public class ScopeDependencyFilterTest 034 extends AbstractDependencyFilterTest 035{ 036 037 @Test 038 public void acceptTest() 039 { 040 041 NodeBuilder builder = new NodeBuilder(); 042 builder.scope( "compile" ).artifactId( "test" ); 043 List<DependencyNode> parents = new LinkedList<>(); 044 045 // null or empty 046 assertTrue( new ScopeDependencyFilter( null, null ).accept( builder.build(), parents ) ); 047 assertTrue( new ScopeDependencyFilter( new LinkedList<String>(), new LinkedList<String>() ).accept( builder.build(), 048 parents ) ); 049 assertTrue( new ScopeDependencyFilter( (String[]) null ).accept( builder.build(), parents ) ); 050 051 // only excludes 052 assertTrue( new ScopeDependencyFilter( "test" ).accept( builder.build(), parents ) ); 053 assertFalse( new ScopeDependencyFilter( "compile" ).accept( builder.build(), parents ) ); 054 assertFalse( new ScopeDependencyFilter( "compile", "test" ).accept( builder.build(), parents ) ); 055 056 // Both 057 String[] excludes1 = { "provided" }; 058 String[] includes1 = { "compile", "test" }; 059 assertTrue( new ScopeDependencyFilter( Arrays.asList( includes1 ), Arrays.asList( excludes1 ) ).accept( builder.build(), 060 parents ) ); 061 assertTrue( new ScopeDependencyFilter( Arrays.asList( includes1 ), null ).accept( builder.build(), parents ) ); 062 063 // exclude wins 064 String[] excludes2 = { "compile" }; 065 String[] includes2 = { "compile" }; 066 assertFalse( new ScopeDependencyFilter( Arrays.asList( includes2 ), Arrays.asList( excludes2 ) ).accept( builder.build(), 067 parents ) ); 068 069 } 070 071}