Skip to content

Commit 7fecc42

Browse files
committed
Merge pull request #87 from daniel-beck/JENKINS-18534
[FIXED JENKINS-18534] equals()/hashCode() for parameter value
2 parents 2a16745 + 8a96c32 commit 7fecc42

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

src/main/java/hudson/scm/listtagsparameter/ListSubversionTagsParameterValue.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,28 @@ public String resolve(String name) {
6464
};
6565
}
6666

67+
@Override
68+
public boolean equals(Object o) {
69+
if (this == o) return true;
70+
if (!(o instanceof ListSubversionTagsParameterValue)) return false;
71+
if (!super.equals(o)) return false;
72+
73+
ListSubversionTagsParameterValue that = (ListSubversionTagsParameterValue) o;
74+
75+
if (tag != null ? !tag.equals(that.tag) : that.tag != null) return false;
76+
if (tagsDir != null ? !tagsDir.equals(that.tagsDir) : that.tagsDir != null) return false;
77+
78+
return true;
79+
}
80+
81+
@Override
82+
public int hashCode() {
83+
int result = super.hashCode();
84+
result = 31 * result + (tagsDir != null ? tagsDir.hashCode() : 0);
85+
result = 31 * result + (tag != null ? tag.hashCode() : 0);
86+
return result;
87+
}
88+
6789
public String getTag() {
6890
return tag;
6991
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package hudson.scm.listtagsparameter;
2+
3+
import org.junit.Test;
4+
import org.jvnet.hudson.test.Bug;
5+
6+
import static org.junit.Assert.assertEquals;
7+
import static org.junit.Assert.assertNotEquals;
8+
9+
/**
10+
* Created by schristou88 on 6/24/14.
11+
*/
12+
public class ListSubversionTagsParameterValueTest {
13+
String expectedName = "name";
14+
String expectedTag = "tag";
15+
String expectedTagsDir = "/tmp";
16+
/**
17+
* Since we are overriding the equals method, we should write a test unit.
18+
*/
19+
@Test
20+
@Bug(18534)
21+
public void testEquality() {
22+
ListSubversionTagsParameterValue parameterValue = new ListSubversionTagsParameterValue(expectedName,
23+
expectedTag,
24+
expectedTagsDir);
25+
26+
assertEquals(parameterValue, parameterValue);
27+
28+
// When name is different
29+
ListSubversionTagsParameterValue otherParameterValue = new ListSubversionTagsParameterValue("different",
30+
expectedTag,
31+
expectedTagsDir);
32+
assertNotEquals("Two parameter values should NOT be equal if the only difference is the name.",
33+
parameterValue,
34+
otherParameterValue);
35+
36+
// When tag is different
37+
otherParameterValue = new ListSubversionTagsParameterValue(expectedName,
38+
"tag2",
39+
expectedTagsDir);
40+
assertNotEquals("Two parameter values should NOT be equal if the difference is the tag.",
41+
parameterValue,
42+
otherParameterValue);
43+
44+
// When tagsdir is different
45+
otherParameterValue = new ListSubversionTagsParameterValue(expectedName,
46+
expectedTag,
47+
"/tmp1");
48+
assertNotEquals("Two parameter values should NOT be equal if the difference is the tagsDir.",
49+
parameterValue,
50+
otherParameterValue);
51+
52+
otherParameterValue = new ListSubversionTagsParameterValue(expectedName,
53+
expectedTag,
54+
expectedTagsDir);
55+
assertEquals("Two parameters with the same value should also be equal.",
56+
parameterValue,
57+
otherParameterValue);
58+
}
59+
60+
/**
61+
* Since we are overriding the hashcode method, we should write a test unit.
62+
*/
63+
@Test
64+
@Bug(18534)
65+
public void testHashCode() {
66+
ListSubversionTagsParameterValue parameterValue = new ListSubversionTagsParameterValue(expectedName,
67+
expectedTag,
68+
expectedTagsDir);
69+
70+
assertEquals(parameterValue.hashCode(), parameterValue.hashCode());
71+
72+
ListSubversionTagsParameterValue otherParameterValue = new ListSubversionTagsParameterValue(expectedName,
73+
expectedTag,
74+
expectedTagsDir);
75+
76+
assertEquals(parameterValue.hashCode(), otherParameterValue.hashCode());
77+
}
78+
}

0 commit comments

Comments
 (0)