View Javadoc
1   package org.apache.maven.toolchain;
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  
22  import static org.junit.Assert.assertFalse;
23  import static org.junit.Assert.assertTrue;
24  
25  import java.io.InputStream;
26  
27  import org.apache.maven.toolchain.java.DefaultJavaToolChain;
28  import org.apache.maven.toolchain.model.PersistedToolchains;
29  import org.apache.maven.toolchain.model.ToolchainModel;
30  import org.apache.maven.toolchain.model.io.xpp3.MavenToolchainsXpp3Reader;
31  import org.codehaus.plexus.util.IOUtil;
32  import org.junit.Test;
33  
34  public class DefaultToolchainTest
35  {
36      private MavenToolchainsXpp3Reader reader = new MavenToolchainsXpp3Reader();
37  
38      @Test
39      public void testEquals() throws Exception
40      {
41          InputStream jdksIS = null;
42          InputStream jdksExtraIS = null;
43          try
44          {
45              jdksIS = ToolchainModel.class.getResourceAsStream( "toolchains-jdks.xml" );
46              jdksExtraIS = ToolchainModel.class.getResourceAsStream( "toolchains-jdks-extra.xml" );
47  
48              PersistedToolchains jdks = reader.read( jdksIS );
49              PersistedToolchains jdksExtra = reader.read( jdksExtraIS );
50  
51              DefaultJavaToolChain tc1 = new DefaultJavaToolChain( jdks.getToolchains().get( 0 ), null );
52              DefaultJavaToolChain tc2 = new DefaultJavaToolChain( jdksExtra.getToolchains().get( 0 ), null );
53  
54              assertTrue( tc1.equals( tc1 ) );
55              assertFalse( tc1.equals( tc2 ) );
56              assertFalse( tc2.equals( tc1 ) );
57              assertTrue( tc2.equals( tc2 ) );
58          }
59          finally
60          {
61              IOUtil.close( jdksIS );
62              IOUtil.close( jdksExtraIS );
63          }
64      }
65  }