Skip to content

Commit b5593c1

Browse files
committed
Add unit tests of IssueFilter
1 parent b5fb1b0 commit b5593c1

2 files changed

Lines changed: 75 additions & 2 deletions

File tree

app/src/main/java/com/github/mobile/core/issue/IssueFilter.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,9 @@ public CharSequence toDisplay() {
240240

241241
@Override
242242
public int hashCode() {
243-
return Arrays.hashCode(new Object[] { open, assignee, milestone, assignee,
244-
repository != null ? repository.generateId() : null, labels });
243+
return Arrays.hashCode(new Object[] { open, assignee != null ? assignee.getId() : null,
244+
milestone != null ? milestone.getNumber() : null, assignee != null ? assignee.getId() : null,
245+
repository != null ? repository.getId() : null, labels });
245246
}
246247

247248
private boolean isEqual(Object a, Object b) {
@@ -262,6 +263,10 @@ private boolean isEqual(User a, User b) {
262263
return a != null && b != null && a.getId() == b.getId();
263264
}
264265

266+
private boolean isEqual(Repository a, Repository b) {
267+
return a != null && b != null && a.getId() == b.getId();
268+
}
269+
265270
@Override
266271
public boolean equals(Object o) {
267272
if (o == this)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2012 GitHub Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.github.mobile.core.issue;
17+
18+
import static org.junit.Assert.assertEquals;
19+
import static org.junit.Assert.assertFalse;
20+
import static org.junit.Assert.assertTrue;
21+
22+
import org.eclipse.egit.github.core.Milestone;
23+
import org.eclipse.egit.github.core.Repository;
24+
import org.eclipse.egit.github.core.User;
25+
import org.junit.Test;
26+
27+
/**
28+
* Unit tests of {@link IssueFilter}
29+
*/
30+
public class IssueFilterTest {
31+
32+
/**
33+
* Verify {@link IssueFilter#equals(Object)}
34+
*/
35+
@Test
36+
public void equalFilter() {
37+
Repository repo = new Repository().setId(1);
38+
IssueFilter filter1 = new IssueFilter(repo);
39+
40+
assertFalse(filter1.equals(null));
41+
assertFalse(filter1.equals(""));
42+
assertTrue(filter1.equals(filter1));
43+
44+
IssueFilter filter2 = new IssueFilter(repo);
45+
assertEquals(filter1, filter2);
46+
assertEquals(filter1.hashCode(), filter2.hashCode());
47+
48+
User user = new User().setId(2);
49+
filter1.setAssignee(user);
50+
assertFalse(filter1.equals(filter2));
51+
filter2.setAssignee(user);
52+
assertEquals(filter1, filter2);
53+
assertEquals(filter1.hashCode(), filter2.hashCode());
54+
55+
filter1.setOpen(false);
56+
assertFalse(filter1.equals(filter2));
57+
filter2.setOpen(false);
58+
assertEquals(filter1, filter2);
59+
assertEquals(filter1.hashCode(), filter2.hashCode());
60+
61+
Milestone milestone = new Milestone().setNumber(3);
62+
filter1.setMilestone(milestone);
63+
assertFalse(filter1.equals(filter2));
64+
filter2.setMilestone(milestone);
65+
assertEquals(filter1, filter2);
66+
assertEquals(filter1.hashCode(), filter2.hashCode());
67+
}
68+
}

0 commit comments

Comments
 (0)