Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mock final class in java by using EasyMock?- Junit test

I have final class and with constructor for that...

I have problem to mock this class. I came to know that i cannot use EasyMock for final class. But in my project i should use easymock only. Is there a way to mock this class? Can you please anyone help me in this?

//A a = createMock(A.class);//IllegalException occuring while running this test case


For example :

final class A {

private int a;
  A(int a){
this.a = a;
}

}
like image 537
shree Avatar asked Feb 14 '23 01:02

shree


1 Answers

It's impossible to mock a final class with pure EasyMock. You'll have to add in something like PowerMock, which integrates well with EasyMock. Or you write a test that doesn't require mocking of a final class.

like image 167
Peter Niederwieser Avatar answered Mar 04 '23 00:03

Peter Niederwieser