View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.javadoc.stubs;
20  
21  import java.io.File;
22  import java.util.ArrayList;
23  import java.util.HashSet;
24  import java.util.List;
25  import java.util.Set;
26  
27  import org.apache.maven.artifact.Artifact;
28  import org.apache.maven.model.Build;
29  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
30  
31  import static org.mockito.Mockito.mock;
32  import static org.mockito.Mockito.when;
33  
34  /**
35   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
36   */
37  public class ProxyTestMavenProjectStub extends MavenProjectStub {
38      private Set<Artifact> dependencyArtifacts = new HashSet<>();
39  
40      public ProxyTestMavenProjectStub() {
41          readModel(new File(getBasedir(), "proxy-test-plugin-config.xml"));
42  
43          setGroupId(getModel().getGroupId());
44          setArtifactId(getModel().getArtifactId());
45          setVersion(getModel().getVersion());
46          setName(getModel().getName());
47          setUrl(getModel().getUrl());
48          setPackaging(getModel().getPackaging());
49  
50          Build build = new Build();
51          build.setFinalName(getModel().getArtifactId());
52          build.setSourceDirectory(getBasedir() + "/src/main/java");
53          build.setDirectory(super.getBasedir() + "/target/test/unit/proxy-test/target");
54          setBuild(build);
55  
56          List<String> compileSourceRoots = new ArrayList<>();
57          compileSourceRoots.add(getBasedir() + "/src/main/java");
58          setCompileSourceRoots(compileSourceRoots);
59  
60          Artifact artifact = mock(Artifact.class);
61          when(artifact.getGroupId()).thenReturn("commons-logging");
62          when(artifact.getArtifactId()).thenReturn("commons-logging");
63          when(artifact.getVersion()).thenReturn("1.1.1");
64          when(artifact.getScope()).thenReturn(Artifact.SCOPE_RUNTIME);
65          when(artifact.getType()).thenReturn("jar");
66          when(artifact.getFile()).thenReturn(getBasedir());
67          DefaultArtifactHandlerStub artifactHandler = new DefaultArtifactHandlerStub();
68          artifactHandler.setExtension("jar");
69          when(artifact.getArtifactHandler()).thenReturn(artifactHandler);
70  
71          dependencyArtifacts.add(artifact);
72      }
73  
74      /** {@inheritDoc} */
75      @Override
76      public File getBasedir() {
77          return new File(super.getBasedir() + "/src/test/resources/unit/proxy-test");
78      }
79  
80      @Override
81      public Set<Artifact> getDependencyArtifacts() {
82          return dependencyArtifacts;
83      }
84  }