使用PowerMock进行文件操作的JUnit测试

时间:2018-07-02 19:34:14

标签: junit mockito powermock

public class FileUtil {

    public void methodOne(Bean bean) {
        StringBuffer profileControlValue = new StringBuffer();
        profileControlValue.append(bean.getName()).append(bean.getDesc());

        String sourcePath = "path to save";

        try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(sourcePath.toString())))) {

            writer.write(profileControlValue.toString());
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

我想使用Mockito / PowerMockito编写上述方法的Junit测试用例。 基本上,我有一个接受Bean并处理值并将其写入文件的方法。

0 个答案:

没有答案