Comments (5)
Although I am unfamiliar to the the Thales JCPROV library, I am a bit curious on this issue. I am wondering if you have tried checking if your class is missing in your class path by simply trying to use the static method before mocking it because this has happened to me once before. But based on your issue since you are work involves with native code maybe mocking the native methods is not the best route because I have heard of challenges on doing this. Have you tried exploring doing something like encapsulating it in a wrapper class or in an interface?
from mockito.
Yes, the library is in the classpath: if I call one of the methods without mocking, it fails in the static initialization block with a missing native library error, as expected.
Also yes, wrapping works fine as a workaround. In addition, there is another class (still part of the library) that offers similar static methods, wrapping each native call with exception throwing in case of errors, and mocking this class works as expected.
from mockito.
Interesting. Does the other successful class also share the same characteristics as the class you are having problems with or are there differences? I am wondering if two classes share the last bullet you mentioned in the post. Also, have you explored using PowerMock perhaps?
from mockito.
No, they are not the same. The successful one:
- Is also public, top level and non-final
- Has also default constructor that is private and does nothing
- Has public methods that are all static but not native
- Has no static initialization block (i.e., no load of a native library)
Imagine something like:
public class NativeClass {
private NativeClass() {}
public static native int method();
static {
System.loadLibrary("native");
}
}
public class WrapperClass {
private WrapperClass() {}
public static int method() {
int result = NativeClass.method();
if (result != 0) throw new RuntimeException(result);
}
}
(written without checking the original code – beware of typos 🙂 )
from mockito.
After reading your difference , it makes sense to why you are seeing it fail because it seems like a common known issue that Mockito is unable to mock native methods; it is currently a limitation on Mockito as of now. Perhaps you can try PowerMock as an alternative solution but I am not aware of a definitive solution.. unless we develop on this maybe creating a discussion on this topic might help.
from mockito.
Related Issues (20)
- In TypeBasedCandidateFilter.isCompatibleTypes -> ClassCastException: class TypeVariableImpl cannot be cast to class Class HOT 9
- Spy does not see method called in feedback call HOT 3
- Mockito.mock(...) does not work inside an Arquillian integration test anymore HOT 1
- Feature Request: MockedConstruction needs a setInitializer method
- ArgumentMatcher like assertArg() for multiple different calls? HOT 3
- Mockito does not work on Java 21 HOT 3
- Mockito.mock() not mocking the Class in Java 17 HOT 1
- ArgumentMatcher for one property
- Tests failures after adding mockito-inline on Java 21 HOT 1
- springjpa+junit5+mockito+querydsl
- ungraceful failure from instrumented code
- AdditionalMatchers.and() and or() swap matcher order HOT 5
- Failing while building mockito-inline version 4.6.1 using ./gradlew build (org.mockito:mockito-inline:4.6.1) HOT 1
- Mockito does not work with OTEL extension api in classpath HOT 1
- verify can't differ/handle logging methods with "Object... arguments" in signature
- Not possible to mock Thread.sleep
- WIthMockito feature request
- potential editorconfig enhancement HOT 2
- Mockito 5.12.0 and Java 22 HOT 3
- Mockito cannot mock this class HOT 1
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 mockito.