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