Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URGENT review: test: Add missing packages in enforcer test #1710

Merged
merged 1 commit into from
Nov 10, 2017
Merged
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package spoon.test.architecture;

import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import spoon.Launcher;
import spoon.SpoonAPI;
Expand All @@ -19,6 +20,7 @@
import spoon.reflect.visitor.filter.AbstractFilter;
import spoon.reflect.visitor.filter.TypeFilter;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
Expand Down Expand Up @@ -248,6 +250,8 @@ public void testSpecPackage() throws Exception {
officialPackages.add("spoon.support.reflect.cu");
officialPackages.add("spoon.support.reflect.declaration");
officialPackages.add("spoon.support.reflect.eval");
officialPackages.add("spoon.reflect.meta");
officialPackages.add("spoon.reflect.meta.impl");
officialPackages.add("spoon.support.reflect.reference");
officialPackages.add("spoon.support.reflect");
officialPackages.add("spoon.support.template");
Expand Down Expand Up @@ -280,19 +284,36 @@ public void process(CtPackage element) {
assertSetEquals("you have created a new package or removed an existing one, please declare it explicitly in SpoonArchitectureEnforcerTest#testSpecPackage", officialPackages, currentPackages);
}

public static void assertSetEquals(String msg, Set<?> set1, Set<?> set2){

private static void assertSetEquals(String msg, Set<?> set1, Set<?> set2){
if(set1 == null || set2 ==null){
throw new IllegalArgumentException();
}

if(set1.size()!=set2.size()){
throw new AssertionError(msg);
if(set1.size() != set2.size()){
throw new AssertionError(msg+"\n\nDetails: "+computeDifference(set1, set2));
}

if (!set1.containsAll(set2)) {
throw new AssertionError(msg);
throw new AssertionError(msg+"\n\nDetails: "+computeDifference(set1, set2));
}

}

private static String computeDifference(Set<?> set1, Set<?> set2) {
Set<String> results = new HashSet<>();

for (Object o : set1) {
if (!set2.contains(o)) {
results.add("Missing package "+o+" in computed set");
} else {
set2.remove(o);
}
}

for (Object o : set2) {
results.add("Package "+o+" presents in computed but not expected set.");
}

return StringUtils.join(results, "\n");
}
}