-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The only direct guava usage was a single function, so reimplented. This prevents the downlaod of an extra dependency when running in a clean environment like CI.
- Loading branch information
Showing
5 changed files
with
86 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/org/jenkinsci/maven/plugins/hp/util/Utils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.jenkinsci.maven.plugins.hp.util; | ||
|
||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class Utils { | ||
|
||
/** | ||
* Return an unmodifiable set whose contents are the unions of all the specified sets. | ||
*/ | ||
@SafeVarargs | ||
public static <T> Set<T> unionOf(Set<T>... sets) { | ||
Set<T> unionSet = new HashSet<>(sets[0]); | ||
for (int i = 1; i < sets.length; i++) { | ||
unionSet.addAll(sets[i]); | ||
} | ||
return Collections.unmodifiableSet(unionSet); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/test/java/org/jenkinsci/maven/plugins/hpi/util/UtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.jenkinsci.maven.plugins.hpi.util; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsInAnyOrder; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
import org.jenkinsci.maven.plugins.hp.util.Utils; | ||
import org.junit.Test; | ||
|
||
public class UtilsTest { | ||
|
||
@Test | ||
public void setUnionCalculation() { | ||
checkUnion("union of a set is itself", | ||
new String[] {"one", "two", "three"}, | ||
Set.of("one", "two", "three")); | ||
|
||
checkUnion("union of 2 sets is correct", | ||
new String[] {"one", "two", "three", "four", "five", "six"}, | ||
Set.of("one", "two", "three"), | ||
Set.of("four", "five", "six")); | ||
|
||
checkUnion("union of 3 sets is correct", | ||
new String[] {"one", "two", "three", "four", "five", "six", "seven"}, | ||
Set.of("one", "three", "five"), | ||
Set.of("two", "four", "six"), | ||
Set.of("one", "seven")); | ||
|
||
checkUnion("union of overlapping sets", | ||
new String[] {"one", "two", "three"}, | ||
Set.of("one", "two", "three"), | ||
Set.of("one", "two", "three"), | ||
Set.of("one", "two", "three"), | ||
Set.of("one", "two", "three"), | ||
Set.of("one", "two", "three"), | ||
Set.of("one", "two", "three")); | ||
|
||
checkUnion("union of an empty set and something is something", | ||
new String[] {"four", "five", "six"}, | ||
Collections.emptySet(), | ||
Set.of("four", "five", "six")); | ||
|
||
checkUnion("union of something and an empty set and is somethine", | ||
new String[] {"four", "five", "six"}, | ||
Set.of("four", "five", "six"), | ||
Collections.emptySet()); | ||
|
||
checkUnion("union of 2 empty sets is empty", | ||
new String[] {}, | ||
Collections.emptySet(), | ||
Collections.emptySet()); | ||
|
||
} | ||
|
||
@SafeVarargs | ||
public static <T> void checkUnion(String reason, T[] expected, Set<T>... unions) { | ||
assertThat(reason, Utils.unionOf(unions), containsInAnyOrder(expected)); | ||
} | ||
|
||
} |