2017-07-07 64 views
0

我一直在收到以下错误: org.powermock.reflect.exceptions.MethodNotFoundException:在java类的层次结构中找不到与名称getParent匹配的方法。 lang.Object。使用PowerMockito模拟Path.getParent()

我不知道为什么。我试图创建一些简单的代码来缩小错误,不明白为什么这个模拟不起作用。

的代码进行测试:

public void forTest(File xmlFile){ 
    Path p = Paths.get(xmlFile.getAbsolutePath()); 
    p.getParent(); 
} 

测试代码:

@RunWith(PowerMockRunner.class) 
@PrepareForTest({XmlFileFunctions.class,Paths.class}) 
public class XmlFileFunctionsTest { 
    @InjectMocks 
    XmlFileFunctions xmlFileFunctionsMock; 

    @Mock 
    File xmlFileMock; 
    @Mock 
    Path pMock; 


    @Test 
    public void myTest(){ 
     when(xmlFileMock.getAbsolutePath()).thenReturn("abc"); 
     PowerMockito.mockStatic(Paths.class); 
     when(Paths.get(Matchers.anyString())).thenReturn(pMock); 

     xmlFileFunctionsMock.forTest(xmlFileMock); 
     verify(pMock).getParent(); 
    } 

} 

回答

相关问题