Skip to content

Commit

Permalink
JAXRSParser / JAXRSParserTest fixed on Windows platform (issue cagata…
Browse files Browse the repository at this point in the history
  • Loading branch information
refacktor committed Mar 29, 2019
1 parent f727466 commit e2dd4a3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ private List<Class<? extends Object>> getClassesInPackage(String packageName, Cl
final String classSeperator = ".";


final String jarPath = clazz.getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
final URL location = clazz.getProtectionDomain().getCodeSource().getLocation();
final String jarPath = new File(location.toURI()).getAbsolutePath();

if (jarPath.endsWith(".jar")) {
/**
Expand All @@ -115,7 +116,7 @@ private List<Class<? extends Object>> getClassesInPackage(String packageName, Cl
return getClassesInJarFile(jarPath);
}

final String packagePath = jarPath + packageName.replace(classSeperator, File.separator);
final String packagePath = jarPath + File.separator + packageName.replace(classSeperator, File.separator);

Files.walkFileTree(Paths.get(packagePath), new SimpleFileVisitor<Path>() {
@Override
Expand All @@ -125,7 +126,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
String fileName = file.toString();

if (fileName.endsWith(classExtension)) {
String className = fileName.replace(jarPath, blank).replace(File.separator, classSeperator);
String className = fileName.replace(jarPath + File.separator, blank).replace(File.separator, classSeperator);
className = className.substring(0, className.length() - classExtension.length());

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import java.io.File;
import java.io.FilenameFilter;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import org.junit.Test;
Expand Down Expand Up @@ -43,8 +45,24 @@ public void testScanPackage() throws Exception {
}
assertEquals(6, totalMethod);

Collections.sort(resourceList, new PathComparator());

assertEquals("/resource1", resourceList.get(0).getPath());
assertEquals("/resource1", resourceList.get(1).getPath());
assertEquals("/resource1/{id}", resourceList.get(2).getPath());
assertEquals("/resource1/{id}/users", resourceList.get(3).getPath());
}

private class PathComparator implements Comparator<Resource> {

@Override
public int compare(Resource o1, Resource o2) {
return o1.getPath().compareTo(o2.getPath());
}

@Override
public boolean equals(Object obj) {
return false;
}
}
}

0 comments on commit e2dd4a3

Please # to comment.