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.Collections; 025import java.util.List; 026 027import org.eclipse.aether.graph.DependencyFilter; 028import org.eclipse.aether.graph.DependencyNode; 029import org.eclipse.aether.internal.test.util.NodeBuilder; 030import org.eclipse.aether.util.filter.DependencyFilterUtils; 031import org.junit.Test; 032 033/** 034 */ 035public class DependencyFilterUtilsTest 036{ 037 038 private static List<DependencyNode> PARENTS = Collections.emptyList(); 039 040 @Test 041 public void testClasspathFilterCompile() 042 { 043 NodeBuilder builder = new NodeBuilder().artifactId( "aid" ); 044 DependencyFilter filter = DependencyFilterUtils.classpathFilter( "compile" ); 045 046 assertTrue( filter.accept( builder.scope( "compile" ).build(), PARENTS ) ); 047 assertTrue( filter.accept( builder.scope( "system" ).build(), PARENTS ) ); 048 assertTrue( filter.accept( builder.scope( "provided" ).build(), PARENTS ) ); 049 assertFalse( filter.accept( builder.scope( "runtime" ).build(), PARENTS ) ); 050 assertFalse( filter.accept( builder.scope( "test" ).build(), PARENTS ) ); 051 } 052 053 @Test 054 public void testClasspathFilterRuntime() 055 { 056 NodeBuilder builder = new NodeBuilder().artifactId( "aid" ); 057 DependencyFilter filter = DependencyFilterUtils.classpathFilter( "runtime" ); 058 059 assertTrue( filter.accept( builder.scope( "compile" ).build(), PARENTS ) ); 060 assertFalse( filter.accept( builder.scope( "system" ).build(), PARENTS ) ); 061 assertFalse( filter.accept( builder.scope( "provided" ).build(), PARENTS ) ); 062 assertTrue( filter.accept( builder.scope( "runtime" ).build(), PARENTS ) ); 063 assertFalse( filter.accept( builder.scope( "test" ).build(), PARENTS ) ); 064 } 065 066 @Test 067 public void testClasspathFilterTest() 068 { 069 NodeBuilder builder = new NodeBuilder().artifactId( "aid" ); 070 DependencyFilter filter = DependencyFilterUtils.classpathFilter( "test" ); 071 072 assertTrue( filter.accept( builder.scope( "compile" ).build(), PARENTS ) ); 073 assertTrue( filter.accept( builder.scope( "system" ).build(), PARENTS ) ); 074 assertTrue( filter.accept( builder.scope( "provided" ).build(), PARENTS ) ); 075 assertTrue( filter.accept( builder.scope( "runtime" ).build(), PARENTS ) ); 076 assertTrue( filter.accept( builder.scope( "test" ).build(), PARENTS ) ); 077 } 078 079 @Test 080 public void testClasspathFilterCompileRuntime() 081 { 082 NodeBuilder builder = new NodeBuilder().artifactId( "aid" ); 083 DependencyFilter filter = DependencyFilterUtils.classpathFilter( "compile", "runtime" ); 084 085 assertTrue( filter.accept( builder.scope( "compile" ).build(), PARENTS ) ); 086 assertTrue( filter.accept( builder.scope( "system" ).build(), PARENTS ) ); 087 assertTrue( filter.accept( builder.scope( "provided" ).build(), PARENTS ) ); 088 assertTrue( filter.accept( builder.scope( "runtime" ).build(), PARENTS ) ); 089 assertFalse( filter.accept( builder.scope( "test" ).build(), PARENTS ) ); 090 } 091 092 @Test 093 public void testClasspathFilterCompilePlusRuntime() 094 { 095 NodeBuilder builder = new NodeBuilder().artifactId( "aid" ); 096 DependencyFilter filter = DependencyFilterUtils.classpathFilter( "compile+runtime" ); 097 098 assertTrue( filter.accept( builder.scope( "compile" ).build(), PARENTS ) ); 099 assertTrue( filter.accept( builder.scope( "system" ).build(), PARENTS ) ); 100 assertTrue( filter.accept( builder.scope( "provided" ).build(), PARENTS ) ); 101 assertTrue( filter.accept( builder.scope( "runtime" ).build(), PARENTS ) ); 102 assertFalse( filter.accept( builder.scope( "test" ).build(), PARENTS ) ); 103 } 104 105 @Test 106 public void testClasspathFilterRuntimeCommaSystem() 107 { 108 NodeBuilder builder = new NodeBuilder().artifactId( "aid" ); 109 DependencyFilter filter = DependencyFilterUtils.classpathFilter( "runtime,system" ); 110 111 assertTrue( filter.accept( builder.scope( "compile" ).build(), PARENTS ) ); 112 assertTrue( filter.accept( builder.scope( "system" ).build(), PARENTS ) ); 113 assertFalse( filter.accept( builder.scope( "provided" ).build(), PARENTS ) ); 114 assertTrue( filter.accept( builder.scope( "runtime" ).build(), PARENTS ) ); 115 assertFalse( filter.accept( builder.scope( "test" ).build(), PARENTS ) ); 116 } 117 118 @Test 119 public void testClasspathFilterNull() 120 { 121 NodeBuilder builder = new NodeBuilder().artifactId( "aid" ); 122 DependencyFilter filter = DependencyFilterUtils.classpathFilter( (String[]) null ); 123 124 assertFalse( filter.accept( builder.scope( "compile" ).build(), PARENTS ) ); 125 assertFalse( filter.accept( builder.scope( "system" ).build(), PARENTS ) ); 126 assertFalse( filter.accept( builder.scope( "provided" ).build(), PARENTS ) ); 127 assertFalse( filter.accept( builder.scope( "runtime" ).build(), PARENTS ) ); 128 assertFalse( filter.accept( builder.scope( "test" ).build(), PARENTS ) ); 129 } 130 131 @Test 132 public void testClasspathFilterUnknownScope() 133 { 134 NodeBuilder builder = new NodeBuilder().artifactId( "aid" ); 135 DependencyFilter filter = DependencyFilterUtils.classpathFilter( "compile" ); 136 137 assertTrue( filter.accept( builder.scope( "" ).build(), PARENTS ) ); 138 assertTrue( filter.accept( builder.scope( "unknown" ).build(), PARENTS ) ); 139 } 140 141}