Polish gh-4048

This commit is contained in:
Rob Winch
2016-08-30 09:42:28 -05:00
parent 422bc37115
commit 53352e336d
2 changed files with 45 additions and 5 deletions

View File

@@ -16,8 +16,11 @@
package org.springframework.security.core.userdetails.jdbc;
import java.util.Locale;
import org.junit.Test;
import org.springframework.context.MessageSource;
import org.springframework.security.PopulatedDatabase;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
@@ -25,6 +28,10 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
/**
* Tests {@link JdbcDaoImpl}.
@@ -69,7 +76,8 @@ public class JdbcDaoImplTests {
}
@Test
public void testCheckDaoOnlyReturnsGrantedAuthoritiesGrantedToUser() throws Exception {
public void testCheckDaoOnlyReturnsGrantedAuthoritiesGrantedToUser()
throws Exception {
JdbcDaoImpl dao = makePopulatedJdbcDao();
UserDetails user = dao.loadUserByUsername("scott");
assertThat(user.getAuthorities()).hasSize(1);
@@ -187,4 +195,23 @@ public class JdbcDaoImplTests {
}
}
@Test(expected = IllegalArgumentException.class)
public void setMessageSourceWhenNullThenThrowsException() throws Exception {
JdbcDaoImpl dao = new JdbcDaoImpl();
dao.setMessageSource(null);
}
@Test
public void setMessageSourceWhenNotNullThenCanGet() throws Exception {
MessageSource source = mock(MessageSource.class);
JdbcDaoImpl dao = new JdbcDaoImpl();
dao.setMessageSource(source);
String code = "code";
dao.getMessages().getMessage(code);
verify(source).getMessage(eq(code), any(Object[].class), any(Locale.class));
}
}