You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have created following class with constructor, which I like to unit test by mocking some of
public class SampleClass {
.........................
........................
public SampleClass(String strBaseUrl, String strProjKey, String strEnv, String strAuthToken) {
................................
...................
**this.defaultClient = Configuration.getDefaultApiClient();**
,,,,,,,,,,,,,,,,,,,,,,,,
.......................
this.featureFlagsApiInstance = new FeatureFlagsApi(defaultClient);
this.userApiInstance = new UsersApi(defaultClient);
}
}
When I call this constructor in test class using PowerMock getting exception InvocationTargetException and get null instance.
TestClass:
@RunWith(PowerMockRunner.class)
@PrepareForTest(fullyQualifiedNames = "com.trmsys.tacoe.launchdarkly.utils.*")
@PowerMockIgnore("jdk.internal.reflect.*")
public class LDUtilTest2 {
@Test
public void testLdUtils() {
//add behaviour of LD client library
try{
FeatureFlagsApi featureFlagsApiInstance = mock(FeatureFlagsApi.class);
UsersApi userApiInstance = mock(UsersApi.class);
**LDHelper ldHelper = new LDHelper("string", "string", "string", "string");**
....................................
...................................
}
catch(Exception e) {
e.printStackTrace();
Assert.fail();
}
}
Observations: From SampleClass statement "this.defaultClient = Configuration.getDefaultApiClient();" which is static method, throw this exception which cause this test failure... I tried mocking this static method too by adding following statements in test class, but result is same
Hi,
I am trying to mock some classes from LaunchDarkly JAVA Client library.
I have created following class with constructor, which I like to unit test by mocking some of
When I call this constructor in test class using PowerMock getting exception InvocationTargetException and get null instance.
TestClass:
Observations: From SampleClass statement "this.defaultClient = Configuration.getDefaultApiClient();" which is static method, throw this exception which cause this test failure... I tried mocking this static method too by adding following statements in test class, but result is same
Java module and their versions being used:
Java: 11
junit: 4.12
mockito-all: 1.10.19
powermock-api-mockito: 1.7.0
powermock-module-junit4: 1.7.0
Best Regard
Hemant
The text was updated successfully, but these errors were encountered: