From 110d8100ffc29fe3544fa57a681d7f24e591b931 Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Tue, 24 Nov 2015 17:07:51 +0100 Subject: [PATCH] Improve UserTokenDao coverage --- .../org/sonar/db/user/UserTokenDaoTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) 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; @@ -63,6 +67,24 @@ public class UserTokenDaoTest { assertThat(userTokenFromDb.getLogin()).isEqualTo(userToken.getLogin()); } + @Test + public void select_by_token_hash() { + String tokenHash = "123456789"; + insertToken(newUserToken().setTokenHash(tokenHash)); + + Optional 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"); -- 2.39.5