View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2011-2026 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.qulice.maven;
6   
7   import java.io.File;
8   import org.apache.maven.model.Build;
9   import org.apache.maven.project.MavenProject;
10  
11  /**
12   * Mocker of {@link MavenProject}.
13   * @since 0.4
14   */
15  public final class MavenProjectMocker {
16  
17      /**
18       * Mock of project.
19       */
20      private final MavenProject project = new MavenProject();
21  
22      /**
23       * In this basedir.
24       * @param dir The directory
25       * @return This object
26       */
27      public MavenProjectMocker inBasedir(final File dir) {
28          final File parent = new File(dir, "target");
29          final Build build = new Build();
30          build.setOutputDirectory(parent.getPath());
31          this.project.setFile(parent);
32          this.project.setBuild(build);
33          return this;
34      }
35  
36      /**
37       * Mock it.
38       * @return The mock
39       * @throws Exception If something wrong happens inside
40       */
41      public MavenProject mock() throws Exception {
42          this.project.setPackaging("jar");
43          return this.project;
44      }
45  }