1

FileInputStream のコンストラクターをモックしようとしていますが、次のコードがあります。

@RunWith(PowerMockRunner.class)
@PrepareForTest(FileInputStream.class)
public class DBUtilsTest {

    @Test(expected = FileNotFoundException.class)
    public void readTableMetadataFileNotFoundException() throws Exception {
        try {
            PowerMockito.whenNew(FileInputStream.class)
                    .withParameterTypes(String.class)
                    .withArguments(Matchers.any(String.class))
                    .thenThrow(FileNotFoundException.class);

            PowerMock.replayAll();

            TableMetadata tableMeta = DBUtils
                    .readTableMetadata(path);
        } finally {
            PowerMock.verifyAll();
        }
    }
}
public class DBUtils {
    public static TableMetadata readTableMetadata(String metadataPath)
            throws FileNotFoundException, IOException {

        Properties properties = new Properties();
        FileInputStream is = new FileInputStream(metadataPath); 
        properties.load(is);
        .....
    }
}

ただし、テストは失敗しますjava.lang.AssertionError: Expected exception: java.io.FileNotFoundException

コンストラクターは実際にはモックされておらず、例外はスローされていないようです。誰でもこの問題について何か助けてもらえますか?

4

1 に答える 1