import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import org.apache.commons.io.IOUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.ServerComponent;
import org.sonar.api.issue.internal.DefaultIssue;
import org.sonar.api.issue.internal.FieldDiffs;
public class AnalysisReportService implements ServerComponent {
- private static final Logger LOG = LoggerFactory.getLogger(AnalysisReportService.class);
private final ComputeEngineIssueStorageFactory issueStorageFactory;
public AnalysisReportService(ComputeEngineIssueStorageFactory issueStorageFactory) {
} catch (IOException e) {
throw new IllegalStateException("Failed to read issues", e);
}
-
}
@VisibleForTesting
Date finishedAt = row.getDate(4);
Long id = row.getLong(5);
- updateColumn(update, 1, createdAt);
- updateColumn(update, 2, updatedAt);
+ update.setLong(1, createdAt == null ? now : Math.min(now, createdAt.getTime()));
+ update.setLong(2, updatedAt == null ? now : Math.min(now, updatedAt.getTime()));
update.setLong(3, startedAt == null ? null : startedAt.getTime());
update.setLong(4, finishedAt == null ? null : finishedAt.getTime());
update.setLong(5, id);
return true;
}
-
- private void updateColumn(SqlStatement update, int position, Date time) throws SQLException {
- if (time == null) {
- update.setLong(position, now);
- } else {
- update.setLong(position, Math.min(now, time.getTime()));
- }
- }
});
}
Date functionalCreatedAt = row.getDate(3);
Long id = row.getLong(4);
- updateColumn(update, 1, createdAt);
- updateColumn(update, 2, updatedAt);
+ update.setLong(1, createdAt == null ? now : Math.min(now, createdAt.getTime()));
+ update.setLong(2, updatedAt == null ? now : Math.min(now, updatedAt.getTime()));
update.setLong(3, functionalCreatedAt == null ? null : functionalCreatedAt.getTime());
update.setLong(4, id);
return true;
}
-
- private void updateColumn(SqlStatement update, int position, Date time) throws SQLException {
- update.setLong(position, time == null ? now : Math.min(now, time.getTime()));
- }
});
}
package org.sonar.api.utils;
import javax.annotation.Nullable;
+
import java.io.NotSerializableException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
}
public static String formatDateTimeNullSafe(@Nullable Date date) {
- if (date == null) {
- return "";
- }
-
- return THREAD_SAFE_DATETIME_FORMAT.format(date);
+ return date == null ? "" : THREAD_SAFE_DATETIME_FORMAT.format(date);
}
public static Date timeToDate(@Nullable Long time) {
package org.sonar.api.utils;
import com.google.common.collect.Lists;
+import org.assertj.core.api.Assertions;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import java.util.Date;
import java.util.List;
+import static org.hamcrest.Matchers.*;
import static org.hamcrest.core.Is.is;
-import static org.hamcrest.Matchers.greaterThan;
-import static org.hamcrest.Matchers.greaterThanOrEqualTo;
-import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.*;
public class DateUtilsTest {
assertThat(DateUtils.formatDateTime(new Date()).length(), greaterThan(20));
}
+ @Test
+ public void format_date_time_null_safe() throws Exception {
+ Assertions.assertThat(DateUtils.formatDateTimeNullSafe(new Date())).startsWith("20");
+ Assertions.assertThat(DateUtils.formatDateTimeNullSafe(new Date()).length()).isGreaterThan(20);
+ Assertions.assertThat(DateUtils.formatDateTimeNullSafe(null)).isEmpty();
+ }
+
+ @Test
+ public void time_to_date() throws Exception {
+ Date date = new Date();
+ Assertions.assertThat(DateUtils.timeToDate(date.getTime())).isEqualTo(date);
+ Assertions.assertThat(DateUtils.timeToDate(null)).isNull();
+ }
+
/**
* Cordially copied from XStream unit test
* See http://koders.com/java/fid8A231D75F2C6E6909FB26BCA11C12D08AD05FB50.aspx?s=ThreadSafeDateFormatTest