How to mock final class and final method

72 views
Skip to first unread message

barada sahoo

unread,
Sep 22, 2021, 3:06:07 AM9/22/21
to mockito
In my project I've one requirement where I need to mock final class. 

I am using the solutions from google, but it seems nothing works great for me. Can someone here suggest please? Thank you in advance.

Ullrich Hafner

unread,
Sep 22, 2021, 3:49:25 AM9/22/21
to moc...@googlegroups.com

Am 22.09.2021 um 08:57 schrieb barada sahoo <barad...@gmail.com>:

In my project I've one requirement where I need to mock final class. 

I am using the solutions from google, but it seems nothing works great for me.


What did you try so far?

Did you use mockito inline? See docs at:


Can someone here suggest please? Thank you in advance.

--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mockito/430ba140-6fe4-45f1-9fb2-79e4c050cd26n%40googlegroups.com.

barada sahoo

unread,
Sep 22, 2021, 3:58:55 AM9/22/21
to moc...@googlegroups.com
Yes I tried mockito inline extension. I got ExceptionInInitializationError. 

Ullrich Hafner

unread,
Sep 22, 2021, 4:01:37 AM9/22/21
to moc...@googlegroups.com
If you do not add more details we cannot help :-(

barada sahoo

unread,
Sep 22, 2021, 4:45:43 AM9/22/21
to moc...@googlegroups.com
Find the screenshot attachments. 



Capture.PNGCapture2.PNGCapture3.PNGCapture4.PNG



--
______________________
Thanks & Regards,

Barada Prasad Sahoo
Pune | India

Ullrich Hafner

unread,
Sep 22, 2021, 5:50:56 AM9/22/21
to moc...@googlegroups.com
You should not use PowerMock. Try Mockito Inline. And update your dependencies, you are using outdated versions:

<dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-inline</artifactId>
    <version>3.12.4</version>
    <scope>test</scope>
</dependency>

 

Am 22.09.2021 um 10:22 schrieb barada sahoo <barad...@gmail.com>:

Find the screenshot attachments. 



<Capture.PNG><Capture2.PNG><Capture3.PNG><Capture4.PNG>

barada sahoo

unread,
Sep 23, 2021, 2:30:07 AM9/23/21
to moc...@googlegroups.com
I removed powermock and used mockito- 3.12.4
Put mockito-extensions file in place. 

Find the attachments for ref. I'm still getting ExceptionInInitialierError.
Please help. Thanks.



 Capture.PNG
Capture2.PNGCapture3.PNG
You received this message because you are subscribed to a topic in the Google Groups "mockito" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mockito/LO4RkNN1PdU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mockito+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mockito/ADECB497-1C45-45DE-B9BD-1280BC9CE599%40gmail.com.
Reply all
Reply to author
Forward
0 new messages