вторник, 12 апреля 2016 г.

tips_of_java


// 1. Date calculating
// old code:
Calendar calLoadDate = Calendar.getInstance();
calLoadDate.setTime(loadDate);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.HOUR_OF_DAY, calLoadDate.get(Calendar.HOUR_OF_DAY));
cal.set(Calendar.MINUTE, calLoadDate.get(Calendar.MINUTE));
cal.set(Calendar.SECOND, calLoadDate.get(Calendar.SECOND));
date = cal.getTime();
// new code:
date = new Date(date.getTime() + loadDate.getTime() - DateUtils.truncate(loadDate, Calendar.DATE).getTime());
// 2. Check if file exists on sftp
// old code:
/**
* Checks if is target files exists.
* @param client sftp client object
* @param trgDir the trg dir
* @param fileName the file name
* @return true, if is target files exists
* @throws Exception directory does not exists
*/
private boolean isTargetFilesExists(SftpClient client, String trgDir, String fileName) throws Exception {
boolean isExists = false;
try {
client.cd(trgDir);
SftpFile[] listing = client.ls();
for (SftpFile f : listing) {
if (f.isFile() && f.getFilename().equals(fileName)) {
isExists = true;
}
}
} catch (Exception e) {
throw new Exception(String.format(messages.getProperty("error.dir.not.exists.set.dir"), trgDir));
}
return isExists;
}
// new code:
/**
* Checks if is target files exists.
* @param client sftp client object
* @param trgDir the trg dir
* @param fileName the file name
* @return true, if is target files exists
* @throws Exception directory does not exists
*/
private boolean isTargetFilesExists(SftpClient client, String trgDir, String fileName) throws Exception {
try {
client.cd(trgDir);
return Stream.of(client.ls()).anyMatch(f -> f.getFilename().equals(fileName));
} catch (Exception e) {
throw new Exception(String.format(messages.getProperty("error.dir.not.exists.set.dir"), trgDir));
}
}
// 3. Move to AsserJ
- compableData.stream().forEach(value -> assertThat(recAsplClient).contains(value));
+ assertThat(recAsplClient).containsAll(compableData);
- assertEquals(String.format("Difference between Table %s and Data must be zero!", asplTable), actual, primitive);
+ assertThat(actual).as("Difference between Table %s and Data must be zero!", asplTable).isEqualTo(0);
+ assertTrue(CollectionUtils.isEqualCollection(recAsplClient, recAsplClientShoudBe));
// 4. Boolean -> boolean - you never got npe!

Комментариев нет:

Отправить комментарий