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
PowerMock 1.7.4 should contain the ability of modifying a private static final field as stated by contributor on #673 but next issue is displayed:
org.powermock.reflect.exceptions.FieldNotFoundException: No instance field assignable from "org.apache.logging.log4j.Logger" could be found in the class hierarchy of Foo.
While running next test:
public class Foo {
private static final Logger LOG = LogManager.getLogger(Foo.class.getName());
}
public class FooTest {
@Rule
public MockitoRule mockitoRule = MockitoJUnit.rule();
@Mock
Logger logger;
@Test
public void test() {
Foo sut = new Foo();
Whitebox.setInternalState(sut, Logger.class, logger);
}
}
With the following environment:
OS: Windows 10 Enterprise x64
Java: Oracle jdk1.8.0_161 x64
Maven dependencies:
junit:junit:4.12
org.mockito:mockito-core:2.23.0
org.powermock:powermock-module-junit4:1.7.4
org.powermock:powermock-api-mockito2:1.7.4
The text was updated successfully, but these errors were encountered:
Notice that if you replace Whitebox.setInternalState(sut, Logger.class, logger); for Whitebox.setInternalState(Foo.class, "LOG", logger); this works as expected.
rea-al
changed the title
WitheBox.setInternalState on private static final field
org.powermock.reflect.Whitebox.setInternalState(Object, Class<?>, Object) not working with object reference
Aug 15, 2019
PowerMock 1.7.4 should contain the ability of modifying a private static final field as stated by contributor on #673 but next issue is displayed:
org.powermock.reflect.exceptions.FieldNotFoundException: No instance field assignable from "org.apache.logging.log4j.Logger" could be found in the class hierarchy of Foo.
While running next test:
With the following environment:
The text was updated successfully, but these errors were encountered: