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.plugin.testing;
20  
21  import javax.inject.Inject;
22  
23  import org.apache.maven.api.plugin.testing.InjectMojo;
24  import org.apache.maven.api.plugin.testing.MojoTest;
25  import org.apache.maven.execution.MavenSession;
26  import org.apache.maven.plugin.MojoExecution;
27  import org.apache.maven.project.MavenProject;
28  import org.junit.jupiter.api.Test;
29  import org.junit.jupiter.api.extension.ExtendWith;
30  import org.mockito.junit.jupiter.MockitoExtension;
31  
32  import static org.junit.jupiter.api.Assertions.assertNotNull;
33  import static org.junit.jupiter.api.Assertions.assertSame;
34  
35  @ExtendWith(MockitoExtension.class)
36  @MojoTest
37  public class ProvidesInjectMojoTest {
38  
39      private static final String POM = "<project>" + "</project>";
40  
41      @Inject
42      private MavenSession session;
43  
44      @Inject
45      private MavenProject project;
46  
47      @Inject
48      private MojoExecution mojoExecution;
49  
50      @Test
51      @InjectMojo(pom = POM, goal = "test:test-plugin:0.0.1-SNAPSHOT:provides")
52      public void bennShouldBeInjected(ProvidesInjectMojo mojo) {
53          assertNotNull(mojo);
54          assertSame(session, mojo.getSession());
55          assertSame(session, mojo.getSessionFromBean());
56  
57          assertSame(project, mojo.getProject());
58          assertSame(project, mojo.getProjectFromBean());
59  
60          assertSame(mojoExecution, mojo.getMojoExecution());
61          assertSame(mojoExecution, mojo.getMojoExecutionFromBean());
62      }
63  }