Comments (7)
That would be great, but for now our build has to be compatible with Java 5. So
we cannot yet use Java 6,7 or 8 symbols or types.
However a specific jdk8 distribution of mockito is clearly not ruled out.
Original comment by [email protected]
on 8 Jul 2014 at 9:12
- Added labels: jdk8
from mockito.
Why not dynamically include modules if a required Java version (or any other
library) is present?
The Spring Framework does something like this in many places, mainly to load
plugins depending on the presence of a certain class in the class path. See
https://github.com/spring-projects/spring-framework/blob/master/spring-web/src/m
ain/java/org/springframework/web/client/RestTemplate.java#L130
Demo code that loads a class only if the Java version meets a certain
requirement follows (with console output and simplified error handling to keep
things simple).
public final class DynamicImport {
private static final int JAVA_VERSION;
static {
final String versionString = System.getProperty("java.version");
final Matcher matcher = Pattern.compile("^1\\.(\\d+)\\.\\d+_\\d+$").matcher(versionString);
if (!matcher.matches()) {
throw new IllegalStateException(String.format("Can't parse Java version [%s]", versionString));
}
JAVA_VERSION = Integer.parseInt(matcher.group(1));
}
private DynamicImport() {
// utility class
}
public static void includeClass(final int minVersion, final String className, final ClassLoader loader) {
if (JAVA_VERSION < minVersion) {
System.out.println(String.format("Skipping loading of class [%s]: Java version %d is lower than required %d", className,
JAVA_VERSION, minVersion));
return;
}
try {
System.out.println(String.format("Loading class [%s]", className));
Class.forName(className, true, loader);
} catch (final ClassNotFoundException e) {
throw new IllegalStateException(String.format("Error loading class [%s]: %s", className, e), e);
}
}
}
Original comment by [email protected]
on 8 Jul 2014 at 9:35
from mockito.
Yeah I know this is possible, we do something similar for JUnit. However as it
involves the JDK it requires to change the build scripts, the dev environment,
the ci, etc.
These tasks may be more relevant if we create a pure jdk8 version.
Original comment by [email protected]
on 8 Jul 2014 at 10:29
from mockito.
Agreed.
Original comment by [email protected]
on 8 Jul 2014 at 10:35
from mockito.
It would be nice if Mockito would support this by default, but ... it is very
easy to add this yourself using a default answer. I have put an example here:
https://gist.github.com/diversit/ef6a1025ac9d1dc2a113
Original comment by [email protected]
on 2 Dec 2014 at 8:47
from mockito.
+1 for the feature
Do you mind opening a ticket in github?
https://github.com/mockito/mockito/issues
We can use reflection to avoid compiling against jdk8
Original comment by [email protected]
on 2 Dec 2014 at 9:28
from mockito.
If you reach this via Google: I created a GitHub issue since I couldn't find
one: https://github.com/mockito/mockito/issues/191
Original comment by [email protected]
on 2 Apr 2015 at 6:04
from mockito.
Related Issues (20)
- Mockito+Dexmaker is not working in Android test project HOT 1
- @InjectMocks and @Spy cannot be used together when object initialized by mockito HOT 10
- How to spy private method HOT 1
- timeout() should use long instead of int HOT 1
- Move internal class Whitebox to API HOT 1
- Get class of object, superclass if mocked object HOT 3
- Mocking interface method that accepts a varargs parameter does not return the mocked value as expected HOT 1
- Mockito fails to verify JavaFX objects HOT 4
- Add warning about stubbing the final methods in documentation HOT 2
- PowermockitoRunner failes with Java 7u65 and Java 8u11 HOT 3
- Mockito should provide a mechanism for classes to opt out of mocking: @Unmockable HOT 17
- Problem with mocking not overriden method which uses generics HOT 5
- Feature request/idea - "No more interactions" for a single method only HOT 4
- Argument Captor argument is not correct in the documentation. HOT 2
- Support "faking" abstract clases HOT 1
- Please push 1.10.x to maven central
- Multiple argument matchers within the same test method causing issue. HOT 2
- Mockito spy fail to handle abstraction correctly HOT 1
- Addind an InvocationListener to a mock, after it has been created. More specific, make a mock verbose. HOT 3
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.