我有一個類通過測試罰款,並運行,如果我在Jenkins以外的單獨的Java類中調用它。它的構造具有這樣的:插件中的Jenkins FileSystem是什麼?
this.fs = FileSystems.getDefault();
後來在執行中,我添加了一個全面的檢查看空指針異常後。
if (this.fs == null) {
throw new Exception("No FileSystem found");
}
所以,當這個插件在運行詹金斯,默認FileSystem
是null
並拋出異常。我原來的代碼使用Paths.get
,但我已經將它切換到this.fs.getPath(stringPath);
,所以我可以使用DI爲單元測試創建一個FileSystem
。
使用Paths.get
在重構之前工作正常,但我不確定如何使用該方法知道正確的FileSystem
,尤其是考慮到在此環境中似乎沒有設置默認值。
聽起來就像我會做一個虛擬插件,運行該行,看看會發生什麼,然後回來。 –