生產代碼(例如)如何在輸入流中模擬zip?
class ClassToTest {
public SomeResult interpreteZipFile(InputStream is) {
ZippedInputStream zis = new ZippedInputStream(is);
//other code with something returned
}
}
不知怎的,我想測試我的課,而無需使用複雜的外部拉鍊資源(大家都不希望發生)。有沒有一些簡單的解決方案來做這樣的事情?
classTotest.interpreteZipFile(new MockToBeZippedFile(new ReaderInputStream(new StringReader("some content"))));
我想就「騙」類InputStream
是沒有進入內容的zip文件。
你的意思是 「模擬輸入流」? 「簡單」的ZipInputStream不夠好嗎? – Danielson
'ZipInputStream'正在從文件解壓縮/讀取。不要壓縮它。我在生產代碼中解壓縮流,所以我需要在測試中壓縮它。 –
足夠公平,'ZipOutputStream'然後 – Danielson