001package org.apache.maven.toolchain;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *  http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import static org.junit.Assert.assertFalse;
023import static org.junit.Assert.assertTrue;
024
025import java.io.InputStream;
026
027import org.apache.maven.toolchain.java.DefaultJavaToolChain;
028import org.apache.maven.toolchain.model.PersistedToolchains;
029import org.apache.maven.toolchain.model.ToolchainModel;
030import org.apache.maven.toolchain.model.io.xpp3.MavenToolchainsXpp3Reader;
031import org.codehaus.plexus.util.IOUtil;
032import org.junit.Test;
033
034public class DefaultToolchainTest
035{
036    private MavenToolchainsXpp3Reader reader = new MavenToolchainsXpp3Reader();
037
038    @Test
039    public void testEquals() throws Exception
040    {
041        InputStream jdksIS = null;
042        InputStream jdksExtraIS = null;
043        try
044        {
045            jdksIS = ToolchainModel.class.getResourceAsStream( "toolchains-jdks.xml" );
046            jdksExtraIS = ToolchainModel.class.getResourceAsStream( "toolchains-jdks-extra.xml" );
047
048            PersistedToolchains jdks = reader.read( jdksIS );
049            PersistedToolchains jdksExtra = reader.read( jdksExtraIS );
050
051            DefaultJavaToolChain tc1 = new DefaultJavaToolChain( jdks.getToolchains().get( 0 ), null );
052            DefaultJavaToolChain tc2 = new DefaultJavaToolChain( jdksExtra.getToolchains().get( 0 ), null );
053
054            assertTrue( tc1.equals( tc1 ) );
055            assertFalse( tc1.equals( tc2 ) );
056            assertFalse( tc2.equals( tc1 ) );
057            assertTrue( tc2.equals( tc2 ) );
058        }
059        finally
060        {
061            IOUtil.close( jdksIS );
062            IOUtil.close( jdksExtraIS );
063        }
064    }
065}