View Javadoc
1   package org.apache.rat.mp.util;
2   
3   import static org.apache.rat.mp.util.ExclusionHelper.ECLIPSE_DEFAULT_EXCLUDES;
4   import static org.apache.rat.mp.util.ExclusionHelper.IDEA_DEFAULT_EXCLUDES;
5   import static org.apache.rat.mp.util.ExclusionHelper.MAVEN_DEFAULT_EXCLUDES;
6   import static org.apache.rat.mp.util.ExclusionHelper.addEclipseDefaults;
7   import static org.apache.rat.mp.util.ExclusionHelper.addIdeaDefaults;
8   import static org.apache.rat.mp.util.ExclusionHelper.addMavenDefaults;
9   import static org.apache.rat.mp.util.ExclusionHelper.addPlexusAndScmDefaults;
10  import static org.junit.jupiter.api.Assertions.assertEquals;
11  import static org.junit.jupiter.api.Assertions.assertTrue;
12  
13  import java.util.HashSet;
14  import java.util.Set;
15  
16  /*
17   * Licensed to the Apache Software Foundation (ASF) under one or more
18   * contributor license agreements.  See the NOTICE file distributed with
19   * this work for additional information regarding copyright ownership.
20   * The ASF licenses this file to You under the Apache License, Version 2.0
21   * (the "License"); you may not use this file except in compliance with
22   * the License.  You may obtain a copy of the License at
23   *
24   *      http://www.apache.org/licenses/LICENSE-2.0
25   *
26   * Unless required by applicable law or agreed to in writing, software
27   * distributed under the License is distributed on an "AS IS" BASIS,
28   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29   * See the License for the specific language governing permissions and
30   * limitations under the License.
31   */
32  
33  import org.apache.maven.plugin.logging.Log;
34  import org.apache.rat.config.SourceCodeManagementSystems;
35  import org.junit.jupiter.api.Test;
36  import org.mockito.Mockito;
37  
38  
39  public class ExclusionHelperTest {
40  
41      
42      private Log log = Mockito.mock(Log.class);
43  
44      @Test
45      public void testNumberOfExclusions() {
46          assertEquals(5,
47                  ECLIPSE_DEFAULT_EXCLUDES.size(),"Did you change the number of eclipse excludes?");
48          assertEquals(4,
49                  IDEA_DEFAULT_EXCLUDES.size(), "Did you change the number of idea excludes?");
50          assertEquals(8,
51                  MAVEN_DEFAULT_EXCLUDES.size(), "Did you change the number of mvn excludes?");
52      }
53  
54      @Test
55      public void testAddingEclipseExclusions() {
56          final Set<String> exclusion = new HashSet<>();
57          exclusion.addAll(addEclipseDefaults(log, false));
58          assertTrue(exclusion.isEmpty());
59          exclusion.addAll(addEclipseDefaults(log, true));
60          assertEquals(5, exclusion.size());
61          exclusion.addAll(addEclipseDefaults(log, true));
62          assertEquals(5, exclusion.size());
63      }
64  
65      @Test
66      public void testAddingIdeaExclusions() {
67          final Set<String> exclusion = new HashSet<>();
68          exclusion.addAll(addIdeaDefaults(log, false));
69          assertTrue(exclusion.isEmpty());
70          exclusion.addAll(addIdeaDefaults(log, true));
71          assertEquals(4, exclusion.size());
72          exclusion.addAll(addIdeaDefaults(log, true));
73          assertEquals(4, exclusion.size());
74      }
75  
76      @Test
77      public void testAddingMavenExclusions() {
78          final Set<String> exclusion = new HashSet<>();
79          exclusion.addAll(addMavenDefaults(log, false));
80          assertTrue(exclusion.isEmpty());
81          exclusion.addAll(addMavenDefaults(log, true));
82          assertEquals(8, exclusion.size());
83          exclusion.addAll(addMavenDefaults(log, true));
84          assertEquals(8, exclusion.size());
85      }
86  
87      @Test
88      public void testAddingPlexusAndScmExclusion() {
89          final int expectedSizeMergedFromPlexusDefaultsAndScm = (37 + SourceCodeManagementSystems.getPluginExclusions().size());
90  
91          final Set<String> exclusion = new HashSet<>();
92          exclusion.addAll(addPlexusAndScmDefaults(log, false));
93          assertTrue(exclusion.isEmpty());
94          exclusion.addAll(addPlexusAndScmDefaults(log, true));
95          assertEquals(
96                  expectedSizeMergedFromPlexusDefaultsAndScm,//
97                  exclusion.size(), //
98                  "Did you upgrade plexus to get more default excludes?");
99          exclusion.addAll(addPlexusAndScmDefaults(log, true));
100         assertEquals(
101                 expectedSizeMergedFromPlexusDefaultsAndScm,//
102                 exclusion.size(), //
103                 "Did you upgrade plexus to get more default excludes?"
104                 );
105     }
106 
107 }