1 /* 2 * Copyright (c) 2011-2025 Yegor Bugayenko 3 * 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 1) Redistributions of source code must retain the above 9 * copyright notice, this list of conditions and the following 10 * disclaimer. 2) Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following 12 * disclaimer in the documentation and/or other materials provided 13 * with the distribution. 3) Neither the name of the Qulice.com nor 14 * the names of its contributors may be used to endorse or promote 15 * products derived from this software without specific prior written 16 * permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 20 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 21 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 * OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 package com.qulice.maven; 32 33 import java.io.File; 34 import org.apache.maven.model.Build; 35 import org.apache.maven.model.Scm; 36 import org.apache.maven.project.MavenProject; 37 import org.mockito.Mockito; 38 39 /** 40 * Mocker of {@link MavenProject}. 41 * @since 0.4 42 */ 43 public final class MavenProjectMocker { 44 45 /** 46 * Mock of project. 47 */ 48 private final MavenProject project = 49 Mockito.mock(MavenProject.class); 50 51 /** 52 * In this basedir. 53 * @param dir The directory 54 * @return This object 55 */ 56 public MavenProjectMocker inBasedir(final File dir) { 57 Mockito.doReturn(dir).when(this.project).getBasedir(); 58 final Build build = Mockito.mock(Build.class); 59 Mockito.doReturn(build).when(this.project).getBuild(); 60 Mockito.doReturn(new File(dir, "target").getPath()) 61 .when(build).getOutputDirectory(); 62 return this; 63 } 64 65 /** 66 * Mock it. 67 * @return The mock 68 * @throws Exception If something wrong happens inside 69 */ 70 public MavenProject mock() throws Exception { 71 Mockito.doReturn("jar").when(this.project).getPackaging(); 72 final Scm scm = new Scm(); 73 scm.setConnection("scm:svn:..."); 74 Mockito.doReturn(scm).when(this.project).getScm(); 75 return this.project; 76 } 77 78 }