/** * Call the default constructor of the class under test. * This is useful to avoid low coverage due to private constructors in final * classes used to prevent instantiating them (eg those classes only have * static methods) * * @throws Throwable */ @Constraints(atMostOnce = true, notMutable = true) public static Object callDefaultConstructorOfTheClassUnderTest() throws Throwable{ Class<?> cut = Thread.currentThread().getContextClassLoader().loadClass(RuntimeSettings.className); return callDefaultConstructor(cut); }
@Test public void testPrivateConstructor() throws Throwable{ FooConstructor.counter = 0; PrivateAccess.callDefaultConstructor(FooConstructor.class); assertTrue(FooConstructor.counter > 0); }