You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2014/11/02 22:34:53 UTC
git commit: Add tests for equals() and hashCode()
Repository: maven
Updated Branches:
refs/heads/master a31c199a3 -> 01a879384
Add tests for equals() and hashCode()
Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/01a87938
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/01a87938
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/01a87938
Branch: refs/heads/master
Commit: 01a879384c8ab01cc02b3037935b99f2b13db50e
Parents: a31c199
Author: Robert Scholte <rf...@codehaus.org>
Authored: Sun Nov 2 22:34:19 2014 +0100
Committer: Robert Scholte <rf...@codehaus.org>
Committed: Sun Nov 2 22:34:19 2014 +0100
----------------------------------------------------------------------
.../maven/toolchain/DefaultToolchainTest.java | 91 ++++++++++++++++++++
.../toolchain/model/toolchains-jdks-extra.xml | 45 ++++++++++
.../maven/toolchain/model/toolchains-jdks.xml | 45 ++++++++++
3 files changed, 181 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven/blob/01a87938/maven-core/src/test/java/org/apache/maven/toolchain/DefaultToolchainTest.java
----------------------------------------------------------------------
diff --git a/maven-core/src/test/java/org/apache/maven/toolchain/DefaultToolchainTest.java b/maven-core/src/test/java/org/apache/maven/toolchain/DefaultToolchainTest.java
new file mode 100644
index 0000000..aaa2346
--- /dev/null
+++ b/maven-core/src/test/java/org/apache/maven/toolchain/DefaultToolchainTest.java
@@ -0,0 +1,91 @@
+package org.apache.maven.toolchain;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.InputStream;
+
+import org.apache.maven.toolchain.java.DefaultJavaToolChain;
+import org.apache.maven.toolchain.model.PersistedToolchains;
+import org.apache.maven.toolchain.model.ToolchainModel;
+import org.apache.maven.toolchain.model.io.xpp3.MavenToolchainsXpp3Reader;
+import org.codehaus.plexus.util.IOUtil;
+import org.junit.Test;
+
+public class DefaultToolchainTest
+{
+ private MavenToolchainsXpp3Reader reader = new MavenToolchainsXpp3Reader();
+
+ @Test
+ public void testEquals() throws Exception
+ {
+ InputStream jdksIS = null;
+ InputStream jdksExtraIS = null;
+ try
+ {
+ jdksIS = ToolchainModel.class.getResourceAsStream( "toolchains-jdks.xml" );
+ jdksExtraIS = ToolchainModel.class.getResourceAsStream( "toolchains-jdks-extra.xml" );
+
+ PersistedToolchains jdks = reader.read( jdksIS );
+ PersistedToolchains jdksExtra = reader.read( jdksExtraIS );
+
+ DefaultJavaToolChain tc1 = new DefaultJavaToolChain( jdks.getToolchains().get( 0 ), null );
+ DefaultJavaToolChain tc2 = new DefaultJavaToolChain( jdksExtra.getToolchains().get( 0 ), null );
+
+ // tc1{type:jdk,id:default} tc2{type:jdk} (no id, so should be considered 'default')
+ assertTrue( tc1.equals( tc1 ) );
+ assertTrue( tc1.equals( tc2 ) );
+ assertTrue( tc2.equals( tc1 ) );
+ assertTrue( tc2.equals( tc2 ) );
+ }
+ finally
+ {
+ IOUtil.close( jdksIS );
+ IOUtil.close( jdksExtraIS );
+ }
+ }
+
+ @Test
+ public void testHashCode() throws Exception
+ {
+ InputStream jdksIS = null;
+ InputStream jdksExtraIS = null;
+ try
+ {
+ jdksIS = ToolchainModel.class.getResourceAsStream( "toolchains-jdks.xml" );
+ jdksExtraIS = ToolchainModel.class.getResourceAsStream( "toolchains-jdks-extra.xml" );
+
+ PersistedToolchains jdks = reader.read( jdksIS );
+ PersistedToolchains jdksExtra = reader.read( jdksExtraIS );
+
+ DefaultJavaToolChain tc1 = new DefaultJavaToolChain( jdks.getToolchains().get( 0 ), null );
+ DefaultJavaToolChain tc2 = new DefaultJavaToolChain( jdksExtra.getToolchains().get( 0 ), null );
+
+ assertEquals( tc1.hashCode(), tc2.hashCode() );
+ }
+ finally
+ {
+ IOUtil.close( jdksIS );
+ IOUtil.close( jdksExtraIS );
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven/blob/01a87938/maven-core/src/test/resources/org/apache/maven/toolchain/model/toolchains-jdks-extra.xml
----------------------------------------------------------------------
diff --git a/maven-core/src/test/resources/org/apache/maven/toolchain/model/toolchains-jdks-extra.xml b/maven-core/src/test/resources/org/apache/maven/toolchain/model/toolchains-jdks-extra.xml
new file mode 100644
index 0000000..322147d
--- /dev/null
+++ b/maven-core/src/test/resources/org/apache/maven/toolchain/model/toolchains-jdks-extra.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<toolchains>
+ <toolchain>
+ <type>jdk</type>
+ <provides>
+ <version>1.4</version>
+ <vendor>sun</vendor>
+ <!-- no id, so it's considered 'default' -->
+ </provides>
+ <configuration>
+ <jdkHome>${env.JAVA_HOME}</jdkHome>
+ </configuration>
+ </toolchain>
+ <toolchain>
+ <type>jdk</type>
+ <provides>
+ <version>1.7</version>
+ <vendor>ibm</vendor>
+ <id>ibm_17</id>
+ </provides>
+ <configuration>
+ <jdkHome>${env.JAVA_HOME}</jdkHome>
+ </configuration>
+ </toolchain>
+</toolchains>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/maven/blob/01a87938/maven-core/src/test/resources/org/apache/maven/toolchain/model/toolchains-jdks.xml
----------------------------------------------------------------------
diff --git a/maven-core/src/test/resources/org/apache/maven/toolchain/model/toolchains-jdks.xml b/maven-core/src/test/resources/org/apache/maven/toolchain/model/toolchains-jdks.xml
new file mode 100644
index 0000000..5048e7b
--- /dev/null
+++ b/maven-core/src/test/resources/org/apache/maven/toolchain/model/toolchains-jdks.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<toolchains>
+ <toolchain>
+ <type>jdk</type>
+ <provides>
+ <version>1.5</version>
+ <vendor>sun</vendor>
+ <id>default</id>
+ </provides>
+ <configuration>
+ <jdkHome>${env.JAVA_HOME}</jdkHome>
+ </configuration>
+ </toolchain>
+ <toolchain>
+ <type>jdk</type>
+ <provides>
+ <version>1.6</version>
+ <vendor>sun</vendor>
+ <id>ide</id>
+ </provides>
+ <configuration>
+ <jdkHome>${env.JAVA_HOME}</jdkHome>
+ </configuration>
+ </toolchain>
+</toolchains>
\ No newline at end of file