Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/main/java/com/github/dockerjava/api/model/Filters.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,22 @@ private static List<String> labelsMapToList(Map<String, String> labels) {
return result;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Filters filters1 = (Filters) o;

return filters.equals(filters1.filters);

}

@Override
public int hashCode() {
return filters.hashCode();
}

@Override
public String toString() {
try {
Expand All @@ -100,4 +116,5 @@ public String toString() {
throw new RuntimeException(e);
}
}

}
43 changes: 43 additions & 0 deletions src/test/java/com/github/dockerjava/api/model/FiltersTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.github.dockerjava.api.model;

import com.google.common.collect.Maps;
import org.testng.annotations.Test;

import java.util.Map;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotSame;

/**
* @author Vincent Latombe <[email protected]>
*/
public class FiltersTest {

@Test
public void newFiltersShouldBeEquals() {
assertEquals(new Filters(), new Filters());
}

@Test
public void filtersWithEqualContentShouldBeEquals() {
assertEquals(new Filters().withContainers("foo"), new Filters().withContainers("foo"));
assertEquals(new Filters().withLabels("alpha=val"), new Filters().withLabels("alpha=val"));
}

@Test
public void withLabelsMapShouldBeEquivalentToVarargs() {
Map<String, String> map = Maps.newHashMap();
map.put("alpha", "val");
assertEquals(new Filters().withLabels("alpha=val"), new Filters().withLabels(map));

map = Maps.newHashMap();
map.put("alpha", "val");
map.put("beta", "val1");
assertEquals(new Filters().withLabels("alpha=val", "beta=val1"), new Filters().withLabels(map));
}

@Test
public void filtersWithDifferentContentShouldntBeEquals() {
assertNotSame(new Filters().withContainers("foo"), new Filters().withContainers("bar"));
}
}