I have code such as:
File file = File createTempFile(“xxx”, “txt”);
So, when i use PowerMock to mock this file object, such as:
@RunWith(PowerMockRunner.class)
@PrepareForTest({File.class,StringUtils.class})
…
PowerMockito.mockState(File.class);
PowerMockito.when(File.createTempFile(Mockito.any(), Mockito.any()).thenReturn(null);
PowerMockito.mockState(StringUtils.class.class);
PowerMockito.when(StringUtils.isEmpty().thenReturn(false);
When I run this code, this file nois null, but I use same code to mock the org.apache.commons.lang3.StringUtils#isEmpty is effectively
New contributor
Chenet Chen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.