From 0362803787b669e66918d0b2e1b7a195f9e22eb6 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Mon, 3 Dec 2012 14:31:58 +0100 Subject: [PATCH] SONAR-3306 Add logs to unit test --- .../core/persistence/SemaphoreDaoTest.java | 54 +++++++++++-------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/SemaphoreDaoTest.java b/sonar-core/src/test/java/org/sonar/core/persistence/SemaphoreDaoTest.java index 3ae10efa307..4ca936bec4b 100644 --- a/sonar-core/src/test/java/org/sonar/core/persistence/SemaphoreDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/persistence/SemaphoreDaoTest.java @@ -24,6 +24,8 @@ import org.apache.ibatis.session.SqlSession; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.Date; import java.util.concurrent.CountDownLatch; @@ -34,6 +36,8 @@ import static org.fest.assertions.Assertions.assertThat; public class SemaphoreDaoTest extends AbstractDaoTestCase { + private static final Logger LOG = LoggerFactory.getLogger(SemaphoreDaoTest.class); + @Rule public ExpectedException thrown = ExpectedException.none(); @@ -74,9 +78,9 @@ public class SemaphoreDaoTest extends AbstractDaoTestCase { SemaphoreDto semaphore = selectSemaphore("foo"); assertThat(semaphore).isNotNull(); assertThat(semaphore.getName()).isEqualTo("foo"); - assertThat(isRecent(semaphore.getCreatedAt(), 10)).isTrue(); - assertThat(isRecent(semaphore.getUpdatedAt(), 10)).isTrue(); - assertThat(isRecent(semaphore.getLockedAt(), 10)).isTrue(); + assertThat(isRecent(semaphore.getCreatedAt())).isTrue(); + assertThat(isRecent(semaphore.getUpdatedAt())).isTrue(); + assertThat(isRecent(semaphore.getLockedAt())).isTrue(); dao.release("foo"); assertThat(selectSemaphore("foo")).isNull(); @@ -92,9 +96,9 @@ public class SemaphoreDaoTest extends AbstractDaoTestCase { SemaphoreDto semaphore = selectSemaphore("foo"); assertThat(semaphore).isNotNull(); assertThat(semaphore.getName()).isEqualTo("foo"); - assertThat(isRecent(semaphore.getCreatedAt(), 10)).isTrue(); - assertThat(isRecent(semaphore.getUpdatedAt(), 10)).isTrue(); - assertThat(isRecent(semaphore.getLockedAt(), 10)).isTrue(); + assertThat(isRecent(semaphore.getCreatedAt())).isTrue(); + assertThat(isRecent(semaphore.getUpdatedAt())).isTrue(); + assertThat(isRecent(semaphore.getLockedAt())).isTrue(); dao.release("foo"); assertThat(selectSemaphore("foo")).isNull(); @@ -110,9 +114,9 @@ public class SemaphoreDaoTest extends AbstractDaoTestCase { SemaphoreDto semaphore = selectSemaphore("foo"); assertThat(semaphore).isNotNull(); assertThat(semaphore.getName()).isEqualTo("foo"); - assertThat(isRecent(semaphore.getCreatedAt(), 10)).isTrue(); - assertThat(isRecent(semaphore.getUpdatedAt(), 10)).isTrue(); - assertThat(isRecent(semaphore.getLockedAt(), 10)).isTrue(); + assertThat(isRecent(semaphore.getCreatedAt())).isTrue(); + assertThat(isRecent(semaphore.getUpdatedAt())).isTrue(); + assertThat(isRecent(semaphore.getLockedAt())).isTrue(); dao.release("foo"); assertThat(selectSemaphore("foo")).isNull(); @@ -129,9 +133,9 @@ public class SemaphoreDaoTest extends AbstractDaoTestCase { SemaphoreDto semaphore = selectSemaphore("foo"); assertThat(semaphore).isNotNull(); assertThat(semaphore.getName()).isEqualTo("foo"); - assertThat(isRecent(semaphore.getCreatedAt(), 10)).isFalse(); - assertThat(isRecent(semaphore.getUpdatedAt(), 10)).isFalse(); - assertThat(isRecent(semaphore.getLockedAt(), 10)).isFalse(); + assertThat(isRecent(semaphore.getCreatedAt())).isFalse(); + assertThat(isRecent(semaphore.getUpdatedAt())).isFalse(); + assertThat(isRecent(semaphore.getLockedAt())).isFalse(); } @Test @@ -145,9 +149,9 @@ public class SemaphoreDaoTest extends AbstractDaoTestCase { SemaphoreDto semaphore = selectSemaphore("foo"); assertThat(semaphore).isNotNull(); assertThat(semaphore.getName()).isEqualTo("foo"); - assertThat(isRecent(semaphore.getCreatedAt(), 10)).isFalse(); - assertThat(isRecent(semaphore.getUpdatedAt(), 10)).isTrue(); - assertThat(isRecent(semaphore.getLockedAt(), 10)).isTrue(); + assertThat(isRecent(semaphore.getCreatedAt())).isFalse(); + assertThat(isRecent(semaphore.getUpdatedAt())).isTrue(); + assertThat(isRecent(semaphore.getLockedAt())).isTrue(); } @Test @@ -161,9 +165,9 @@ public class SemaphoreDaoTest extends AbstractDaoTestCase { SemaphoreDto semaphore = selectSemaphore("foo"); assertThat(semaphore).isNotNull(); assertThat(semaphore.getName()).isEqualTo("foo"); - assertThat(isRecent(semaphore.getCreatedAt(), 10)).isFalse(); - assertThat(isRecent(semaphore.getUpdatedAt(), 10)).isTrue(); - assertThat(isRecent(semaphore.getLockedAt(), 10)).isTrue(); + assertThat(isRecent(semaphore.getCreatedAt())).isFalse(); + assertThat(isRecent(semaphore.getUpdatedAt())).isTrue(); + assertThat(isRecent(semaphore.getLockedAt())).isTrue(); dao.release("foo"); assertThat(selectSemaphore("foo")).isNull(); @@ -180,9 +184,9 @@ public class SemaphoreDaoTest extends AbstractDaoTestCase { SemaphoreDto semaphore = selectSemaphore("foo"); assertThat(semaphore).isNotNull(); assertThat(semaphore.getName()).isEqualTo("foo"); - assertThat(isRecent(semaphore.getCreatedAt(), 10)).isFalse(); - assertThat(isRecent(semaphore.getUpdatedAt(), 10)).isFalse(); - assertThat(isRecent(semaphore.getLockedAt(), 10)).isFalse(); + assertThat(isRecent(semaphore.getCreatedAt())).isFalse(); + assertThat(isRecent(semaphore.getUpdatedAt())).isFalse(); + assertThat(isRecent(semaphore.getLockedAt())).isFalse(); } @Test @@ -229,9 +233,13 @@ public class SemaphoreDaoTest extends AbstractDaoTestCase { } } - private static boolean isRecent(Date date, int durationInMinutes) { + private static boolean isRecent(Date date) { + LOG.info("**** Date : "+ date); Date now = new Date(); - return date.before(now) && DateUtils.addSeconds(date, durationInMinutes*60).after(now); + LOG.info("**** Now : "+ now); + Date dateInTheFuture = DateUtils.addDays(date, 1); + LOG.info("**** DateInTheFuture : "+ dateInTheFuture); + return date.before(now) && dateInTheFuture.after(now); } private static class Runner extends Thread { -- 2.39.5