diff --git a/saturn-console-api/src/test/java/com/vip/saturn/job/console/service/impl/AuthenticationServiceImplTest.java b/saturn-console-api/src/test/java/com/vip/saturn/job/console/service/impl/AuthenticationServiceImplTest.java index a61b73d44..394ffab9f 100644 --- a/saturn-console-api/src/test/java/com/vip/saturn/job/console/service/impl/AuthenticationServiceImplTest.java +++ b/saturn-console-api/src/test/java/com/vip/saturn/job/console/service/impl/AuthenticationServiceImplTest.java @@ -34,14 +34,30 @@ public void testAuthenticateSuccessfully() throws SaturnJobConsoleException { public void testAuthenticationFailWhenUserIsNotFound() throws SaturnJobConsoleException { authnService.setHashMethod("plaintext"); when(userRepository.select("john")).thenReturn(null); + boolean hasException = false; + try { + assertNull(authnService.authenticate("john", "password")); + } catch (SaturnJobConsoleException e) { + hasException = true; + assertEquals(SaturnJobConsoleException.ERROR_CODE_AUTHN_FAIL, e.getErrorCode()); + } + + assertTrue(hasException); - assertNull(authnService.authenticate("john", "password")); } @Test public void testAuthenticationFailWhenPasswordInputIsEmpty() throws SaturnJobConsoleException { authnService.setHashMethod("plaintext"); - assertNull(authnService.authenticate("john", "")); + boolean hasException = false; + try { + authnService.authenticate("john", ""); + } catch (SaturnJobConsoleException e) { + hasException = true; + assertEquals(SaturnJobConsoleException.ERROR_CODE_AUTHN_FAIL, e.getErrorCode()); + } + + assertTrue(hasException); } private User createUser(String username, String password) {