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.enforcer.rules.dependency;
20  
21  import org.apache.maven.enforcer.rule.api.EnforcerLogger;
22  import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
23  import org.apache.maven.enforcer.rules.utils.DependencyNodeBuilder;
24  import org.junit.jupiter.api.Test;
25  import org.junit.jupiter.api.extension.ExtendWith;
26  import org.mockito.InjectMocks;
27  import org.mockito.Mock;
28  import org.mockito.junit.jupiter.MockitoExtension;
29  
30  import static org.assertj.core.api.Assertions.assertThatCode;
31  import static org.mockito.ArgumentMatchers.anyList;
32  import static org.mockito.Mockito.mock;
33  import static org.mockito.Mockito.when;
34  
35  @ExtendWith(MockitoExtension.class)
36  class RequireUpperBoundDepsTest {
37  
38      @Mock
39      private ResolverUtil resolverUtil;
40  
41      @InjectMocks
42      private RequireUpperBoundDeps rule;
43  
44      @Test
45      void testRule() throws Exception {
46  
47          rule.setLog(mock(EnforcerLogger.class));
48  
49          when(resolverUtil.resolveTransitiveDependenciesVerbose(anyList()))
50                  .thenReturn(new DependencyNodeBuilder()
51                          .withType(DependencyNodeBuilder.Type.POM)
52                          .withChildNode(new DependencyNodeBuilder()
53                                  .withArtifactId("childA")
54                                  .withVersion("1.0.0")
55                                  .build())
56                          .withChildNode(new DependencyNodeBuilder()
57                                  .withArtifactId("childA")
58                                  .withVersion("2.0.0")
59                                  .build())
60                          .build());
61  
62          assertThatCode(rule::execute)
63                  .isInstanceOf(EnforcerRuleException.class)
64                  .hasMessageContaining("default-group:childA:1.0.0:classifier")
65                  .hasMessageContaining("default-group:childA:2.0.0:classifier");
66      }
67  }