这是我的密码:
public String getDate() throws IOException {
StringBuilder fileURI = new StringBuilder(locationName);
fileURI.append(fileName);
S3ObjectInputStream ts = null;
ts = (S3ObjectInputStream) s3Services.getResourceStream(fileURI.toString());
String timeStamp;
String onlyDate = null;
LocalDate mydate;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(ts))) {
timeStamp = reader.readLine();
onlyDate = timeStamp.substring(0, 10);
LocalDate date = LocalDate.parse(onlyDate);
mydate= date.minusDays(1);
}
return mydate.toString();
}
我第一次在junit上工作。
我需要模拟S3服务并测试是否使用预期值调用了getresourcestream()。
我试图模拟s3objectinputstream,并确保调用了其上的正确方法。
@Test
public void testgetDate() throws IOException {
Mockito.mock(Service.class);
StringBuilder fileURI = new StringBuilder("test");
fileURI.append("testFile.txt");
Mockito.mock(S3ObjectInputStream .class);
S3ObjectInputStream ts = null;
Mockito.when(s3Services.getResourceStream(fileURI.toString())).thenReturn(ts);
service.getDate();
}
暂无答案!
目前还没有任何答案,快来回答吧!