Skip to content

Commit 51c580e

Browse files
committed
Implement equals/hashCode for Filters
1 parent 135cfe5 commit 51c580e

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

src/main/java/com/github/dockerjava/api/model/Filters.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,22 @@ private static List<String> labelsMapToList(Map<String, String> labels) {
9292
return result;
9393
}
9494

95+
@Override
96+
public boolean equals(Object o) {
97+
if (this == o) return true;
98+
if (o == null || getClass() != o.getClass()) return false;
99+
100+
Filters filters1 = (Filters) o;
101+
102+
return filters.equals(filters1.filters);
103+
104+
}
105+
106+
@Override
107+
public int hashCode() {
108+
return filters.hashCode();
109+
}
110+
95111
@Override
96112
public String toString() {
97113
try {
@@ -100,4 +116,5 @@ public String toString() {
100116
throw new RuntimeException(e);
101117
}
102118
}
119+
103120
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.github.dockerjava.api.model;
2+
3+
import com.google.common.collect.Maps;
4+
import org.testng.annotations.Test;
5+
6+
import java.util.Map;
7+
8+
import static org.testng.Assert.assertEquals;
9+
import static org.testng.Assert.assertNotSame;
10+
11+
/**
12+
* @author Vincent Latombe <vincent@latombe.net>
13+
*/
14+
public class FiltersTest {
15+
16+
@Test
17+
public void newFiltersShouldBeEquals() {
18+
assertEquals(new Filters(), new Filters());
19+
}
20+
21+
@Test
22+
public void filtersWithEqualContentShouldBeEquals() {
23+
assertEquals(new Filters().withContainers("foo"), new Filters().withContainers("foo"));
24+
assertEquals(new Filters().withLabels("alpha=val"), new Filters().withLabels("alpha=val"));
25+
}
26+
27+
@Test
28+
public void withLabelsMapShouldBeEquivalentToVarargs() {
29+
Map<String, String> map = Maps.newHashMap();
30+
map.put("alpha", "val");
31+
assertEquals(new Filters().withLabels("alpha=val"), new Filters().withLabels(map));
32+
33+
map = Maps.newHashMap();
34+
map.put("alpha", "val");
35+
map.put("beta", "val1");
36+
assertEquals(new Filters().withLabels("alpha=val", "beta=val1"), new Filters().withLabels(map));
37+
}
38+
39+
@Test
40+
public void filtersWithDifferentContentShouldntBeEquals() {
41+
assertNotSame(new Filters().withContainers("foo"), new Filters().withContainers("bar"));
42+
}
43+
}

0 commit comments

Comments
 (0)