I have a "final" class, in which I need to test private methods, tried the following way for the failure case to get (Exception) but getting error
[junit] Caused by: IllegalArgumentException: Cannot subclass final class class
How to resolve this error, can anyone please suggest
//final class
public final Class Test {
//private constructor
private Test(Events event) {
//initialization
}
private JSONObject getReg() {
return new JSONObject;
}
private State Updation(String macAddr) {
try {
return update(getReg(), PATH, macAddr);
} catch (Exception e) {
throw new JSONException(e);
}
}
}
@PrepareForTest({Test.class})
@RunWith(PowerMockRunner.class)
public class TestClassTest {
@Test(expected = Exception.class)
public void UpdationInvalidTest() throws Exception {
JSONObject jsonObj = new JSONObject();
Test test = Whitebox.invokeConstructor(Test.class, event);
Test testSpy = PowerMockito.spy(test);
PowerMockito.doReturn(jsonObj).when(testSpy, "getReg");
Whitebox.invokeMethod(test, "Updation", "00:00:00:00:00:00");
}
}