View Javadoc
1   package org.apache.maven.plugins.jdeps.consumers;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  import static org.junit.Assert.assertEquals;
22  
23  import org.junit.Test;
24  
25  public class JDepsConsumerTest
26  {
27  
28      private JDepsConsumer consumer;
29      
30      @Test
31      public void testJDKInterAPI()
32      {
33          
34          consumer = new JDepsConsumer();
35          consumer.consumeLine( "test-classes -> java.base" );
36          consumer.consumeLine( "   <unnamed> (test-classes)" );
37          consumer.consumeLine( "      -> java.io                                            " );
38          consumer.consumeLine( "      -> java.lang                                          " );
39          consumer.consumeLine( "      -> sun.misc                                           JDK internal API (java.base)" );
40          
41          assertEquals( 1, consumer.getOffendingPackages().size() );
42          assertEquals( "JDK internal API (java.base)", consumer.getOffendingPackages().get( "sun.misc" ) );
43          assertEquals( 0, consumer.getProfiles().size() );
44      }
45      
46      @Test
47      public void testJDKInternalAPI_Linux_Java8()
48      {
49          consumer = new JDepsConsumer();
50          consumer.consumeLine( "classes -> JDK removed internal API" );
51          consumer.consumeLine( "classes -> java.base" );
52          consumer.consumeLine( "   <unnamed>                                          -> java.io                                            java.base" );
53          consumer.consumeLine( "   <unnamed>                                          -> java.lang                                          java.base" );
54          consumer.consumeLine( "   <unnamed>                                          -> sun.misc                                           JDK internal API (JDK removed internal API)" );
55          
56          assertEquals( 1, consumer.getOffendingPackages().size() );
57          assertEquals( "JDK internal API (JDK removed internal API)", consumer.getOffendingPackages().get( "sun.misc" ) );
58          assertEquals( 0, consumer.getProfiles().size() );
59      }
60  
61      @Test
62      public void testProfile()
63      {
64          consumer = new JDepsConsumer();
65          consumer.consumeLine( "E:\\java-workspace\\apache-maven-plugins\\maven-jdeps-plugin\\target\\classes -> "
66              + "C:\\Program Files\\Java\\jdk1.8.0\\jre\\lib\\rt.jar (compact1)" );
67          consumer.consumeLine( "   <unnamed> (classes)" );
68          consumer.consumeLine( "      -> java.io                                            compact1" );
69          consumer.consumeLine( "      -> java.lang                                          compact1" );
70          consumer.consumeLine( "      -> sun.misc                                           JDK internal API (rt.jar)" );
71          
72          assertEquals( 1, consumer.getOffendingPackages().size() );
73          assertEquals( "JDK internal API (rt.jar)", consumer.getOffendingPackages().get( "sun.misc" ) );
74          assertEquals( 2, consumer.getProfiles().size() );
75          assertEquals( "compact1", consumer.getProfiles().get( "java.io" ) );
76          assertEquals( "compact1", consumer.getProfiles().get( "java.lang" ) );
77      }
78  
79  }