Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIXED JENKINS-18534] equals()/hashCode() for parameter value #87

Merged
merged 2 commits into from Jul 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -64,6 +64,28 @@ public String resolve(String name) {
};
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ListSubversionTagsParameterValue)) return false;
if (!super.equals(o)) return false;

ListSubversionTagsParameterValue that = (ListSubversionTagsParameterValue) o;

if (tag != null ? !tag.equals(that.tag) : that.tag != null) return false;
if (tagsDir != null ? !tagsDir.equals(that.tagsDir) : that.tagsDir != null) return false;

return true;
}

@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (tagsDir != null ? tagsDir.hashCode() : 0);
result = 31 * result + (tag != null ? tag.hashCode() : 0);
return result;
}

public String getTag() {
return tag;
}
Expand Down
@@ -0,0 +1,78 @@
package hudson.scm.listtagsparameter;

import org.junit.Test;
import org.jvnet.hudson.test.Bug;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;

/**
* Created by schristou88 on 6/24/14.
*/
public class ListSubversionTagsParameterValueTest {
String expectedName = "name";
String expectedTag = "tag";
String expectedTagsDir = "/tmp";
/**
* Since we are overriding the equals method, we should write a test unit.
*/
@Test
@Bug(18534)
public void testEquality() {
ListSubversionTagsParameterValue parameterValue = new ListSubversionTagsParameterValue(expectedName,
expectedTag,
expectedTagsDir);

assertEquals(parameterValue, parameterValue);

// When name is different
ListSubversionTagsParameterValue otherParameterValue = new ListSubversionTagsParameterValue("different",
expectedTag,
expectedTagsDir);
assertNotEquals("Two parameter values should NOT be equal if the only difference is the name.",
parameterValue,
otherParameterValue);

// When tag is different
otherParameterValue = new ListSubversionTagsParameterValue(expectedName,
"tag2",
expectedTagsDir);
assertNotEquals("Two parameter values should NOT be equal if the difference is the tag.",
parameterValue,
otherParameterValue);

// When tagsdir is different
otherParameterValue = new ListSubversionTagsParameterValue(expectedName,
expectedTag,
"/tmp1");
assertNotEquals("Two parameter values should NOT be equal if the difference is the tagsDir.",
parameterValue,
otherParameterValue);

otherParameterValue = new ListSubversionTagsParameterValue(expectedName,
expectedTag,
expectedTagsDir);
assertEquals("Two parameters with the same value should also be equal.",
parameterValue,
otherParameterValue);
}

/**
* Since we are overriding the hashcode method, we should write a test unit.
*/
@Test
@Bug(18534)
public void testHashCode() {
ListSubversionTagsParameterValue parameterValue = new ListSubversionTagsParameterValue(expectedName,
expectedTag,
expectedTagsDir);

assertEquals(parameterValue.hashCode(), parameterValue.hashCode());

ListSubversionTagsParameterValue otherParameterValue = new ListSubversionTagsParameterValue(expectedName,
expectedTag,
expectedTagsDir);

assertEquals(parameterValue.hashCode(), otherParameterValue.hashCode());
}
}