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.api.plugin.testing;
20  
21  import javax.inject.Inject;
22  
23  import java.lang.annotation.ElementType;
24  import java.lang.annotation.Retention;
25  import java.lang.annotation.RetentionPolicy;
26  import java.lang.annotation.Target;
27  
28  import org.apache.maven.api.di.Provides;
29  import org.junit.jupiter.api.extension.ExtendWith;
30  
31  /**
32   * Annotation that enables Maven plugin (Mojo) testing support in JUnit tests.
33   * When applied to a test class, it automatically sets up the testing environment
34   * for Maven plugins, including dependency injection and parameter resolution.
35   *
36   * <p>This annotation works in conjunction with {@link InjectMojo} and {@link MojoParameter}
37   * to provide a comprehensive testing framework for Maven plugins. It automatically registers
38   * the {@link MojoExtension} which handles the plugin lifecycle and dependency injection.</p>
39   *
40   * <p>Example usage:</p>
41   * <pre>
42   * {@code
43   * @MojoTest
44   * class MyMojoTest {
45   *     @Inject
46   *     private SomeComponent component;
47   *
48   *     @Test
49   *     @InjectMojo(goal = "my-goal")
50   *     @MojoParameter(name = "parameter", value = "value")
51   *     void testMojoExecution(MyMojo mojo) {
52   *         // mojo is instantiated with the specified parameters
53   *         // component is automatically injected
54   *         mojo.execute();
55   *         // verify execution results
56   *     }
57   *
58   *     @Provides
59   *     SomeComponent provideMockedComponent() {
60   *         return mock(SomeComponent.class);
61   *     }
62   * }
63   * }
64   * </pre>
65   *
66   * <p>The annotation supports:</p>
67   * <ul>
68   *   <li>Automatic Mojo instantiation and configuration</li>
69   *   <li>Parameter injection via {@link MojoParameter}</li>
70   *   <li>Component injection via {@link Inject}</li>
71   *   <li>Mock component injection via {@link Provides}</li>
72   *   <li>Custom POM configuration via {@link InjectMojo#pom()}</li>
73   *   <li>Base directory configuration for test resources via {@link Basedir}</li>
74   * </ul>
75   *
76   *
77   * @see MojoExtension
78   * @see InjectMojo
79   * @see MojoParameter
80   * @see Provides
81   * @since 4.0.0
82   */
83  @Retention(RetentionPolicy.RUNTIME)
84  @ExtendWith(MojoExtension.class)
85  @Target(ElementType.TYPE)
86  public @interface MojoTest {}