1 package org.apache.maven.shared.dependency.tree.filter;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import org.apache.maven.artifact.Artifact;
23 import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
24 import org.apache.maven.plugin.testing.stubs.ArtifactStub;
25 import org.apache.maven.shared.dependency.tree.DependencyNode;
26 import org.jmock.Mock;
27 import org.jmock.MockObjectTestCase;
28
29 /**
30 * Tests <code>ArtifactDependencyNodeFilter</code>.
31 *
32 * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
33 * @version $Id: ArtifactDependencyNodeFilterTest.java 1100703 2011-05-08 08:27:33Z hboutemy $
34 * @see ArtifactDependencyNodeFilter
35 */
36 public class ArtifactDependencyNodeFilterTest
37 extends MockObjectTestCase
38 {
39 // fields -----------------------------------------------------------------
40
41 private Artifact artifact;
42
43 private DependencyNode node;
44
45 private ArtifactDependencyNodeFilter nodeFilter;
46
47 private ArtifactFilter artifactFilter;
48
49 // TestCase methods -------------------------------------------------------
50
51 /**
52 * {@inheritDoc}
53 */
54 protected void setUp()
55 throws Exception
56 {
57 artifact = new ArtifactStub();
58 node = new DependencyNode( artifact );
59 }
60
61 // tests ------------------------------------------------------------------
62
63 public void testArtifactFilterInclude()
64 {
65 artifactFilter = createArtifactFilter( artifact, true );
66 nodeFilter = new ArtifactDependencyNodeFilter( artifactFilter );
67
68 assertTrue( nodeFilter.accept( node ) );
69 }
70
71 public void testArtifactFilterExclude()
72 {
73 artifactFilter = createArtifactFilter( artifact, false );
74 nodeFilter = new ArtifactDependencyNodeFilter( artifactFilter );
75
76 assertFalse( nodeFilter.accept( node ) );
77 }
78
79 // private methods --------------------------------------------------------
80
81 private ArtifactFilter createArtifactFilter( Artifact artifact, boolean include )
82 {
83 Mock mock = mock( ArtifactFilter.class );
84
85 mock.stubs().method( "include" ).with( same( artifact ) ).will( returnValue( include ) );
86
87 return (ArtifactFilter) mock.proxy();
88 }
89 }