aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-11-24 17:07:51 +0100
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-11-24 17:07:51 +0100
commit110d8100ffc29fe3544fa57a681d7f24e591b931 (patch)
tree022e24462a958f40e1ad39000b314b34be591751 /sonar-db
parent5634bf689509aed3c48877469d4549ab7b5141a4 (diff)
downloadsonarqube-110d8100ffc29fe3544fa57a681d7f24e591b931.tar.gz
sonarqube-110d8100ffc29fe3544fa57a681d7f24e591b931.zip
Improve UserTokenDao coverage
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/src/test/java/org/sonar/db/user/UserTokenDaoTest.java22
1 files changed, 22 insertions, 0 deletions
diff --git a/sonar-db/src/test/java/org/sonar/db/user/UserTokenDaoTest.java b/sonar-db/src/test/java/org/sonar/db/user/UserTokenDaoTest.java
index 55ea930b442..be50fa659fa 100644
--- a/sonar-db/src/test/java/org/sonar/db/user/UserTokenDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/user/UserTokenDaoTest.java
@@ -26,9 +26,11 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
+import org.junit.rules.ExpectedException;
import org.sonar.api.utils.System2;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
+import org.sonar.db.RowNotFoundException;
import org.sonar.test.DbTests;
import static org.assertj.core.api.Assertions.assertThat;
@@ -38,6 +40,8 @@ import static org.sonar.db.user.UserTokenTesting.newUserToken;
public class UserTokenDaoTest {
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
DbSession dbSession;
@@ -64,6 +68,24 @@ public class UserTokenDaoTest {
}
@Test
+ public void select_by_token_hash() {
+ String tokenHash = "123456789";
+ insertToken(newUserToken().setTokenHash(tokenHash));
+
+ Optional<UserTokenDto> result = underTest.selectByTokenHash(dbSession, tokenHash);
+
+ Assertions.assertThat(result).isPresent();
+ }
+
+ @Test
+ public void fail_if_token_is_not_found() {
+ expectedException.expect(RowNotFoundException.class);
+ expectedException.expectMessage("User token with token hash 'unknown-token-hash' not found");
+
+ underTest.selectOrFailByTokenHash(dbSession, "unknown-token-hash");
+ }
+
+ @Test
public void select_by_login_and_name() {
UserTokenDto userToken = newUserToken().setLogin("login").setName("name").setTokenHash("token");
insertToken(userToken);