public List<String> getPmFileParentPaths(String rootDir, String[] neTypes) { List<String> pmFileParentPaths = new ArrayList<>(); for (String neType : neTypes) { pmFileParentPaths.addAll(getLocalPmFileRootDirForMe(rootDir, neType)); } return pmFileParentPaths; } public static List<String> getLocalPmFileRootDirForMe(String localRootDir, String neType) { return FileCleanService.PHHOME.stream().map(pm -> getLocalPmFileRootDirForMe(localRootDir, pm, neType)).collect(toList()); } public static String getLocalPmFileRootDirForMe(String localRootDir, String pmHome, String neType) { return String.join(File.separator, localRootDir, pmHome, neType); } 写UT
时间: 2024-02-28 11:56:33 浏览: 140
Hbase工具类
针对这段代码,可以写出如下的UT:
```
@Test
public void testGetPmFileParentPaths() {
String rootDir = "/home/user/pmdata";
String[] neTypes = {"type1", "type2"};
List<String> expectedResult = new ArrayList<>();
expectedResult.add("/home/user/pmdata/pm1/type1");
expectedResult.add("/home/user/pmdata/pm2/type1");
expectedResult.add("/home/user/pmdata/pm1/type2");
expectedResult.add("/home/user/pmdata/pm2/type2");
List<String> result = getPmFileParentPaths(rootDir, neTypes);
assertEquals(expectedResult, result);
}
@Test
public void testGetLocalPmFileRootDirForMe() {
String localRootDir = "/home/user/pmdata";
String pmHome = "pm1";
String neType = "type1";
String expectedResult = "/home/user/pmdata/pm1/type1";
String result = getLocalPmFileRootDirForMe(localRootDir, pmHome, neType);
assertEquals(expectedResult, result);
}
```
这些UT覆盖了代码中的两个方法,分别测试了它们的输入和输出。可以通过运行这些UT来验证代码是否正确。
阅读全文