diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2012-10-23 10:57:32 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2012-10-23 10:57:32 +0200 |
commit | c408b3c0bf41d1b897d58f394a9a7133f53bfd1e (patch) | |
tree | 1c4b0b8088b44926514ffc4e5c96a170d3003aa0 /sonar-core | |
parent | 3b116ee36d876b6daa14883dead9f26f82f73e7b (diff) | |
download | sonarqube-c408b3c0bf41d1b897d58f394a9a7133f53bfd1e.tar.gz sonarqube-c408b3c0bf41d1b897d58f394a9a7133f53bfd1e.zip |
SONAR-3887 add unit tests
Diffstat (limited to 'sonar-core')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/persistence/SemaphoreDao.java | 2 | ||||
-rw-r--r-- | sonar-core/src/test/java/org/sonar/core/persistence/SemaphoreDaoTest.java | 32 |
2 files changed, 33 insertions, 1 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/SemaphoreDao.java b/sonar-core/src/main/java/org/sonar/core/persistence/SemaphoreDao.java index 288881f9fac..4176925f504 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/SemaphoreDao.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/SemaphoreDao.java @@ -39,7 +39,7 @@ public class SemaphoreDao { public boolean acquire(String name, int maxDurationInSeconds) { Preconditions.checkArgument(!Strings.isNullOrEmpty(name), "Semaphore name must not be empty"); - Preconditions.checkArgument(maxDurationInSeconds > 0, "Semaphore max duration must be positive"); + Preconditions.checkArgument(maxDurationInSeconds > 0, "Semaphore max duration must be positive: " + maxDurationInSeconds); SqlSession session = mybatis.openSession(); try { 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 6abc912b896..5efd621aa30 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 @@ -20,7 +20,9 @@ package org.sonar.core.persistence; import org.apache.commons.lang.time.DateUtils; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import java.sql.Connection; import java.sql.PreparedStatement; @@ -35,6 +37,36 @@ import static org.fest.assertions.Assertions.assertThat; public class SemaphoreDaoTest extends AbstractDaoTestCase { + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void should_fail_to_acquire_if_blank_semaphore_name() { + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Semaphore name must not be empty"); + + SemaphoreDao dao = new SemaphoreDao(getMyBatis()); + dao.acquire(null, 5000); + } + + @Test + public void should_fail_to_acquire_if_negative_timeout() { + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Semaphore max duration must be positive: -5000"); + + SemaphoreDao dao = new SemaphoreDao(getMyBatis()); + dao.acquire("foo", -5000); + } + + @Test + public void should_fail_to_release_if_blank_semaphore_name() { + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("Semaphore name must not be empty"); + + SemaphoreDao dao = new SemaphoreDao(getMyBatis()); + dao.release(null); + } + @Test public void create_and_acquire_semaphore() throws Exception { SemaphoreDao dao = new SemaphoreDao(getMyBatis()); |