-
-
Notifications
You must be signed in to change notification settings - Fork 128
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
Solves issue #530 #536
Solves issue #530 #536
Conversation
Pull Request Test Coverage Report for Build 1102
💛 - Coveralls |
I like this solution because it does not involve adding a new dependency. |
I'm thinking how to create a test for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you think that getClasses
method is too big you can split it in small pieces (getClassesFromJar
, getClassesFromXYZ
) if you think that this operation improve the readability.
pippo-controller-parent/pippo-controller/src/main/java/ro/pippo/controller/util/ClassUtils.java
Outdated
Show resolved
Hide resolved
pippo-controller-parent/pippo-controller/src/main/java/ro/pippo/controller/util/ClassUtils.java
Outdated
Show resolved
Hide resolved
Hi @decebals ! Let me know if you want me to change anything. I needed to create dummy classes and a ultra small jar inside src/test/resources/ in order to create the test for the |
I am happy to see some tests 😄. I think that the PR is good. I prefer to not store the classes use din test and the jar file but this is another story. I think that we can improve this aspect in the future. |
Hi @decebals ! I agree with you! I'll take a look at what you said. I saw that your AbstractExtensionFinderTest user |
This means that the work is almost ready 😄. I redirected you to PF4J just to see the code. If you like something from that project, you can use that part here. If you think that it's too complicate for our needs, try to find something more simple. |
Hi @decebals ! Today I looked at it again and I have good and bad news.
Creating the Jar and classes at test run time worked! 🥳
As we are testing a class with static methods I need to use If I remove I kind of blindly tried to use the runner Another solution, which works, is to hack the public class ClassUtils {
private final static Logger log = LoggerFactory.getLogger(ClassUtils.class);
private static ClassUtils INSTANCE; // added
protected ClassUtils() { // added
ClassUtils.INSTANCE = this;
}
@SuppressWarnings("unchecked")
public static <T> Class<T> getClass(String className) {
try {
// return (Class<T>) Class.forName(className); // removed
return (Class<T>) Class.forName(className, true, INSTANCE.getClassLoader()); // added
} catch (Exception e) {
throw new PippoRuntimeException("Failed to get class '{}'", className);
}
}
protected ClassLoader getClassLoader() { // added - It will be mocked in the test
return this.getClass().getClassLoader();
}
// ...
} Within the public static class ClassUtilsMock extends ClassUtils {
private URL jarUrl;
ClassUtilsMock(URL jarUrl) {
super();
this.jarUrl = jarUrl;
}
@Override
protected ClassLoader getClassLoader() {
return new URLClassLoader(new URL[] { jarUrl });
}
} And in the test methods I refer to What do you think? Any comments? ps: I haven't committed yet. |
Ohh, I had forgotten about this:
I spent a lot of time on this! Adding the annotation below to the test class the problem went away: @PowerMockIgnore({
"com.sun.tools.*",
"javax.tools.*",
}) |
Hi @decebals ! All changes are done. Please let me know if you want me to make any changes. |
You committed a new |
The code looks clean. I think that you can merge this request (always with squash :)). I don't know about file |
Hi! Folders/files that are auto-generated can be marked in Eclipse as This file is from this plugin: https://nodj.github.io/AutoDeriv/ I can remove it without any problems. What do you say? |
Yes. And I think that is a good idea to add a new entry in |
Solves #530