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.dependency.analyze;
20  
21  import javax.inject.Inject;
22  
23  import org.apache.maven.api.plugin.testing.Basedir;
24  import org.apache.maven.api.plugin.testing.InjectMojo;
25  import org.apache.maven.api.plugin.testing.MojoTest;
26  import org.apache.maven.plugin.logging.Log;
27  import org.junit.jupiter.api.Test;
28  import org.mockito.ArgumentCaptor;
29  
30  import static org.junit.jupiter.api.Assertions.assertTrue;
31  import static org.mockito.Mockito.verify;
32  import static org.mockito.Mockito.when;
33  
34  /**
35   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
36   * @version $Id$
37   */
38  @MojoTest
39  class TestAnalyzeDuplicateMojo {
40  
41      @Inject
42      private Log log;
43  
44      @Test
45      @Basedir("/unit/duplicate-dependencies")
46      @InjectMojo(goal = "analyze-duplicate", pom = "plugin-config.xml")
47      void testDuplicate(AnalyzeDuplicateMojo mojo) throws Exception {
48          when(log.isInfoEnabled()).thenReturn(true);
49  
50          mojo.execute();
51  
52          ArgumentCaptor<String> logCapture = ArgumentCaptor.forClass(String.class);
53          verify(log).info(logCapture.capture());
54  
55          assertTrue(logCapture
56                  .getValue()
57                  .contains("List of duplicate dependencies defined in <dependencies/> in your pom.xml"));
58          assertTrue(logCapture.getValue().contains("junit:junit:jar"));
59      }
60  
61      @Test
62      @Basedir("/unit/duplicate-dependencies")
63      @InjectMojo(goal = "analyze-duplicate", pom = "plugin-config2.xml")
64      void testDuplicate2(AnalyzeDuplicateMojo mojo) throws Exception {
65          when(log.isInfoEnabled()).thenReturn(true);
66  
67          mojo.execute();
68  
69          ArgumentCaptor<String> logCapture = ArgumentCaptor.forClass(String.class);
70          verify(log).info(logCapture.capture());
71  
72          assertTrue(logCapture
73                  .getValue()
74                  .contains("List of duplicate dependencies defined in <dependencyManagement/> in your pom.xml"));
75          assertTrue(logCapture.getValue().contains("junit:junit:jar"));
76      }
77  }