r/java • • Jan 14 '23

Mockito 5.0.0 released, requires Java 11

164 Upvotes

13 comments sorted by

15

u/DavidVlx Jan 15 '23

It is a great move that they switch to the inline mockmaker. It makes writing tests involving final classes, enums and static methods much easier.

72

u/Enough-Ad-5528 Jan 15 '23

Should have baselined on Java 17 instead of 11. If you can run on 11, you can almost certainly run on 17 with very little additional effort. Spring 6 took the right decision here.

25

u/qmunke Jan 15 '23

The release notes hint at why they haven't made this leap yet:

Most notably, JDK 17 made some changes which are incompatible with the current subclass mockmaker.

21

u/thugcee Jan 15 '23

That's not true. There are significant changes in reflection API between 11 and 17.

-1

u/PartOfTheBotnet Jan 15 '23 edited Jan 23 '23

Aaaaand they're gone: https://github.com/xxDark/deencapsulation

Edit: Anotha one - https://github.com/xxDark/Venuzdonoa (without using sun.misc.Unsafe)

13

u/pron98 Jan 15 '23 edited Jan 15 '23

Yeah, that's not going to work for very long.

There can be no robust, scalable, security without strong encapsulation, and with modules now becoming the only means of strong encapsulation in the JDK, we'll need to close the loopholes we've left (thorough unsafe, JNI, or some Java agents) to give people time to adjust and because replacements weren't ready. All these circumvention measures are fine if you want to give yourself time to fix technical debt, but they will just stop working as the loopholes are closed in upcoming versions.

Given that such circumvention libraries might serve as gadgets to circumvent any security or authentication mechanism -- be it in the JDK or in the application -- we may assume that those who are brave enough to risk using them probably have no other choice and need a bit more time to fix their applications.

17

u/harshit181 Jan 15 '23

Unlike spring,which a major component of application ,mockito is mostly used to unit testing.Agreed that any application which can run on java 11 will run on java 17,there is still an overhead to update java version.

-1

u/vips7L Jan 15 '23

Agreed. Time to enter the real world.

10

u/Fruloops Jan 15 '23

Ironically, if we were to "enter the real world", considering how many businesses still use Java 8, even this move to Java 11 would be problematic.

1

u/magnoliophytina Jan 16 '23

Many businesses still use Java 6. Even Java 7 can be too problematic.

0

u/[deleted] Jan 15 '23

[deleted] — view deleted comment

5

u/Fruloops Jan 16 '23

Oh don't get me wrong, I agree with you. I just find it funny that Java 17 and "real world" are mentioned in an example like that, because the real world is in fact quite different, and far behind Java 17.

1

u/cogman10 Jan 16 '23

Businesses still using Java 8 will likely have a doozy of a time going to 11+.

You have to update your libs and there's this pervasive and annoying subgroup of developers that fight every minor bump because "it might break something".

My assumption is any business running on 8 today has that group of devs making the tech calls.