Comments (6)
So to be clear, your proposed resolution is to replace getParentClassloader
in GwtMockitoTestRunner
so that it returns Thread.currentThread().getContextClassLoader()
instead of ClassLoader.getSystemClassLoader()
?
This seems to me like it's probably the right thing to do; I'm trying to think if it might have any negative side effects. If I understand correctly, IDEA's test runner presumably works by starting a thread, setting that thread's context classloader to something magical, then executing the test on that thread. By having the parent classloader be the system classloader, we're basically bypassing whatever IDEA had set.
In most cases the context classloader will be the same as the system classloader, but in the cases where it's not it's because some tool quite explicitly wanted to use a different classloader for that thread. So it's always going to be better to respect that preference than to force the system classloader.
Does that reasoning sound correct? If so and no one objects I'll make the change. If this is blocking you, you can create your own subclass of GwtMockitoTestRunner
that overrides the parent classloader in the meantime.
Thanks for tracking down the problem, these classloader bugs are always super tricky.
from gwtmockito.
Yes, what I did for the version I'm now using in IDEA and with plain Maven is exactly as you described.
And yes, the reasoning sounds correct as well. If you are not interested in resources tied to a particular class, the thread context classloader is always the best bet.
I thought creating a custom subclass would not be all that simple in 1.1.5, but looking at it again now, it seems I might be mistaken. I'll probably try that on Monday.
Edit:
Tried to work around this by subclassing in 1.1.5. Overriding getParentClassloader()
isn't enough, since the parent class loder isn't explicitly added to the classpath of the ClassPool in 1.1.5. master or 1.1.6 fixes this.
from gwtmockito.
If I understand correctly, IDEA's test runner presumably works by starting a thread, setting that thread's context classloader to something magical, then executing the test on that thread.
Or more likely just setting the current thread's context classloader to some kind of URLClassLoader
to simply isolate your project's classpath from IDEA test runner's one.
Maven uses some similar techniques under certain conditions so it can happen there too: https://maven.apache.org/surefire/maven-surefire-plugin/examples/class-loading.html
from gwtmockito.
Alright, I've made the change and pushed a new snapshot to Maven. Been a while since the last release, so I'll release 1.1.6 in a week or so if no one reports any problems
from gwtmockito.
Still no 1.1.6 release.
from gwtmockito.
Apologies for the long delay. 1.1.6 has been released and should now be available on Maven Central.
from gwtmockito.
Related Issues (20)
- getting GwtMockitoTestRunner$FailedCastException in DateBox HOT 1
- ClassCastException with JsArrayInteger HOT 1
- Since Mockito 2.1.0 TextBox.setValue(null) does not work anymore HOT 4
- ToggleButton ClassCastException
- What does it mean "Illegal class modifiers" ? HOT 1
- JaCoCo support not working HOT 7
- Better GWT unit testing http://google.github.io/gwtmockito hyperLink HOT 2
- Provide an example in the samples or documentation for doing code coverage HOT 1
- #68 broke the build HOT 1
- Java 9 support HOT 2
- gwtmockito and GXT HOT 1
- Java 10 upgrade: java.lang.IllegalStateException HOT 3
- javassist 3.22.0-GA breaks gwtmockito ("class is frozen") HOT 3
- Mockito failure with Java11 HOT 1
- gwtmockito v1.1.9 is not available in public repos HOT 3
- IllegalAccessError when using GwtMockitoTestRunner
- Release 1.1.9 is incomplete in maven repository HOT 1
- ClassCastException When Calling MenuItem.setTitle HOT 2
- Junit5 support HOT 1
- Problem with Java 17
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gwtmockito.