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