Problem
Could not initialize class ...
- ...
javax.xml.transform.FactoryFinder
(in our case). - In the article, where we found the solution, it was the class
SessionFactory
.
Class Under Test
We wanted to write a test for a utils class with static members.
We got the error when trying to create a Mock of a class, which contained a new
statement as an initialization of a static field.
public class ClassUnderTest{
private static JavaType javaType = new JavaType();
// ...
}
Test Class
@RunWith(PowerMockRunner.class)
@PrepareForTest(ClassUnderTest.class)
public class TestForClassUnderTest {
@Test
public void testCase() {
PowerMockito.mockStatic(ClassUnderTest.class);