View Javadoc
1   package org.apache.maven.plugins.javadoc.stubs;
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 static org.mockito.Mockito.mock;
23  import static org.mockito.Mockito.when;
24  
25  import org.apache.maven.artifact.Artifact;
26  import org.apache.maven.model.Build;
27  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
28  
29  import java.io.File;
30  import java.util.ArrayList;
31  import java.util.HashSet;
32  import java.util.List;
33  import java.util.Set;
34  
35  /**
36   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
37   */
38  public class ProxyTestMavenProjectStub
39      extends MavenProjectStub
40  {
41      private Set<Artifact> dependencyArtifacts = new HashSet<>();
42  
43      public ProxyTestMavenProjectStub()
44      {
45          readModel( new File( getBasedir(), "proxy-test-plugin-config.xml" ) );
46  
47          setGroupId( getModel().getGroupId() );
48          setArtifactId( getModel().getArtifactId() );
49          setVersion( getModel().getVersion() );
50          setName( getModel().getName() );
51          setUrl( getModel().getUrl() );
52          setPackaging( getModel().getPackaging() );
53  
54          Build build = new Build();
55          build.setFinalName( getModel().getArtifactId() );
56          build.setSourceDirectory( getBasedir() + "/src/main/java" );
57          build.setDirectory( super.getBasedir() + "/target/test/unit/proxy-test/target" );
58          setBuild( build );
59  
60          List<String> compileSourceRoots = new ArrayList<>();
61          compileSourceRoots.add( getBasedir() + "/src/main/java" );
62          setCompileSourceRoots( compileSourceRoots );
63  
64          
65          Artifact artifact = mock( Artifact.class );
66          when( artifact.getGroupId()).thenReturn( "commons-logging" );
67          when( artifact.getArtifactId()).thenReturn( "commons-logging" );
68          when( artifact.getVersion()).thenReturn( "1.1.1" );
69          when( artifact.getScope()).thenReturn( Artifact.SCOPE_RUNTIME );
70          when( artifact.getType()).thenReturn( "jar" );
71          when( artifact.getFile()).thenReturn( getBasedir() );
72          DefaultArtifactHandlerStubactHandlerStub.html#DefaultArtifactHandlerStub">DefaultArtifactHandlerStub artifactHandler = new DefaultArtifactHandlerStub();
73          artifactHandler.setExtension( "jar" );
74          when( artifact.getArtifactHandler()).thenReturn( artifactHandler );
75  
76          dependencyArtifacts.add( artifact );
77      }
78  
79      /** {@inheritDoc} */
80      @Override
81      public File getBasedir()
82      {
83          return new File( super.getBasedir() + "/src/test/resources/unit/proxy-test" );
84      }
85  
86      @Override
87      public Set<Artifact> getDependencyArtifacts()
88      {
89          return dependencyArtifacts;
90      }
91  }