summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakozak2011-11-24 08:10:07 (EST)
committer Winston Prakash2011-12-01 20:47:25 (EST)
commita1f5f4144d3063fe89df8aab280fdf2772e218a1 (patch)
tree42d2a537a95b90811e9e45a1bdde85e33d364329
parent11da6cf25c8512bad20ec109d1680bfb5a649665 (diff)
downloadorg.eclipse.hudson.core-a1f5f4144d3063fe89df8aab280fdf2772e218a1.zip
org.eclipse.hudson.core-a1f5f4144d3063fe89df8aab280fdf2772e218a1.tar.gz
org.eclipse.hudson.core-a1f5f4144d3063fe89df8aab280fdf2772e218a1.tar.bz2
Implement equals/hashcode for ParameterDefinition subclasses. Add unit tests for new logic
Signed-off-by: Winston Prakash <winston.prakash@gmail.com>
-rw-r--r--hudson-core/src/main/java/hudson/model/BooleanParameterDefinition.java16
-rw-r--r--hudson-core/src/main/java/hudson/model/ChoiceParameterDefinition.java17
-rw-r--r--hudson-core/src/main/java/hudson/model/ParameterDefinition.java28
-rw-r--r--hudson-core/src/main/java/hudson/model/PasswordParameterDefinition.java17
-rw-r--r--hudson-core/src/main/java/hudson/model/RunParameterDefinition.java16
-rw-r--r--hudson-core/src/main/java/hudson/model/StringParameterDefinition.java17
-rw-r--r--hudson-core/src/test/java/hudson/model/BooleanParameterDefinitionEqualsHashCodeTest.java73
-rw-r--r--hudson-core/src/test/java/hudson/model/ChoiceParameterDefinitionEqualsHashCodeTest.java73
-rw-r--r--hudson-core/src/test/java/hudson/model/PasswordParameterDefinitionEqualsHashCodeTest.java93
-rw-r--r--hudson-core/src/test/java/hudson/model/RunParameterDefinitionEqualsHashCodeTest.java73
-rw-r--r--hudson-core/src/test/java/hudson/model/StringParameterDefinitionEqualsHashCodeTest.java73
11 files changed, 496 insertions, 0 deletions
diff --git a/hudson-core/src/main/java/hudson/model/BooleanParameterDefinition.java b/hudson-core/src/main/java/hudson/model/BooleanParameterDefinition.java
index 6aaf213..d43eadf 100644
--- a/hudson-core/src/main/java/hudson/model/BooleanParameterDefinition.java
+++ b/hudson-core/src/main/java/hudson/model/BooleanParameterDefinition.java
@@ -16,6 +16,8 @@
package hudson.model;
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.DataBoundConstructor;
import net.sf.json.JSONObject;
@@ -68,4 +70,18 @@ public class BooleanParameterDefinition extends SimpleParameterDefinition {
}
}
+ @Override
+ public boolean equals(Object o) {
+ return super.equals(o) && new EqualsBuilder()
+ .append(isDefaultValue(), ((BooleanParameterDefinition) o).isDefaultValue())
+ .isEquals();
+ }
+
+ @Override
+ public int hashCode() {
+ return new HashCodeBuilder()
+ .appendSuper(super.hashCode())
+ .append(isDefaultValue())
+ .toHashCode();
+ }
}
diff --git a/hudson-core/src/main/java/hudson/model/ChoiceParameterDefinition.java b/hudson-core/src/main/java/hudson/model/ChoiceParameterDefinition.java
index bb09d31..f714b71 100644
--- a/hudson-core/src/main/java/hudson/model/ChoiceParameterDefinition.java
+++ b/hudson-core/src/main/java/hudson/model/ChoiceParameterDefinition.java
@@ -14,6 +14,8 @@
package hudson.model;
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.export.Exported;
@@ -95,4 +97,19 @@ public class ChoiceParameterDefinition extends SimpleParameterDefinition {
}
}
+ @Override
+ public boolean equals(Object o) {
+ return super.equals(o) && new EqualsBuilder()
+ .append(getChoices(), ((ChoiceParameterDefinition) o).getChoices())
+ .isEquals();
+ }
+
+ @Override
+ public int hashCode() {
+ return new HashCodeBuilder()
+ .appendSuper(super.hashCode())
+ .append(getChoices())
+ .toHashCode();
+ }
+
}
diff --git a/hudson-core/src/main/java/hudson/model/ParameterDefinition.java b/hudson-core/src/main/java/hudson/model/ParameterDefinition.java
index 97852ba..311496d 100644
--- a/hudson-core/src/main/java/hudson/model/ParameterDefinition.java
+++ b/hudson-core/src/main/java/hudson/model/ParameterDefinition.java
@@ -28,6 +28,7 @@ import java.io.IOException;
import net.sf.json.JSONObject;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
@@ -219,4 +220,31 @@ public abstract class ParameterDefinition implements
return "Parameter";
}
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ ParameterDefinition that = (ParameterDefinition) o;
+
+ if (name != null ? !name.equals(that.name) : that.name != null) {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return new HashCodeBuilder()
+ .append(getName())
+ .append(getClass())
+ .toHashCode();
+ }
}
+
diff --git a/hudson-core/src/main/java/hudson/model/PasswordParameterDefinition.java b/hudson-core/src/main/java/hudson/model/PasswordParameterDefinition.java
index 29b40e0..992dd49 100644
--- a/hudson-core/src/main/java/hudson/model/PasswordParameterDefinition.java
+++ b/hudson-core/src/main/java/hudson/model/PasswordParameterDefinition.java
@@ -17,6 +17,8 @@
package hudson.model;
import net.sf.json.JSONObject;
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.DataBoundConstructor;
import hudson.Extension;
@@ -76,4 +78,19 @@ public class PasswordParameterDefinition extends SimpleParameterDefinition {
return "/help/parameter/string.html";
}
}
+
+ @Override
+ public boolean equals(Object o) {
+ return super.equals(o) && new EqualsBuilder()
+ .append(getDefaultValue(), ((PasswordParameterDefinition) o).getDefaultValue())
+ .isEquals();
+ }
+
+ @Override
+ public int hashCode() {
+ return new HashCodeBuilder()
+ .appendSuper(super.hashCode())
+ .append(getDefaultValue())
+ .toHashCode();
+ }
}
diff --git a/hudson-core/src/main/java/hudson/model/RunParameterDefinition.java b/hudson-core/src/main/java/hudson/model/RunParameterDefinition.java
index a176ffe..4ae2053 100644
--- a/hudson-core/src/main/java/hudson/model/RunParameterDefinition.java
+++ b/hudson-core/src/main/java/hudson/model/RunParameterDefinition.java
@@ -18,6 +18,8 @@ package hudson.model;
import net.sf.json.JSONObject;
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.export.Exported;
@@ -84,4 +86,18 @@ public class RunParameterDefinition extends SimpleParameterDefinition {
return new RunParameterValue(getName(), value, getDescription());
}
+ @Override
+ public boolean equals(Object o) {
+ return super.equals(o) && new EqualsBuilder()
+ .append(getProjectName(), ((RunParameterDefinition) o).getProjectName())
+ .isEquals();
+ }
+
+ @Override
+ public int hashCode() {
+ return new HashCodeBuilder()
+ .appendSuper(super.hashCode())
+ .append(getProjectName())
+ .toHashCode();
+ }
}
diff --git a/hudson-core/src/main/java/hudson/model/StringParameterDefinition.java b/hudson-core/src/main/java/hudson/model/StringParameterDefinition.java
index e57018c..8566a44 100644
--- a/hudson-core/src/main/java/hudson/model/StringParameterDefinition.java
+++ b/hudson-core/src/main/java/hudson/model/StringParameterDefinition.java
@@ -18,6 +18,8 @@ package hudson.model;
import hudson.Extension;
import net.sf.json.JSONObject;
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
@@ -75,4 +77,19 @@ public class StringParameterDefinition extends SimpleParameterDefinition {
public ParameterValue createValue(String value) {
return new StringParameterValue(getName(), value, getDescription());
}
+
+ @Override
+ public boolean equals(Object o) {
+ return super.equals(o) && new EqualsBuilder()
+ .append(getDefaultValue(), ((StringParameterDefinition) o).getDefaultValue())
+ .isEquals();
+ }
+
+ @Override
+ public int hashCode() {
+ return new HashCodeBuilder()
+ .appendSuper(super.hashCode())
+ .append(getDefaultValue())
+ .toHashCode();
+ }
}
diff --git a/hudson-core/src/test/java/hudson/model/BooleanParameterDefinitionEqualsHashCodeTest.java b/hudson-core/src/test/java/hudson/model/BooleanParameterDefinitionEqualsHashCodeTest.java
new file mode 100644
index 0000000..940a58c
--- /dev/null
+++ b/hudson-core/src/test/java/hudson/model/BooleanParameterDefinitionEqualsHashCodeTest.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ *
+ * Copyright (c) 2011 Oracle Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+*
+* Nikita Levyankov
+ *
+ *
+ *******************************************************************************/
+package hudson.model;
+
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+
+/**
+ * Equals and hashCode test for {@link BooleanParameterDefinition} object
+ * <p/>
+ * Date: 11/2/11
+ *
+ * @author Nikita Levyankov
+ */
+public class BooleanParameterDefinitionEqualsHashCodeTest {
+
+ @Test
+ public void testEquals() {
+ BooleanParameterDefinition o1 = new BooleanParameterDefinition("name1", false, "description");
+ assertEquals(o1, o1);
+ assertFalse(o1.equals(null));
+ assertFalse(o1.equals(new StringParameterDefinition("test1", "value", "description")));
+ assertFalse(new BooleanParameterDefinition("name1", false, null).equals(
+ new BooleanParameterDefinition(null, false, null)));
+ assertFalse(
+ new BooleanParameterDefinition(null, true, null).equals(new BooleanParameterDefinition(null, false, null)));
+ assertFalse(o1.equals(new BooleanParameterDefinition(null, true, null)));
+ assertFalse(o1.equals(new BooleanParameterDefinition("name1", true, "description")));
+
+ assertEquals(o1, new BooleanParameterDefinition("name1", false, "description"));
+ assertEquals(o1, new BooleanParameterDefinition("name1", false, "description1"));
+ assertEquals(new BooleanParameterDefinition(null, false, "d1"),
+ new BooleanParameterDefinition(null, false, "d1"));
+ assertEquals(new BooleanParameterDefinition(null, false, null),
+ new BooleanParameterDefinition(null, false, null));
+ }
+
+ @Test
+ public void testHashCode() {
+ BooleanParameterDefinition o1 = new BooleanParameterDefinition("name1", false, "description");
+ assertEquals(o1, o1);
+ assertFalse(o1.hashCode() == new StringParameterDefinition("test1", "value", "description").hashCode());
+ assertFalse(new BooleanParameterDefinition("name1", false, null).hashCode() ==
+ new BooleanParameterDefinition(null, false, null).hashCode());
+ assertFalse(new BooleanParameterDefinition(null, true, null).hashCode() ==
+ new BooleanParameterDefinition(null, false, null).hashCode());
+ assertFalse(o1.hashCode() == new BooleanParameterDefinition(null, true, null).hashCode());
+ assertFalse(o1.hashCode() == new BooleanParameterDefinition("name1", true, "description").hashCode());
+
+ assertTrue(o1.hashCode() == new BooleanParameterDefinition("name1", false, "description").hashCode());
+ assertTrue(o1.hashCode() == new BooleanParameterDefinition("name1", false, "description1").hashCode());
+ assertTrue(new BooleanParameterDefinition(null, false, "d1").hashCode() ==
+ new BooleanParameterDefinition(null, false, "d1").hashCode());
+ assertTrue(new BooleanParameterDefinition(null, false, null).hashCode() ==
+ new BooleanParameterDefinition(null, false, null).hashCode());
+ }
+}
diff --git a/hudson-core/src/test/java/hudson/model/ChoiceParameterDefinitionEqualsHashCodeTest.java b/hudson-core/src/test/java/hudson/model/ChoiceParameterDefinitionEqualsHashCodeTest.java
new file mode 100644
index 0000000..7e34f77
--- /dev/null
+++ b/hudson-core/src/test/java/hudson/model/ChoiceParameterDefinitionEqualsHashCodeTest.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ *
+ * Copyright (c) 2011 Oracle Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+*
+* Nikita Levyankov
+ *
+ *
+ *******************************************************************************/
+package hudson.model;
+
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+
+/**
+ * Equals and hashCode test for {@link ChoiceParameterDefinition} object
+ * <p/>
+ * Date: 11/2/11
+ *
+ * @author Nikita Levyankov
+ */
+public class ChoiceParameterDefinitionEqualsHashCodeTest {
+
+ @Test
+ public void testEquals() {
+ ChoiceParameterDefinition o1 = new ChoiceParameterDefinition("name1", "value\nvalue2", "description");
+ assertEquals(o1, o1);
+ assertFalse(o1.equals(null));
+ assertFalse(o1.equals(new StringParameterDefinition("test1", "value\nvalue2", "description")));
+ assertFalse(new ChoiceParameterDefinition("name1", "value\nvalue2", null).equals(
+ new ChoiceParameterDefinition(null, "value\nvalue2", null)));
+ assertFalse(new ChoiceParameterDefinition(null, "value1", null).equals(
+ new ChoiceParameterDefinition(null, "value\nvalue2", null)));
+ assertFalse(o1.equals(new ChoiceParameterDefinition(null, "value1", null)));
+ assertFalse(o1.equals(new ChoiceParameterDefinition("name1", "value1", "description")));
+
+ assertEquals(o1, new ChoiceParameterDefinition("name1", "value\nvalue2", "description"));
+ assertEquals(o1, new ChoiceParameterDefinition("name1", "value\nvalue2", "description1"));
+ assertEquals(new ChoiceParameterDefinition(null, "value\nvalue2", "d1"),
+ new ChoiceParameterDefinition(null, "value\nvalue2", "d1"));
+ assertEquals(new ChoiceParameterDefinition(null, "value\nvalue2", null),
+ new ChoiceParameterDefinition(null, "value\nvalue2", null));
+ }
+
+ @Test
+ public void testHashCode() {
+ ChoiceParameterDefinition o1 = new ChoiceParameterDefinition("name1", "value\nvalue2", "description");
+ assertTrue(o1.hashCode() == o1.hashCode());
+ assertFalse(o1.hashCode() == new StringParameterDefinition("test1", "value\nvalue2", "description").hashCode());
+ assertFalse(new ChoiceParameterDefinition("name1", "value\nvalue2", null).hashCode() ==
+ new ChoiceParameterDefinition(null, "value\nvalue2", null).hashCode());
+ assertFalse(new ChoiceParameterDefinition(null, "value1", null).hashCode() ==
+ new ChoiceParameterDefinition(null, "value\nvalue2", null).hashCode());
+ assertFalse(o1.hashCode() == new ChoiceParameterDefinition(null, "value1", null).hashCode());
+ assertFalse(o1.hashCode() == new ChoiceParameterDefinition("name1", "value1", "description").hashCode());
+
+ assertTrue(o1.hashCode() == new ChoiceParameterDefinition("name1", "value\nvalue2", "description").hashCode());
+ assertTrue(o1.hashCode() == new ChoiceParameterDefinition("name1", "value\nvalue2", "description1").hashCode());
+ assertTrue(new ChoiceParameterDefinition(null, "value\nvalue2", "d1").hashCode() ==
+ new ChoiceParameterDefinition(null, "value\nvalue2", "d1").hashCode());
+ assertTrue(new ChoiceParameterDefinition(null, "value\nvalue2", null).hashCode() ==
+ new ChoiceParameterDefinition(null, "value\nvalue2", null).hashCode());
+ }
+}
diff --git a/hudson-core/src/test/java/hudson/model/PasswordParameterDefinitionEqualsHashCodeTest.java b/hudson-core/src/test/java/hudson/model/PasswordParameterDefinitionEqualsHashCodeTest.java
new file mode 100644
index 0000000..57bb41c
--- /dev/null
+++ b/hudson-core/src/test/java/hudson/model/PasswordParameterDefinitionEqualsHashCodeTest.java
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ *
+ * Copyright (c) 2011 Oracle Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+*
+* Nikita Levyankov
+ *
+ *
+ *******************************************************************************/
+package hudson.model;
+
+import hudson.util.Secret;
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.reflect.Whitebox;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+import static org.easymock.EasyMock.expect;
+import static org.powermock.api.easymock.PowerMock.createMock;
+import static org.powermock.api.easymock.PowerMock.mockStatic;
+import static org.powermock.api.easymock.PowerMock.replayAll;
+import static org.powermock.api.easymock.PowerMock.verifyAll;
+
+
+/**
+ * Equals and hashCode test for {@link PasswordParameterDefinition} object
+ * <p/>
+ * Date: 11/2/11
+ *
+ * @author Nikita Levyankov
+ */
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({Secret.class, Hudson.class})
+public class PasswordParameterDefinitionEqualsHashCodeTest {
+
+ @Before
+ public void setUp() throws Exception {
+ Hudson hudson = createMock(Hudson.class);
+ mockStatic(Hudson.class);
+ expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
+ mockStatic(Secret.class);
+ Secret secret = Whitebox.invokeConstructor(Secret.class, new Class<?>[]{String.class}, new String[]{"value"});
+ expect(Secret.fromString(EasyMock.<String>anyObject())).andReturn(secret).anyTimes();
+ expect(Secret.toString(EasyMock.<Secret>anyObject())).andReturn(secret.toString()).anyTimes();
+ replayAll();
+ }
+
+ @Test
+ public void testEquals() throws Exception {
+ PasswordParameterDefinition o1 = new PasswordParameterDefinition("name1", "value", "description");
+ assertEquals(o1, o1);
+ assertFalse(o1.equals(null));
+ assertFalse(o1.equals(new StringParameterDefinition("test1", "value", "description")));
+ assertFalse(new PasswordParameterDefinition("name1", "value", null).equals(
+ new PasswordParameterDefinition(null, "value", null)));
+
+ assertEquals(o1, new PasswordParameterDefinition("name1", "value", "description"));
+ assertEquals(o1, new PasswordParameterDefinition("name1", "value", "description1"));
+ assertEquals(new PasswordParameterDefinition(null, "value", "d1"),
+ new PasswordParameterDefinition(null, "value", "d1"));
+ assertEquals(new PasswordParameterDefinition(null, "value", null),
+ new PasswordParameterDefinition(null, "value", null));
+ verifyAll();
+ }
+
+ @Test
+ public void testHashCode() {
+ PasswordParameterDefinition o1 = new PasswordParameterDefinition("name1", "value", "description");
+ assertTrue(o1.hashCode() == o1.hashCode());
+ assertFalse(o1.hashCode() == new StringParameterDefinition("test1", "value", "description").hashCode());
+ assertFalse(new PasswordParameterDefinition("name1", "value", null).hashCode() ==
+ new PasswordParameterDefinition(null, "value", null).hashCode());
+ assertTrue(o1.hashCode() == new PasswordParameterDefinition("name1", "value", "description").hashCode());
+ assertTrue(o1.hashCode() == new PasswordParameterDefinition("name1", "value", "description1").hashCode());
+ assertTrue(new PasswordParameterDefinition(null, "value", "d1").hashCode() ==
+ new PasswordParameterDefinition(null, "value", "d1").hashCode());
+ assertTrue(new PasswordParameterDefinition(null, "value", null).hashCode() ==
+ new PasswordParameterDefinition(null, "value", null).hashCode());
+ verifyAll();
+ }
+}
diff --git a/hudson-core/src/test/java/hudson/model/RunParameterDefinitionEqualsHashCodeTest.java b/hudson-core/src/test/java/hudson/model/RunParameterDefinitionEqualsHashCodeTest.java
new file mode 100644
index 0000000..950af50
--- /dev/null
+++ b/hudson-core/src/test/java/hudson/model/RunParameterDefinitionEqualsHashCodeTest.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ *
+ * Copyright (c) 2011 Oracle Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+*
+* Nikita Levyankov
+ *
+ *
+ *******************************************************************************/
+package hudson.model;
+
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+
+/**
+ * Equals and hashCode test for {@link RunParameterDefinition} object
+ * <p/>
+ * Date: 11/2/11
+ *
+ * @author Nikita Levyankov
+ */
+public class RunParameterDefinitionEqualsHashCodeTest {
+
+ @Test
+ public void testEquals() {
+ RunParameterDefinition o1 = new RunParameterDefinition("name1", "value", "description");
+ assertEquals(o1, o1);
+ assertFalse(o1.equals(null));
+ assertFalse(o1.equals(new StringParameterDefinition("test1", "value", "description")));
+ assertFalse(new RunParameterDefinition("name1", "value", null).equals(
+ new RunParameterDefinition(null, "value", null)));
+ assertFalse(new RunParameterDefinition(null, "value1", null).equals(
+ new RunParameterDefinition(null, "value", null)));
+ assertFalse(o1.equals(new RunParameterDefinition(null, "value1", null)));
+ assertFalse(o1.equals(new RunParameterDefinition("name1", "value1", "description")));
+
+ assertEquals(o1, new RunParameterDefinition("name1", "value", "description"));
+ assertEquals(o1, new RunParameterDefinition("name1", "value", "description1"));
+ assertEquals(new RunParameterDefinition(null, "value", "d1"),
+ new RunParameterDefinition(null, "value", "d1"));
+ assertEquals(new RunParameterDefinition(null, "value", null),
+ new RunParameterDefinition(null, "value", null));
+ }
+
+ @Test
+ public void testHashCode() {
+ RunParameterDefinition o1 = new RunParameterDefinition("name1", "value", "description");
+ assertTrue(o1.hashCode() == o1.hashCode());
+ assertFalse(o1.equals(new StringParameterDefinition("test1", "value", "description")));
+ assertFalse(new RunParameterDefinition("name1", "value", null).hashCode() ==
+ new RunParameterDefinition(null, "value", null).hashCode());
+ assertFalse(new RunParameterDefinition(null, "value1", null).hashCode() ==
+ new RunParameterDefinition(null, "value", null).hashCode());
+ assertFalse(o1.hashCode() == new RunParameterDefinition(null, "value1", null).hashCode());
+ assertFalse(o1.hashCode() == new RunParameterDefinition("name1", "value1", "description").hashCode());
+
+ assertTrue(o1.hashCode() == new RunParameterDefinition("name1", "value", "description").hashCode());
+ assertTrue(o1.hashCode() == new RunParameterDefinition("name1", "value", "description1").hashCode());
+ assertTrue(new RunParameterDefinition(null, "value", "d1").hashCode() ==
+ new RunParameterDefinition(null, "value", "d1").hashCode());
+ assertTrue(new RunParameterDefinition(null, "value", null).hashCode() ==
+ new RunParameterDefinition(null, "value", null).hashCode());
+ }
+}
diff --git a/hudson-core/src/test/java/hudson/model/StringParameterDefinitionEqualsHashCodeTest.java b/hudson-core/src/test/java/hudson/model/StringParameterDefinitionEqualsHashCodeTest.java
new file mode 100644
index 0000000..4ff2fd8
--- /dev/null
+++ b/hudson-core/src/test/java/hudson/model/StringParameterDefinitionEqualsHashCodeTest.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ *
+ * Copyright (c) 2011 Oracle Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+*
+* Nikita Levyankov
+ *
+ *
+ *******************************************************************************/
+package hudson.model;
+
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+
+/**
+ * Equals and hashCode test for {@link StringParameterDefinition} object
+ * <p/>
+ * Date: 11/2/11
+ *
+ * @author Nikita Levyankov
+ */
+public class StringParameterDefinitionEqualsHashCodeTest {
+
+ @Test
+ public void testEquals() {
+ StringParameterDefinition o1 = new StringParameterDefinition("name1", "value", "description");
+ assertEquals(o1, o1);
+ assertFalse(o1.equals(null));
+ assertFalse(o1.equals(new RunParameterDefinition("test1", "value", "description")));
+ assertFalse(new StringParameterDefinition("name1", "value", null).equals(
+ new StringParameterDefinition(null, "value", null)));
+ assertFalse(new StringParameterDefinition(null, "value1", null).equals(
+ new StringParameterDefinition(null, "value", null)));
+ assertFalse(o1.equals(new StringParameterDefinition(null, "value1", null)));
+ assertFalse(o1.equals(new StringParameterDefinition("name1", "value1", "description")));
+
+ assertEquals(o1, new StringParameterDefinition("name1", "value", "description"));
+ assertEquals(o1, new StringParameterDefinition("name1", "value", "description1"));
+ assertEquals(new StringParameterDefinition(null, "value", "d1"),
+ new StringParameterDefinition(null, "value", "d1"));
+ assertEquals(new StringParameterDefinition(null, "value", null),
+ new StringParameterDefinition(null, "value", null));
+ }
+
+ @Test
+ public void testHashCode() {
+ StringParameterDefinition o1 = new StringParameterDefinition("name1", "value", "description");
+ assertTrue(o1.hashCode() == o1.hashCode());
+ assertFalse(o1.hashCode() == new RunParameterDefinition("test1", "value", "description").hashCode());
+ assertFalse(new StringParameterDefinition("name1", "value", null).hashCode() ==
+ new StringParameterDefinition(null, "value", null).hashCode());
+ assertFalse(new StringParameterDefinition(null, "value1", null).hashCode() ==
+ new StringParameterDefinition(null, "value", null).hashCode());
+ assertFalse(o1.hashCode() == new StringParameterDefinition(null, "value1", null).hashCode());
+ assertFalse(o1.hashCode() == new StringParameterDefinition("name1", "value1", "description").hashCode());
+
+ assertTrue(o1.hashCode() == new StringParameterDefinition("name1", "value", "description").hashCode());
+ assertTrue(o1.hashCode() == new StringParameterDefinition("name1", "value", "description1").hashCode());
+ assertTrue(new StringParameterDefinition(null, "value", "d1").hashCode() ==
+ new StringParameterDefinition(null, "value", "d1").hashCode());
+ assertTrue(new StringParameterDefinition(null, "value", null).hashCode() ==
+ new StringParameterDefinition(null, "value", null).hashCode());
+ }
+}