1
0
mirror of synced 2026-08-04 09:17:02 +00:00

Remove redundant throws clauses

Removes exceptions that are declared in a method's signature but never thrown by the method itself or its implementations/derivatives.
This commit is contained in:
Lars Grefer
2019-08-23 01:03:54 +02:00
parent f0515a021c
commit 34dd5fea30
418 changed files with 1146 additions and 1273 deletions
@@ -37,7 +37,7 @@ public class TestDataSource extends DriverManagerDataSource implements Disposabl
setPassword("");
}
public void destroy() throws Exception {
public void destroy() {
System.out.println("Shutting down database: " + name);
new JdbcTemplate(this).execute("SHUTDOWN");
}
@@ -59,7 +59,7 @@ public class AuthorizationFailureEventTests {
}
@Test
public void gettersReturnCtorSuppliedData() throws Exception {
public void gettersReturnCtorSuppliedData() {
AuthorizationFailureEvent event = new AuthorizationFailureEvent(new Object(),
attributes, foo, exception);
assertThat(event.getConfigAttributes()).isSameAs(attributes);
@@ -55,7 +55,7 @@ public class SecurityConfigTests {
}
@Test
public void testObjectEquals() throws Exception {
public void testObjectEquals() {
SecurityConfig security1 = new SecurityConfig("TEST");
SecurityConfig security2 = new SecurityConfig("TEST");
assertThat(security2).isEqualTo(security1);
@@ -34,7 +34,7 @@ public class Jsr250VoterTests {
// SEC-1443
@Test
public void supportsMultipleRolesCorrectly() throws Exception {
public void supportsMultipleRolesCorrectly() {
List<ConfigAttribute> attrs = new ArrayList<>();
Jsr250Voter voter = new Jsr250Voter();
@@ -161,7 +161,7 @@ public class SecuredAnnotationSecurityMetadataSourceTests {
// SEC-1491
@Test
public void customAnnotationAttributesAreFound() throws Exception {
public void customAnnotationAttributesAreFound() {
SecuredAnnotationSecurityMetadataSource mds = new SecuredAnnotationSecurityMetadataSource(
new CustomSecurityAnnotationMetadataExtractor());
Collection<ConfigAttribute> attrs = mds.findAttributes(
@@ -35,7 +35,7 @@ public class AbstractSecurityExpressionHandlerTests {
private AbstractSecurityExpressionHandler<Object> handler;
@Before
public void setUp() throws Exception {
public void setUp() {
handler = new AbstractSecurityExpressionHandler<Object>() {
@Override
protected SecurityExpressionOperations createSecurityExpressionRoot(
@@ -47,7 +47,7 @@ public class AbstractSecurityExpressionHandlerTests {
}
@Test
public void beanNamesAreCorrectlyResolved() throws Exception {
public void beanNamesAreCorrectlyResolved() {
handler.setApplicationContext(new AnnotationConfigApplicationContext(
TestConfiguration.class));
@@ -45,7 +45,7 @@ public class SecurityExpressionRootTests {
}
@Test
public void denyAllIsFalsePermitAllTrue() throws Exception {
public void denyAllIsFalsePermitAllTrue() {
assertThat(root.denyAll()).isFalse();
assertThat(root.denyAll).isFalse();
assertThat(root.permitAll()).isTrue();
@@ -53,7 +53,7 @@ public class SecurityExpressionRootTests {
}
@Test
public void rememberMeIsCorrectlyDetected() throws Exception {
public void rememberMeIsCorrectlyDetected() {
AuthenticationTrustResolver atr = mock(AuthenticationTrustResolver.class);
root.setTrustResolver(atr);
when(atr.isRememberMe(JOE)).thenReturn(true);
@@ -62,7 +62,7 @@ public class SecurityExpressionRootTests {
}
@Test
public void roleHierarchySupportIsCorrectlyUsedInEvaluatingRoles() throws Exception {
public void roleHierarchySupportIsCorrectlyUsedInEvaluatingRoles() {
root.setRoleHierarchy(authorities -> AuthorityUtils.createAuthorityList("ROLE_C"));
assertThat(root.hasRole("C")).isTrue();
@@ -75,27 +75,27 @@ public class SecurityExpressionRootTests {
}
@Test
public void hasRoleAddsDefaultPrefix() throws Exception {
public void hasRoleAddsDefaultPrefix() {
assertThat(root.hasRole("A")).isTrue();
assertThat(root.hasRole("NO")).isFalse();
}
@Test
public void hasRoleEmptyPrefixDoesNotAddsDefaultPrefix() throws Exception {
public void hasRoleEmptyPrefixDoesNotAddsDefaultPrefix() {
root.setDefaultRolePrefix("");
assertThat(root.hasRole("A")).isFalse();
assertThat(root.hasRole("ROLE_A")).isTrue();
}
@Test
public void hasRoleNullPrefixDoesNotAddsDefaultPrefix() throws Exception {
public void hasRoleNullPrefixDoesNotAddsDefaultPrefix() {
root.setDefaultRolePrefix(null);
assertThat(root.hasRole("A")).isFalse();
assertThat(root.hasRole("ROLE_A")).isTrue();
}
@Test
public void hasRoleDoesNotAddDefaultPrefixForAlreadyPrefixedRoles() throws Exception {
public void hasRoleDoesNotAddDefaultPrefixForAlreadyPrefixedRoles() {
SecurityExpressionRoot root = new SecurityExpressionRoot(JOE) {
};
@@ -104,34 +104,33 @@ public class SecurityExpressionRootTests {
}
@Test
public void hasAnyRoleAddsDefaultPrefix() throws Exception {
public void hasAnyRoleAddsDefaultPrefix() {
assertThat(root.hasAnyRole("NO", "A")).isTrue();
assertThat(root.hasAnyRole("NO", "NOT")).isFalse();
}
@Test
public void hasAnyRoleDoesNotAddDefaultPrefixForAlreadyPrefixedRoles()
throws Exception {
public void hasAnyRoleDoesNotAddDefaultPrefixForAlreadyPrefixedRoles() {
assertThat(root.hasAnyRole("ROLE_NO", "ROLE_A")).isTrue();
assertThat(root.hasAnyRole("ROLE_NO", "ROLE_NOT")).isFalse();
}
@Test
public void hasAnyRoleEmptyPrefixDoesNotAddsDefaultPrefix() throws Exception {
public void hasAnyRoleEmptyPrefixDoesNotAddsDefaultPrefix() {
root.setDefaultRolePrefix("");
assertThat(root.hasRole("A")).isFalse();
assertThat(root.hasRole("ROLE_A")).isTrue();
}
@Test
public void hasAnyRoleNullPrefixDoesNotAddsDefaultPrefix() throws Exception {
public void hasAnyRoleNullPrefixDoesNotAddsDefaultPrefix() {
root.setDefaultRolePrefix(null);
assertThat(root.hasAnyRole("A")).isFalse();
assertThat(root.hasAnyRole("ROLE_A")).isTrue();
}
@Test
public void hasAuthorityDoesNotAddDefaultPrefix() throws Exception {
public void hasAuthorityDoesNotAddDefaultPrefix() {
assertThat(root.hasAuthority("A")).isFalse();
assertThat(root.hasAnyAuthority("NO", "A")).isFalse();
assertThat(root.hasAnyAuthority("ROLE_A", "NOT")).isTrue();
@@ -44,7 +44,7 @@ public class ExpressionBasedPreInvocationAdviceTests {
private ExpressionBasedPreInvocationAdvice expressionBasedPreInvocationAdvice;
@Before
public void setUp() throws Exception {
public void setUp() {
expressionBasedPreInvocationAdvice = new ExpressionBasedPreInvocationAdvice();
}
@@ -51,7 +51,7 @@ public class MethodSecurityExpressionRootTests {
}
@Test
public void canCallMethodsOnVariables() throws Exception {
public void canCallMethodsOnVariables() {
ctx.setVariable("var", "somestring");
Expression e = parser.parseExpression("#var.length() == 10");
@@ -71,8 +71,7 @@ public class MethodSecurityExpressionRootTests {
}
@Test
public void hasPermissionOnDomainObjectReturnsFalseIfPermissionEvaluatorDoes()
throws Exception {
public void hasPermissionOnDomainObjectReturnsFalseIfPermissionEvaluatorDoes() {
final Object dummyDomainObject = new Object();
final PermissionEvaluator pe = mock(PermissionEvaluator.class);
ctx.setVariable("domainObject", dummyDomainObject);
@@ -84,8 +83,7 @@ public class MethodSecurityExpressionRootTests {
}
@Test
public void hasPermissionOnDomainObjectReturnsTrueIfPermissionEvaluatorDoes()
throws Exception {
public void hasPermissionOnDomainObjectReturnsTrueIfPermissionEvaluatorDoes() {
final Object dummyDomainObject = new Object();
final PermissionEvaluator pe = mock(PermissionEvaluator.class);
ctx.setVariable("domainObject", dummyDomainObject);
@@ -96,7 +94,7 @@ public class MethodSecurityExpressionRootTests {
}
@Test
public void hasPermissionOnDomainObjectWorksWithIntegerExpressions() throws Exception {
public void hasPermissionOnDomainObjectWorksWithIntegerExpressions() {
final Object dummyDomainObject = new Object();
ctx.setVariable("domainObject", dummyDomainObject);
final PermissionEvaluator pe = mock(PermissionEvaluator.class);
@@ -116,7 +114,7 @@ public class MethodSecurityExpressionRootTests {
}
@Test
public void hasPermissionWorksWithThisObject() throws Exception {
public void hasPermissionWorksWithThisObject() {
Object targetObject = new Object() {
public String getX() {
return "x";
@@ -84,8 +84,7 @@ public class PrePostAnnotationSecurityMetadataSourceTests {
}
@Test
public void classLevelPreAnnotationIsPickedUpWhenNoMethodLevelExists()
throws Exception {
public void classLevelPreAnnotationIsPickedUpWhenNoMethodLevelExists() {
ConfigAttribute[] attrs = mds.getAttributes(voidImpl1).toArray(
new ConfigAttribute[0]);
@@ -167,7 +166,7 @@ public class PrePostAnnotationSecurityMetadataSourceTests {
}
@Test
public void customAnnotationAtClassLevelIsDetected() throws Exception {
public void customAnnotationAtClassLevelIsDetected() {
ConfigAttribute[] attrs = mds.getAttributes(annotatedAtClassLevel).toArray(
new ConfigAttribute[0]);
@@ -175,7 +174,7 @@ public class PrePostAnnotationSecurityMetadataSourceTests {
}
@Test
public void customAnnotationAtInterfaceLevelIsDetected() throws Exception {
public void customAnnotationAtInterfaceLevelIsDetected() {
ConfigAttribute[] attrs = mds.getAttributes(annotatedAtInterfaceLevel).toArray(
new ConfigAttribute[0]);
@@ -183,7 +182,7 @@ public class PrePostAnnotationSecurityMetadataSourceTests {
}
@Test
public void customAnnotationAtMethodLevelIsDetected() throws Exception {
public void customAnnotationAtMethodLevelIsDetected() {
ConfigAttribute[] attrs = mds.getAttributes(annotatedAtMethodLevel).toArray(
new ConfigAttribute[0]);
@@ -31,7 +31,7 @@ public class RoleHierarchyUtilsTests {
private static final String EOL = System.lineSeparator();
@Test
public void roleHierarchyFromMapWhenMapValidThenConvertsCorrectly() throws Exception {
public void roleHierarchyFromMapWhenMapValidThenConvertsCorrectly() {
// @formatter:off
String expectedRoleHierarchy = "ROLE_A > ROLE_B" + EOL +
"ROLE_A > ROLE_C" + EOL +
@@ -50,17 +50,17 @@ public class RoleHierarchyUtilsTests {
}
@Test(expected = IllegalArgumentException.class)
public void roleHierarchyFromMapWhenMapNullThenThrowsIllegalArgumentException() throws Exception {
public void roleHierarchyFromMapWhenMapNullThenThrowsIllegalArgumentException() {
RoleHierarchyUtils.roleHierarchyFromMap(null);
}
@Test(expected = IllegalArgumentException.class)
public void roleHierarchyFromMapWhenMapEmptyThenThrowsIllegalArgumentException() throws Exception {
public void roleHierarchyFromMapWhenMapEmptyThenThrowsIllegalArgumentException() {
RoleHierarchyUtils.roleHierarchyFromMap(Collections.<String, List<String>>emptyMap());
}
@Test(expected = IllegalArgumentException.class)
public void roleHierarchyFromMapWhenRoleNullThenThrowsIllegalArgumentException() throws Exception {
public void roleHierarchyFromMapWhenRoleNullThenThrowsIllegalArgumentException() {
Map<String, List<String>> roleHierarchyMap = new HashMap<>();
roleHierarchyMap.put(null, asList("ROLE_B", "ROLE_C"));
@@ -68,7 +68,7 @@ public class RoleHierarchyUtilsTests {
}
@Test(expected = IllegalArgumentException.class)
public void roleHierarchyFromMapWhenRoleEmptyThenThrowsIllegalArgumentException() throws Exception {
public void roleHierarchyFromMapWhenRoleEmptyThenThrowsIllegalArgumentException() {
Map<String, List<String>> roleHierarchyMap = new HashMap<>();
roleHierarchyMap.put("", asList("ROLE_B", "ROLE_C"));
@@ -76,7 +76,7 @@ public class RoleHierarchyUtilsTests {
}
@Test(expected = IllegalArgumentException.class)
public void roleHierarchyFromMapWhenImpliedRolesNullThenThrowsIllegalArgumentException() throws Exception {
public void roleHierarchyFromMapWhenImpliedRolesNullThenThrowsIllegalArgumentException() {
Map<String, List<String>> roleHierarchyMap = new HashMap<>();
roleHierarchyMap.put("ROLE_A", null);
@@ -84,7 +84,7 @@ public class RoleHierarchyUtilsTests {
}
@Test(expected = IllegalArgumentException.class)
public void roleHierarchyFromMapWhenImpliedRolesEmptyThenThrowsIllegalArgumentException() throws Exception {
public void roleHierarchyFromMapWhenImpliedRolesEmptyThenThrowsIllegalArgumentException() {
Map<String, List<String>> roleHierarchyMap = new HashMap<>();
roleHierarchyMap.put("ROLE_A", Collections.<String>emptyList());
@@ -35,7 +35,7 @@ public class AbstractSecurityInterceptorTests {
// ========================================================================================================
@Test(expected = IllegalArgumentException.class)
public void detectsIfInvocationPassedIncompatibleSecureObject() throws Exception {
public void detectsIfInvocationPassedIncompatibleSecureObject() {
MockSecurityInterceptorWhichOnlySupportsStrings si = new MockSecurityInterceptorWhichOnlySupportsStrings();
si.setRunAsManager(mock(RunAsManager.class));
@@ -41,8 +41,7 @@ public class RunAsManagerImplTests {
}
@Test
public void testDoesNotReturnAdditionalAuthoritiesIfCalledWithoutARunAsSetting()
throws Exception {
public void testDoesNotReturnAdditionalAuthoritiesIfCalledWithoutARunAsSetting() {
UsernamePasswordAuthenticationToken inputToken = new UsernamePasswordAuthenticationToken(
"Test", "Password",
AuthorityUtils.createAuthorityList("ROLE_ONE", "ROLE_TWO"));
@@ -56,7 +55,7 @@ public class RunAsManagerImplTests {
}
@Test
public void testRespectsRolePrefix() throws Exception {
public void testRespectsRolePrefix() {
UsernamePasswordAuthenticationToken inputToken = new UsernamePasswordAuthenticationToken(
"Test", "Password", AuthorityUtils.createAuthorityList("ONE", "TWO"));
@@ -83,7 +82,7 @@ public class RunAsManagerImplTests {
}
@Test
public void testReturnsAdditionalGrantedAuthorities() throws Exception {
public void testReturnsAdditionalGrantedAuthorities() {
UsernamePasswordAuthenticationToken inputToken = new UsernamePasswordAuthenticationToken(
"Test", "Password",
AuthorityUtils.createAuthorityList("ROLE_ONE", "ROLE_TWO"));
@@ -133,7 +132,7 @@ public class RunAsManagerImplTests {
}
@Test
public void testSupports() throws Exception {
public void testSupports() {
RunAsManager runAs = new RunAsManagerImpl();
assertThat(runAs.supports(new SecurityConfig("RUN_AS_SOMETHING"))).isTrue();
assertThat(!runAs.supports(new SecurityConfig("ROLE_WHICH_IS_IGNORED"))).isTrue();
@@ -67,7 +67,7 @@ public class MethodSecurityInterceptorTests {
// ========================================================================================================
@Before
public final void setUp() throws Exception {
public final void setUp() {
SecurityContextHolder.clearContext();
token = new TestingAuthenticationToken("Test", "Password");
interceptor = new MethodSecurityInterceptor();
@@ -83,7 +83,7 @@ public class MethodSecurityInterceptorTests {
}
@After
public void tearDown() throws Exception {
public void tearDown() {
SecurityContextHolder.clearContext();
}
@@ -210,8 +210,7 @@ public class MethodSecurityInterceptorTests {
}
@Test(expected = AuthenticationException.class)
public void callIsntMadeWhenAuthenticationManagerRejectsAuthentication()
throws Exception {
public void callIsntMadeWhenAuthenticationManagerRejectsAuthentication() {
final TestingAuthenticationToken token = new TestingAuthenticationToken("Test",
"Password");
SecurityContextHolder.getContext().setAuthentication(token);
@@ -224,7 +223,7 @@ public class MethodSecurityInterceptorTests {
}
@Test
public void callSucceedsIfAccessDecisionManagerGrantsAccess() throws Exception {
public void callSucceedsIfAccessDecisionManagerGrantsAccess() {
token.setAuthenticated(true);
interceptor.setPublishAuthorizationSuccess(true);
SecurityContextHolder.getContext().setAuthentication(token);
@@ -238,7 +237,7 @@ public class MethodSecurityInterceptorTests {
}
@Test
public void callIsntMadeWhenAccessDecisionManagerRejectsAccess() throws Exception {
public void callIsntMadeWhenAccessDecisionManagerRejectsAccess() {
SecurityContextHolder.getContext().setAuthentication(token);
// Use mocked target to make sure invocation doesn't happen (not in expectations
// so test would fail)
@@ -263,7 +262,7 @@ public class MethodSecurityInterceptorTests {
}
@Test
public void runAsReplacementIsCorrectlySet() throws Exception {
public void runAsReplacementIsCorrectlySet() {
SecurityContext ctx = SecurityContextHolder.getContext();
ctx.setAuthentication(token);
token.setAuthenticated(true);
@@ -284,7 +283,7 @@ public class MethodSecurityInterceptorTests {
// SEC-1967
@Test
public void runAsReplacementCleansAfterException() throws Exception {
public void runAsReplacementCleansAfterException() {
createTarget(true);
when(realTarget.makeUpperCase(anyString())).thenThrow(new RuntimeException());
SecurityContext ctx = SecurityContextHolder.getContext();
@@ -311,7 +310,7 @@ public class MethodSecurityInterceptorTests {
}
@Test(expected = AuthenticationCredentialsNotFoundException.class)
public void emptySecurityContextIsRejected() throws Exception {
public void emptySecurityContextIsRejected() {
mdsReturnsUserRole();
advisedTarget.makeUpperCase("hello");
}
@@ -66,7 +66,7 @@ public class AspectJMethodSecurityInterceptorTests {
// ========================================================================================================
@Before
public final void setUp() throws Exception {
public final void setUp() {
MockitoAnnotations.initMocks(this);
SecurityContextHolder.clearContext();
token = new TestingAuthenticationToken("Test", "Password");
@@ -109,7 +109,7 @@ public class AspectJMethodSecurityInterceptorTests {
@SuppressWarnings("unchecked")
@Test
public void callbackIsNotInvokedWhenPermissionDenied() throws Exception {
public void callbackIsNotInvokedWhenPermissionDenied() {
doThrow(new AccessDeniedException("denied")).when(adm).decide(
any(), any(), any());
@@ -124,7 +124,7 @@ public class AspectJMethodSecurityInterceptorTests {
}
@Test
public void adapterHoldsCorrectData() throws Exception {
public void adapterHoldsCorrectData() {
TargetObject to = new TargetObject();
Method m = ClassUtils.getMethodIfAvailable(TargetObject.class, "countLength",
new Class[] { String.class });
@@ -139,7 +139,7 @@ public class AspectJMethodSecurityInterceptorTests {
}
@Test
public void afterInvocationManagerIsNotInvokedIfExceptionIsRaised() throws Throwable {
public void afterInvocationManagerIsNotInvokedIfExceptionIsRaised() {
token.setAuthenticated(true);
SecurityContextHolder.getContext().setAuthentication(token);
@@ -161,8 +161,7 @@ public class AspectJMethodSecurityInterceptorTests {
// SEC-1967
@Test
@SuppressWarnings("unchecked")
public void invokeWithAspectJCallbackRunAsReplacementCleansAfterException()
throws Exception {
public void invokeWithAspectJCallbackRunAsReplacementCleansAfterException() {
SecurityContext ctx = SecurityContextHolder.getContext();
ctx.setAuthentication(token);
token.setAuthenticated(true);
@@ -54,7 +54,7 @@ public class MapBasedMethodSecurityMetadataSourceTests {
}
@Test
public void methodsWithDifferentArgumentsAreMatchedCorrectly() throws Exception {
public void methodsWithDifferentArgumentsAreMatchedCorrectly() {
mds.addSecureMethod(MockService.class, someMethodInteger, ROLE_A);
mds.addSecureMethod(MockService.class, someMethodString, ROLE_B);
@@ -57,7 +57,7 @@ public class MethodInvocationPrivilegeEvaluatorTests {
// ========================================================================================================
@Before
public final void setUp() throws Exception {
public final void setUp() {
SecurityContextHolder.clearContext();
interceptor = new MethodSecurityInterceptor();
token = new TestingAuthenticationToken("Test", "Password", "ROLE_SOMETHING");
@@ -85,7 +85,7 @@ public class MethodInvocationPrivilegeEvaluatorTests {
}
@Test
public void allowsAccessUsingCreateFromClass() throws Exception {
public void allowsAccessUsingCreateFromClass() {
final MethodInvocation mi = MethodInvocationUtils.createFromClass(
new OtherTargetObject(), ITargetObject.class, "makeLowerCase",
new Class[] { String.class }, new Object[] { "Hello world" });
@@ -97,7 +97,7 @@ public class MethodInvocationPrivilegeEvaluatorTests {
}
@Test
public void declinesAccessUsingCreate() throws Exception {
public void declinesAccessUsingCreate() {
Object object = new TargetObject();
final MethodInvocation mi = MethodInvocationUtils.create(object, "makeLowerCase",
"foobar");
@@ -110,7 +110,7 @@ public class MethodInvocationPrivilegeEvaluatorTests {
}
@Test
public void declinesAccessUsingCreateFromClass() throws Exception {
public void declinesAccessUsingCreateFromClass() {
final MethodInvocation mi = MethodInvocationUtils.createFromClass(
new OtherTargetObject(), ITargetObject.class, "makeLowerCase",
new Class[] { String.class }, new Object[] { "helloWorld" });
@@ -54,7 +54,7 @@ public class MockMethodInvocation implements MethodInvocation {
return targetObject;
}
public Object proceed() throws Throwable {
public Object proceed() {
return null;
}
}
@@ -51,7 +51,7 @@ public class AbstractAccessDecisionManagerTests {
}
@Test
public void testDelegatesSupportsClassRequests() throws Exception {
public void testDelegatesSupportsClassRequests() {
List list = new Vector();
list.add(new DenyVoter());
list.add(new MockStringOnlyVoter());
@@ -63,7 +63,7 @@ public class AbstractAccessDecisionManagerTests {
}
@Test
public void testDelegatesSupportsRequests() throws Exception {
public void testDelegatesSupportsRequests() {
List list = new Vector();
DenyVoter voter = new DenyVoter();
DenyAgainVoter denyVoter = new DenyAgainVoter();
@@ -80,7 +80,7 @@ public class AbstractAccessDecisionManagerTests {
}
@Test
public void testProperlyStoresListOfVoters() throws Exception {
public void testProperlyStoresListOfVoters() {
List list = new Vector();
DenyVoter voter = new DenyVoter();
DenyAgainVoter denyVoter = new DenyAgainVoter();
@@ -91,7 +91,7 @@ public class AbstractAccessDecisionManagerTests {
}
@Test
public void testRejectsEmptyList() throws Exception {
public void testRejectsEmptyList() {
List list = new Vector();
try {
@@ -104,7 +104,7 @@ public class AbstractAccessDecisionManagerTests {
}
@Test
public void testRejectsNullVotersList() throws Exception {
public void testRejectsNullVotersList() {
try {
new MockDecisionManagerImpl(null);
fail("Should have thrown IllegalArgumentException");
@@ -121,7 +121,7 @@ public class AbstractAccessDecisionManagerTests {
}
@Test
public void testWillNotStartIfDecisionVotersNotSet() throws Exception {
public void testWillNotStartIfDecisionVotersNotSet() {
try {
new MockDecisionManagerImpl(null);
fail("Should have thrown IllegalArgumentException");
@@ -42,14 +42,13 @@ public class AbstractAclVoterTests {
};
@Test
public void supportsMethodInvocations() throws Exception {
public void supportsMethodInvocations() {
assertThat(voter.supports(MethodInvocation.class)).isTrue();
assertThat(voter.supports(String.class)).isFalse();
}
@Test
public void expectedDomainObjectArgumentIsReturnedFromMethodInvocation()
throws Exception {
public void expectedDomainObjectArgumentIsReturnedFromMethodInvocation() {
voter.setProcessDomainObjectClass(String.class);
MethodInvocation mi = MethodInvocationUtils.create(new TestClass(),
"methodTakingAString", "The Argument");
@@ -57,7 +56,7 @@ public class AbstractAclVoterTests {
}
@Test
public void correctArgumentIsSelectedFromMultipleArgs() throws Exception {
public void correctArgumentIsSelectedFromMultipleArgs() {
voter.setProcessDomainObjectClass(String.class);
MethodInvocation mi = MethodInvocationUtils.create(new TestClass(),
"methodTakingAListAndAString", new ArrayList<>(), "The Argument");
@@ -73,29 +73,28 @@ public class AffirmativeBasedTests {
}
@Test
public void oneDenyVoteOneAbstainVoteOneAffirmativeVoteGrantsAccess()
throws Exception {
public void oneDenyVoteOneAbstainVoteOneAffirmativeVoteGrantsAccess() {
mgr = new AffirmativeBased(Arrays.<AccessDecisionVoter<? extends Object>> asList(
deny, abstain, grant));
mgr.decide(user, new Object(), attrs);
}
@Test
public void oneAffirmativeVoteTwoAbstainVotesGrantsAccess() throws Exception {
public void oneAffirmativeVoteTwoAbstainVotesGrantsAccess() {
mgr = new AffirmativeBased(Arrays.<AccessDecisionVoter<? extends Object>> asList(
grant, abstain, abstain));
mgr.decide(user, new Object(), attrs);
}
@Test(expected = AccessDeniedException.class)
public void oneDenyVoteTwoAbstainVotesDeniesAccess() throws Exception {
public void oneDenyVoteTwoAbstainVotesDeniesAccess() {
mgr = new AffirmativeBased(Arrays.<AccessDecisionVoter<? extends Object>> asList(
deny, abstain, abstain));
mgr.decide(user, new Object(), attrs);
}
@Test(expected = AccessDeniedException.class)
public void onlyAbstainVotesDeniesAccessWithDefault() throws Exception {
public void onlyAbstainVotesDeniesAccessWithDefault() {
mgr = new AffirmativeBased(Arrays.<AccessDecisionVoter<? extends Object>> asList(
abstain, abstain, abstain));
assertThat(!mgr.isAllowIfAllAbstainDecisions()).isTrue(); // check default
@@ -104,8 +103,7 @@ public class AffirmativeBasedTests {
}
@Test
public void testThreeAbstainVotesGrantsAccessIfAllowIfAllAbstainDecisionsIsSet()
throws Exception {
public void testThreeAbstainVotesGrantsAccessIfAllowIfAllAbstainDecisionsIsSet() {
mgr = new AffirmativeBased(Arrays.<AccessDecisionVoter<? extends Object>> asList(
abstain, abstain, abstain));
mgr.setAllowIfAllAbstainDecisions(true);
@@ -35,8 +35,7 @@ import java.util.*;
public class ConsensusBasedTests {
@Test(expected = AccessDeniedException.class)
public void testOneAffirmativeVoteOneDenyVoteOneAbstainVoteDeniesAccessWithoutDefault()
throws Exception {
public void testOneAffirmativeVoteOneDenyVoteOneAbstainVoteDeniesAccessWithoutDefault() {
TestingAuthenticationToken auth = makeTestToken();
ConsensusBased mgr = makeDecisionManager();
mgr.setAllowIfEqualGrantedDeniedDecisions(false);
@@ -49,8 +48,7 @@ public class ConsensusBasedTests {
}
@Test
public void testOneAffirmativeVoteOneDenyVoteOneAbstainVoteGrantsAccessWithDefault()
throws Exception {
public void testOneAffirmativeVoteOneDenyVoteOneAbstainVoteGrantsAccessWithDefault() {
TestingAuthenticationToken auth = makeTestToken();
ConsensusBased mgr = makeDecisionManager();
@@ -64,7 +62,7 @@ public class ConsensusBasedTests {
}
@Test
public void testOneAffirmativeVoteTwoAbstainVotesGrantsAccess() throws Exception {
public void testOneAffirmativeVoteTwoAbstainVotesGrantsAccess() {
TestingAuthenticationToken auth = makeTestToken();
ConsensusBased mgr = makeDecisionManager();
@@ -73,7 +71,7 @@ public class ConsensusBasedTests {
}
@Test(expected = AccessDeniedException.class)
public void testOneDenyVoteTwoAbstainVotesDeniesAccess() throws Exception {
public void testOneDenyVoteTwoAbstainVotesDeniesAccess() {
TestingAuthenticationToken auth = makeTestToken();
ConsensusBased mgr = makeDecisionManager();
@@ -82,7 +80,7 @@ public class ConsensusBasedTests {
}
@Test(expected = AccessDeniedException.class)
public void testThreeAbstainVotesDeniesAccessWithDefault() throws Exception {
public void testThreeAbstainVotesDeniesAccessWithDefault() {
TestingAuthenticationToken auth = makeTestToken();
ConsensusBased mgr = makeDecisionManager();
@@ -92,7 +90,7 @@ public class ConsensusBasedTests {
}
@Test
public void testThreeAbstainVotesGrantsAccessWithoutDefault() throws Exception {
public void testThreeAbstainVotesGrantsAccessWithoutDefault() {
TestingAuthenticationToken auth = makeTestToken();
ConsensusBased mgr = makeDecisionManager();
mgr.setAllowIfAllAbstainDecisions(true);
@@ -102,7 +100,7 @@ public class ConsensusBasedTests {
}
@Test
public void testTwoAffirmativeVotesTwoAbstainVotesGrantsAccess() throws Exception {
public void testTwoAffirmativeVotesTwoAbstainVotesGrantsAccess() {
TestingAuthenticationToken auth = makeTestToken();
ConsensusBased mgr = makeDecisionManager();
@@ -73,8 +73,7 @@ public class UnanimousBasedTests {
}
@Test
public void testOneAffirmativeVoteOneDenyVoteOneAbstainVoteDeniesAccess()
throws Exception {
public void testOneAffirmativeVoteOneDenyVoteOneAbstainVoteDeniesAccess() {
TestingAuthenticationToken auth = makeTestToken();
UnanimousBased mgr = makeDecisionManager();
@@ -90,7 +89,7 @@ public class UnanimousBasedTests {
}
@Test
public void testOneAffirmativeVoteTwoAbstainVotesGrantsAccess() throws Exception {
public void testOneAffirmativeVoteTwoAbstainVotesGrantsAccess() {
TestingAuthenticationToken auth = makeTestToken();
UnanimousBased mgr = makeDecisionManager();
@@ -100,7 +99,7 @@ public class UnanimousBasedTests {
}
@Test
public void testOneDenyVoteTwoAbstainVotesDeniesAccess() throws Exception {
public void testOneDenyVoteTwoAbstainVotesDeniesAccess() {
TestingAuthenticationToken auth = makeTestToken();
UnanimousBased mgr = makeDecisionManager();
@@ -115,7 +114,7 @@ public class UnanimousBasedTests {
}
@Test
public void testRoleVoterPrefixObserved() throws Exception {
public void testRoleVoterPrefixObserved() {
TestingAuthenticationToken auth = makeTestTokenWithFooBarPrefix();
UnanimousBased mgr = makeDecisionManagerWithFooBarPrefix();
@@ -126,7 +125,7 @@ public class UnanimousBasedTests {
}
@Test
public void testThreeAbstainVotesDeniesAccessWithDefault() throws Exception {
public void testThreeAbstainVotesDeniesAccessWithDefault() {
TestingAuthenticationToken auth = makeTestToken();
UnanimousBased mgr = makeDecisionManager();
@@ -143,7 +142,7 @@ public class UnanimousBasedTests {
}
@Test
public void testThreeAbstainVotesGrantsAccessWithoutDefault() throws Exception {
public void testThreeAbstainVotesGrantsAccessWithoutDefault() {
TestingAuthenticationToken auth = makeTestToken();
UnanimousBased mgr = makeDecisionManager();
mgr.setAllowIfAllAbstainDecisions(true);
@@ -155,7 +154,7 @@ public class UnanimousBasedTests {
}
@Test
public void testTwoAffirmativeVotesTwoAbstainVotesGrantsAccess() throws Exception {
public void testTwoAffirmativeVotesTwoAbstainVotesGrantsAccess() {
TestingAuthenticationToken auth = makeTestToken();
UnanimousBased mgr = makeDecisionManager();
@@ -42,7 +42,7 @@ public class AbstractAuthenticationTokenTests {
// ========================================================================================================
@Before
public final void setUp() throws Exception {
public final void setUp() {
authorities = AuthorityUtils.createAuthorityList("ROLE_ONE", "ROLE_TWO");
}
@@ -58,7 +58,7 @@ public class AbstractAuthenticationTokenTests {
}
@Test
public void testGetters() throws Exception {
public void testGetters() {
MockAuthenticationImpl token = new MockAuthenticationImpl("Test", "Password",
authorities);
assertThat(token.getPrincipal()).isEqualTo("Test");
@@ -67,7 +67,7 @@ public class AbstractAuthenticationTokenTests {
}
@Test
public void testHashCode() throws Exception {
public void testHashCode() {
MockAuthenticationImpl token1 = new MockAuthenticationImpl("Test", "Password",
authorities);
MockAuthenticationImpl token2 = new MockAuthenticationImpl("Test", "Password",
@@ -83,7 +83,7 @@ public class AbstractAuthenticationTokenTests {
}
@Test
public void testObjectsEquals() throws Exception {
public void testObjectsEquals() {
MockAuthenticationImpl token1 = new MockAuthenticationImpl("Test", "Password",
authorities);
MockAuthenticationImpl token2 = new MockAuthenticationImpl("Test", "Password",
@@ -115,7 +115,7 @@ public class AbstractAuthenticationTokenTests {
}
@Test
public void testSetAuthenticated() throws Exception {
public void testSetAuthenticated() {
MockAuthenticationImpl token = new MockAuthenticationImpl("Test", "Password",
authorities);
assertThat(!token.isAuthenticated()).isTrue();
@@ -40,7 +40,7 @@ public class DefaultAuthenticationEventPublisherTests {
DefaultAuthenticationEventPublisher publisher;
@Test
public void expectedDefaultMappingsAreSatisfied() throws Exception {
public void expectedDefaultMappingsAreSatisfied() {
publisher = new DefaultAuthenticationEventPublisher();
ApplicationEventPublisher appPublisher = mock(ApplicationEventPublisher.class);
publisher.setApplicationEventPublisher(appPublisher);
@@ -123,7 +123,7 @@ public class DefaultAuthenticationEventPublisherTests {
}
@Test
public void unknownFailureExceptionIsIgnored() throws Exception {
public void unknownFailureExceptionIsIgnored() {
publisher = new DefaultAuthenticationEventPublisher();
Properties p = new Properties();
p.put(MockAuthenticationException.class.getName(),
@@ -69,8 +69,7 @@ public class ProviderManagerTests {
}
@Test
public void authenticationSucceedsWithSupportedTokenAndReturnsExpectedObject()
throws Exception {
public void authenticationSucceedsWithSupportedTokenAndReturnsExpectedObject() {
final Authentication a = mock(Authentication.class);
ProviderManager mgr = new ProviderManager(
Arrays.asList(createProviderWhichReturns(a)));
@@ -96,13 +95,12 @@ public class ProviderManagerTests {
}
@Test(expected = IllegalArgumentException.class)
public void testStartupFailsIfProvidersNotSet() throws Exception {
public void testStartupFailsIfProvidersNotSet() {
new ProviderManager(null);
}
@Test
public void detailsAreNotSetOnAuthenticationTokenIfAlreadySetByProvider()
throws Exception {
public void detailsAreNotSetOnAuthenticationTokenIfAlreadySetByProvider() {
Object requestDetails = "(Request Details)";
final Object resultDetails = "(Result Details)";
@@ -143,8 +141,7 @@ public class ProviderManagerTests {
}
@Test
public void authenticationExceptionIsIgnoredIfLaterProviderAuthenticates()
throws Exception {
public void authenticationExceptionIsIgnoredIfLaterProviderAuthenticates() {
final Authentication authReq = mock(Authentication.class);
ProviderManager mgr = new ProviderManager(
Arrays.asList(createProviderWhichThrows(new BadCredentialsException("",
@@ -153,8 +150,7 @@ public class ProviderManagerTests {
}
@Test
public void authenticationExceptionIsRethrownIfNoLaterProviderAuthenticates()
throws Exception {
public void authenticationExceptionIsRethrownIfNoLaterProviderAuthenticates() {
ProviderManager mgr = new ProviderManager(Arrays.asList(
createProviderWhichThrows(new BadCredentialsException("")),
@@ -169,8 +165,7 @@ public class ProviderManagerTests {
// SEC-546
@Test
public void accountStatusExceptionPreventsCallsToSubsequentProviders()
throws Exception {
public void accountStatusExceptionPreventsCallsToSubsequentProviders() {
AuthenticationProvider iThrowAccountStatusException = createProviderWhichThrows(new AccountStatusException(
"") {
});
@@ -189,7 +184,7 @@ public class ProviderManagerTests {
}
@Test
public void parentAuthenticationIsUsedIfProvidersDontAuthenticate() throws Exception {
public void parentAuthenticationIsUsedIfProvidersDontAuthenticate() {
AuthenticationManager parent = mock(AuthenticationManager.class);
Authentication authReq = mock(Authentication.class);
when(parent.authenticate(authReq)).thenReturn(authReq);
@@ -199,7 +194,7 @@ public class ProviderManagerTests {
}
@Test
public void parentIsNotCalledIfAccountStatusExceptionIsThrown() throws Exception {
public void parentIsNotCalledIfAccountStatusExceptionIsThrown() {
AuthenticationProvider iThrowAccountStatusException = createProviderWhichThrows(new AccountStatusException(
"", new Throwable()) {
});
@@ -216,7 +211,7 @@ public class ProviderManagerTests {
}
@Test
public void providerNotFoundFromParentIsIgnored() throws Exception {
public void providerNotFoundFromParentIsIgnored() {
final Authentication authReq = mock(Authentication.class);
AuthenticationEventPublisher publisher = mock(AuthenticationEventPublisher.class);
AuthenticationManager parent = mock(AuthenticationManager.class);
@@ -239,7 +234,7 @@ public class ProviderManagerTests {
}
@Test
public void authenticationExceptionFromParentOverridesPreviousOnes() throws Exception {
public void authenticationExceptionFromParentOverridesPreviousOnes() {
AuthenticationManager parent = mock(AuthenticationManager.class);
ProviderManager mgr = new ProviderManager(
Arrays.asList(createProviderWhichThrows(new BadCredentialsException(""))),
@@ -263,7 +258,7 @@ public class ProviderManagerTests {
@Test
@SuppressWarnings("deprecation")
public void statusExceptionIsPublished() throws Exception {
public void statusExceptionIsPublished() {
AuthenticationManager parent = mock(AuthenticationManager.class);
final LockedException expected = new LockedException("");
ProviderManager mgr = new ProviderManager(
@@ -347,7 +342,7 @@ public class ProviderManagerTests {
new ArrayList<>(0));
}
private ProviderManager makeProviderManager() throws Exception {
private ProviderManager makeProviderManager() {
MockProvider provider1 = new MockProvider();
List<AuthenticationProvider> providers = new ArrayList<>();
providers.add(provider1);
@@ -37,7 +37,7 @@ public class AnonymousAuthenticationProviderTests {
// ========================================================================================================
@Test
public void testDetectsAnInvalidKey() throws Exception {
public void testDetectsAnInvalidKey() {
AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider(
"qwerty");
@@ -54,7 +54,7 @@ public class AnonymousAuthenticationProviderTests {
}
@Test
public void testDetectsMissingKey() throws Exception {
public void testDetectsMissingKey() {
try {
new AnonymousAuthenticationProvider(null);
fail("Should have thrown IllegalArgumentException");
@@ -65,14 +65,14 @@ public class AnonymousAuthenticationProviderTests {
}
@Test
public void testGettersSetters() throws Exception {
public void testGettersSetters() {
AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider(
"qwerty");
assertThat(aap.getKey()).isEqualTo("qwerty");
}
@Test
public void testIgnoresClassesItDoesNotSupport() throws Exception {
public void testIgnoresClassesItDoesNotSupport() {
AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider(
"qwerty");
@@ -85,7 +85,7 @@ public class AnonymousAuthenticationProviderTests {
}
@Test
public void testNormalOperation() throws Exception {
public void testNormalOperation() {
AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider(
"qwerty");
@@ -149,17 +149,17 @@ public class AnonymousAuthenticationTokenTests {
}
@Test(expected = IllegalArgumentException.class)
public void constructorWhenNullAuthoritiesThenThrowIllegalArgumentException() throws Exception {
public void constructorWhenNullAuthoritiesThenThrowIllegalArgumentException() {
new AnonymousAuthenticationToken("key", "principal", null);
}
@Test(expected = IllegalArgumentException.class)
public void constructorWhenEmptyAuthoritiesThenThrowIllegalArgumentException() throws Exception {
public void constructorWhenEmptyAuthoritiesThenThrowIllegalArgumentException() {
new AnonymousAuthenticationToken("key", "principal", Collections.<GrantedAuthority>emptyList());
}
@Test(expected = IllegalArgumentException.class)
public void constructorWhenPrincipalIsEmptyStringThenThrowIllegalArgumentException() throws Exception {
public void constructorWhenPrincipalIsEmptyStringThenThrowIllegalArgumentException() {
new AnonymousAuthenticationToken("key", "", ROLES_12);
}
}
@@ -96,7 +96,7 @@ public class DefaultJaasAuthenticationProviderTests {
}
@Test
public void authenticateSuccess() throws Exception {
public void authenticateSuccess() {
Authentication auth = provider.authenticate(token);
assertThat(auth.getPrincipal()).isEqualTo(token.getPrincipal());
assertThat(auth.getCredentials()).isEqualTo(token.getCredentials());
@@ -194,7 +194,7 @@ public class DefaultJaasAuthenticationProviderTests {
}
@Test
public void logoutNullLoginContext() throws Exception {
public void logoutNullLoginContext() {
SessionDestroyedEvent event = mock(SessionDestroyedEvent.class);
SecurityContext securityContext = mock(SecurityContext.class);
JaasAuthenticationToken token = mock(JaasAuthenticationToken.class);
@@ -62,7 +62,7 @@ public class JaasAuthenticationProviderTests {
// ========================================================================================================
@Before
public void setUp() throws Exception {
public void setUp() {
String resName = "/" + getClass().getName().replace('.', '/') + ".xml";
context = new ClassPathXmlApplicationContext(resName);
eventCheck = (JaasEventCheck) context.getBean("eventCheck");
@@ -190,7 +190,7 @@ public class JaasAuthenticationProviderTests {
}
@Test
public void testFull() throws Exception {
public void testFull() {
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
"user", "password", AuthorityUtils.createAuthorityList("ROLE_ONE"));
@@ -227,7 +227,7 @@ public class JaasAuthenticationProviderTests {
}
@Test
public void testGetApplicationEventPublisher() throws Exception {
public void testGetApplicationEventPublisher() {
assertThat(jaasProvider.getApplicationEventPublisher()).isNotNull();
}
@@ -294,7 +294,7 @@ public class JaasAuthenticationProviderTests {
super(loginModule);
}
public void logout() throws LoginException {
public void logout() {
this.loggedOut = true;
}
}
@@ -29,20 +29,18 @@ import org.springframework.security.authentication.jaas.JaasGrantedAuthority;
public class JaasGrantedAuthorityTests {
/**
* @throws Exception
*/
@Test
public void authorityWithNullRoleFailsAssertion() throws Exception {
public void authorityWithNullRoleFailsAssertion() {
assertThatThrownBy(() -> new JaasGrantedAuthority(null, null))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("role cannot be null");
}
/**
* @throws Exception
*/
@Test
public void authorityWithNullPrincipleFailsAssertion() throws Exception {
public void authorityWithNullPrincipleFailsAssertion() {
assertThatThrownBy(() -> new JaasGrantedAuthority("role", null))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("principal cannot be null");
@@ -52,14 +52,14 @@ public class SecurityContextLoginModuleTests {
// ========================================================================================================
@Before
public void setUp() throws Exception {
public void setUp() {
this.module = new SecurityContextLoginModule();
this.module.initialize(this.subject, null, null, null);
SecurityContextHolder.clearContext();
}
@After
public void tearDown() throws Exception {
public void tearDown() {
SecurityContextHolder.clearContext();
this.module = null;
}
@@ -75,7 +75,7 @@ public class SecurityContextLoginModuleTests {
}
@Test
public void testLoginException() throws Exception {
public void testLoginException() {
try {
this.module.login();
fail("LoginException expected, there is no Authentication in the SecurityContext");
@@ -112,7 +112,7 @@ public class SecurityContextLoginModuleTests {
}
@Test
public void testNullAuthenticationInSecurityContext() throws Exception {
public void testNullAuthenticationInSecurityContext() {
try {
SecurityContextHolder.getContext().setAuthentication(null);
this.module.login();
@@ -34,8 +34,7 @@ public class TestCallbackHandler implements JaasAuthenticationCallbackHandler {
// ~ Methods
// ========================================================================================================
public void handle(Callback callback, Authentication auth) throws IOException,
UnsupportedCallbackException {
public void handle(Callback callback, Authentication auth) {
if (callback instanceof TextInputCallback) {
TextInputCallback tic = (TextInputCallback) callback;
tic.setText(auth.getPrincipal().toString());
@@ -37,11 +37,11 @@ public class TestLoginModule implements LoginModule {
// ~ Methods
// ========================================================================================================
public boolean abort() throws LoginException {
public boolean abort() {
return true;
}
public boolean commit() throws LoginException {
public boolean commit() {
return true;
}
@@ -82,7 +82,7 @@ public class TestLoginModule implements LoginModule {
return true;
}
public boolean logout() throws LoginException {
public boolean logout() {
return true;
}
}
@@ -37,7 +37,7 @@ public class RememberMeAuthenticationProviderTests {
// ~ Methods
// ========================================================================================================
@Test
public void testDetectsAnInvalidKey() throws Exception {
public void testDetectsAnInvalidKey() {
RememberMeAuthenticationProvider aap = new RememberMeAuthenticationProvider(
"qwerty");
@@ -54,7 +54,7 @@ public class RememberMeAuthenticationProviderTests {
}
@Test
public void testDetectsMissingKey() throws Exception {
public void testDetectsMissingKey() {
try {
new RememberMeAuthenticationProvider(null);
fail("Should have thrown IllegalArgumentException");
@@ -73,7 +73,7 @@ public class RememberMeAuthenticationProviderTests {
}
@Test
public void testIgnoresClassesItDoesNotSupport() throws Exception {
public void testIgnoresClassesItDoesNotSupport() {
RememberMeAuthenticationProvider aap = new RememberMeAuthenticationProvider(
"qwerty");
@@ -86,7 +86,7 @@ public class RememberMeAuthenticationProviderTests {
}
@Test
public void testNormalOperation() throws Exception {
public void testNormalOperation() {
RememberMeAuthenticationProvider aap = new RememberMeAuthenticationProvider(
"qwerty");
@@ -94,7 +94,7 @@ public abstract class AbstractDelegatingSecurityContextExecutorServiceTests exte
}
@Test
public void submitCallable() throws Exception {
public void submitCallable() {
when(delegate.submit(wrappedCallable)).thenReturn(expectedFutureObject);
Future<Object> result = executor.submit(callable);
verify(delegate).submit(wrappedCallable);
@@ -102,7 +102,7 @@ public abstract class AbstractDelegatingSecurityContextExecutorServiceTests exte
}
@Test
public void submitRunnableWithResult() throws Exception {
public void submitRunnableWithResult() {
when(delegate.submit(wrappedRunnable, resultArg))
.thenReturn(expectedFutureObject);
Future<Object> result = executor.submit(runnable, resultArg);
@@ -112,7 +112,7 @@ public abstract class AbstractDelegatingSecurityContextExecutorServiceTests exte
@Test
@SuppressWarnings("unchecked")
public void submitRunnable() throws Exception {
public void submitRunnable() {
when((Future<Object>) delegate.submit(wrappedRunnable)).thenReturn(
expectedFutureObject);
Future<?> result = executor.submit(runnable);
@@ -168,4 +168,4 @@ public abstract class AbstractDelegatingSecurityContextExecutorServiceTests exte
}
protected abstract DelegatingSecurityContextExecutorService create();
}
}
@@ -56,7 +56,7 @@ public class DelegatingSecurityContextRunnableTests {
private SecurityContext originalSecurityContext;
@Before
public void setUp() throws Exception {
public void setUp() {
originalSecurityContext = SecurityContextHolder.createEmptyContext();
doAnswer((Answer<Object>) invocation -> {
assertThat(SecurityContextHolder.getContext()).isEqualTo(securityContext);
@@ -59,7 +59,7 @@ public class SpringSecurityCoreVersionTests {
}
@Test
public void springVersionIsUpToDate() throws Exception {
public void springVersionIsUpToDate() {
// Property is set by the build script
String springVersion = System.getProperty("springVersion");
@@ -67,7 +67,7 @@ public class SpringSecurityCoreVersionTests {
}
@Test
public void serialVersionMajorAndMinorVersionMatchBuildVersion() throws Exception {
public void serialVersionMajorAndMinorVersionMatchBuildVersion() {
String version = System.getProperty("springSecurityVersion");
// Strip patch version
@@ -156,7 +156,7 @@ public class SpringSecurityCoreVersionTests {
verifyZeroInteractions(logger);
}
private String getDisableChecksProperty() throws Exception {
private String getDisableChecksProperty() {
return SpringSecurityCoreVersion.class.getName().concat(".DISABLE_CHECKS");
}
@@ -30,7 +30,7 @@ import org.springframework.security.core.GrantedAuthority;
public class SimpleGrantedAuthorityTests {
@Test
public void equalsBehavesAsExpected() throws Exception {
public void equalsBehavesAsExpected() {
SimpleGrantedAuthority auth1 = new SimpleGrantedAuthority("TEST");
assertThat(auth1).isEqualTo(auth1);
assertThat(new SimpleGrantedAuthority("TEST")).isEqualTo(auth1);
@@ -81,7 +81,7 @@ public class SimpleAuthoritiesMapperTests {
}
@Test
public void defaultAuthorityIsAssignedIfSet() throws Exception {
public void defaultAuthorityIsAssignedIfSet() {
SimpleAuthorityMapper mapper = new SimpleAuthorityMapper();
mapper.setDefaultAuthority("ROLE_USER");
Set<String> mapped = AuthorityUtils.authorityListToSet(mapper
@@ -33,7 +33,7 @@ public class SecurityContextHolderTests {
// ~ Methods
// ========================================================================================================
@Before
public final void setUp() throws Exception {
public final void setUp() {
SecurityContextHolder
.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
}
@@ -89,7 +89,7 @@ public class AnnotationParameterNameDiscovererTests {
}
@Test
public void getParameterNamesClassAnnotationOnInterface() throws Exception {
public void getParameterNamesClassAnnotationOnInterface() {
assertThat(
discoverer.getParameterNames(ReflectionUtils.findMethod(DaoImpl.class,
"findMessageByTo", String.class))).isEqualTo(
@@ -101,7 +101,7 @@ public class AnnotationParameterNameDiscovererTests {
}
@Test
public void getParameterNamesClassAnnotationOnImpl() throws Exception {
public void getParameterNamesClassAnnotationOnImpl() {
assertThat(
discoverer.getParameterNames(ReflectionUtils.findMethod(Dao.class,
"findMessageByToAndFrom", String.class, String.class)))
@@ -113,7 +113,7 @@ public class AnnotationParameterNameDiscovererTests {
}
@Test
public void getParameterNamesClassAnnotationOnBaseClass() throws Exception {
public void getParameterNamesClassAnnotationOnBaseClass() {
assertThat(
discoverer.getParameterNames(ReflectionUtils.findMethod(Dao.class,
"findMessageByIdNoAnnotation", String.class))).isNull();
@@ -40,7 +40,7 @@ public class SessionRegistryImplTests {
// ========================================================================================================
@Before
public void setUp() throws Exception {
public void setUp() {
sessionRegistry = new SessionRegistryImpl();
}
@@ -70,7 +70,7 @@ public class SessionRegistryImplTests {
}
@Test
public void testMultiplePrincipals() throws Exception {
public void testMultiplePrincipals() {
Object principal1 = "principal_1";
Object principal2 = "principal_2";
String sessionId1 = "1234567890";
@@ -125,7 +125,7 @@ public class SessionRegistryImplTests {
}
@Test
public void testTwoSessionsOnePrincipalExpiring() throws Exception {
public void testTwoSessionsOnePrincipalExpiring() {
Object principal = "Some principal object";
String sessionId1 = "1234567890";
String sessionId2 = "9876543210";
@@ -151,7 +151,7 @@ public class SessionRegistryImplTests {
}
@Test
public void testTwoSessionsOnePrincipalHandling() throws Exception {
public void testTwoSessionsOnePrincipalHandling() {
Object principal = "Some principal object";
String sessionId1 = "1234567890";
String sessionId2 = "9876543210";
@@ -54,7 +54,7 @@ public class UserTests {
}
@Test
public void hashLookupOnlyDependsOnUsername() throws Exception {
public void hashLookupOnlyDependsOnUsername() {
User user1 = new User("rod", "koala", true, true, true, true, ROLE_12);
Set<UserDetails> users = new HashSet<>();
users.add(user1);
@@ -80,7 +80,7 @@ public class UserTests {
}
@Test
public void testNullValuesRejected() throws Exception {
public void testNullValuesRejected() {
try {
new User(null, "koala", true, true, true, true, ROLE_12);
fail("Should have thrown IllegalArgumentException");
@@ -106,7 +106,7 @@ public class UserTests {
}
@Test
public void testNullWithinGrantedAuthorityElementIsRejected() throws Exception {
public void testNullWithinGrantedAuthorityElementIsRejected() {
try {
List<GrantedAuthority> auths = AuthorityUtils.createAuthorityList("ROLE_ONE");
auths.add(null);
@@ -119,7 +119,7 @@ public class UserTests {
}
@Test
public void testUserGettersSetter() throws Exception {
public void testUserGettersSetter() {
UserDetails user = new User("rod", "koala", true, true, true, true,
AuthorityUtils.createAuthorityList("ROLE_TWO", "ROLE_ONE"));
assertThat(user.getUsername()).isEqualTo("rod");
@@ -133,7 +133,7 @@ public class UserTests {
}
@Test
public void enabledFlagIsFalseForDisabledAccount() throws Exception {
public void enabledFlagIsFalseForDisabledAccount() {
UserDetails user = new User("rod", "koala", false, true, true, true, ROLE_12);
assertThat(user.isEnabled()).isFalse();
}
@@ -149,7 +149,7 @@ public class UserTests {
}
@Test
public void withUserDetailsWhenAllEnabled() throws Exception {
public void withUserDetailsWhenAllEnabled() {
User expected = new User("rob", "pass", true, true, true, true, ROLE_12);
UserDetails actual = User.withUserDetails(expected).build();
@@ -165,7 +165,7 @@ public class UserTests {
@Test
public void withUserDetailsWhenAllDisabled() throws Exception {
public void withUserDetailsWhenAllDisabled() {
User expected = new User("rob", "pass", false, false, false, false, ROLE_12);
UserDetails actual = User.withUserDetails(expected).build();
@@ -38,7 +38,7 @@ public class NullUserCacheTests {
}
@Test
public void testCacheOperation() throws Exception {
public void testCacheOperation() {
NullUserCache cache = new NullUserCache();
cache.putUserInCache(getUser());
assertThat(cache.getUserFromCache(null)).isNull();
@@ -42,7 +42,7 @@ public class JdbcDaoImplTests {
// ~ Methods
// ========================================================================================================
private JdbcDaoImpl makePopulatedJdbcDao() throws Exception {
private JdbcDaoImpl makePopulatedJdbcDao() {
JdbcDaoImpl dao = new JdbcDaoImpl();
dao.setDataSource(PopulatedDatabase.getDataSource());
dao.afterPropertiesSet();
@@ -50,7 +50,7 @@ public class JdbcDaoImplTests {
return dao;
}
private JdbcDaoImpl makePopulatedJdbcDaoWithRolePrefix() throws Exception {
private JdbcDaoImpl makePopulatedJdbcDaoWithRolePrefix() {
JdbcDaoImpl dao = new JdbcDaoImpl();
dao.setDataSource(PopulatedDatabase.getDataSource());
dao.setRolePrefix("ARBITRARY_PREFIX_");
@@ -168,7 +168,7 @@ public class JdbcDaoImplTests {
}
@Test
public void testStartupFailsIfDataSourceNotSet() throws Exception {
public void testStartupFailsIfDataSourceNotSet() {
JdbcDaoImpl dao = new JdbcDaoImpl();
try {
@@ -181,7 +181,7 @@ public class JdbcDaoImplTests {
}
@Test
public void testStartupFailsIfUserMapSetToNull() throws Exception {
public void testStartupFailsIfUserMapSetToNull() {
JdbcDaoImpl dao = new JdbcDaoImpl();
try {
@@ -195,14 +195,14 @@ public class JdbcDaoImplTests {
}
@Test(expected = IllegalArgumentException.class)
public void setMessageSourceWhenNullThenThrowsException() throws Exception {
public void setMessageSourceWhenNullThenThrowsException() {
JdbcDaoImpl dao = new JdbcDaoImpl();
dao.setMessageSource(null);
}
@Test
public void setMessageSourceWhenNotNullThenCanGet() throws Exception {
public void setMessageSourceWhenNotNullThenCanGet() {
MessageSource source = mock(MessageSource.class);
JdbcDaoImpl dao = new JdbcDaoImpl();
dao.setMessageSource(source);
@@ -60,12 +60,12 @@ public class RememberMeAuthenticationTokenMixinTests extends AbstractMixinTests
// @formatter:on
@Test(expected = IllegalArgumentException.class)
public void testWithNullPrincipal() throws JsonProcessingException, JSONException {
public void testWithNullPrincipal() {
new RememberMeAuthenticationToken("key", null, Collections.<GrantedAuthority>emptyList());
}
@Test(expected = IllegalArgumentException.class)
public void testWithNullKey() throws JsonProcessingException, JSONException {
public void testWithNullKey() {
new RememberMeAuthenticationToken(null, "principal", Collections.<GrantedAuthority>emptyList());
}
@@ -44,7 +44,7 @@ public class SecurityJackson2ModulesTests {
}
@Test
public void readValueWhenNotWhitelistedOrMappedThenThrowsException() throws Exception {
public void readValueWhenNotWhitelistedOrMappedThenThrowsException() {
String content = "{\"@class\":\"org.springframework.security.jackson2.SecurityJackson2ModulesTests$NotWhitelisted\",\"property\":\"bar\"}";
assertThatThrownBy(() -> {
mapper.readValue(content, Object.class);
@@ -93,7 +93,7 @@ public class UsernamePasswordAuthenticationTokenMixinTests extends AbstractMixin
}
@Test
public void deserializeUnauthenticatedUsernamePasswordAuthenticationTokenMixinTest() throws IOException, JSONException {
public void deserializeUnauthenticatedUsernamePasswordAuthenticationTokenMixinTest() throws IOException {
UsernamePasswordAuthenticationToken token = mapper
.readValue(UNAUTHENTICATED_STRINGPRINCIPAL_JSON, UsernamePasswordAuthenticationToken.class);
assertThat(token).isNotNull();
@@ -290,7 +290,7 @@ public class JdbcUserDetailsManagerTests {
}
@Test
public void deleteGroupRemovesData() throws Exception {
public void deleteGroupRemovesData() {
manager.deleteGroup("GROUP_0");
manager.deleteGroup("GROUP_1");
manager.deleteGroup("GROUP_2");
@@ -302,7 +302,7 @@ public class JdbcUserDetailsManagerTests {
}
@Test
public void renameGroupIsSuccessful() throws Exception {
public void renameGroupIsSuccessful() {
manager.renameGroup("GROUP_0", "GROUP_X");
assertThat(template.queryForObject("select id from groups where group_name = 'GROUP_X'",
@@ -310,7 +310,7 @@ public class JdbcUserDetailsManagerTests {
}
@Test
public void addingGroupUserSetsCorrectData() throws Exception {
public void addingGroupUserSetsCorrectData() {
manager.addUserToGroup("tom", "GROUP_0");
assertThat(
@@ -319,7 +319,7 @@ public class JdbcUserDetailsManagerTests {
}
@Test
public void removeUserFromGroupDeletesGroupMemberRow() throws Exception {
public void removeUserFromGroupDeletesGroupMemberRow() {
manager.removeUserFromGroup("jerry", "GROUP_1");
assertThat(
@@ -328,12 +328,12 @@ public class JdbcUserDetailsManagerTests {
}
@Test
public void findGroupAuthoritiesReturnsCorrectAuthorities() throws Exception {
public void findGroupAuthoritiesReturnsCorrectAuthorities() {
assertThat(AuthorityUtils.createAuthorityList("ROLE_A")).isEqualTo(manager.findGroupAuthorities("GROUP_0"));
}
@Test
public void addGroupAuthorityInsertsCorrectGroupAuthorityRow() throws Exception {
public void addGroupAuthorityInsertsCorrectGroupAuthorityRow() {
GrantedAuthority auth = new SimpleGrantedAuthority("ROLE_X");
manager.addGroupAuthority("GROUP_0", auth);
@@ -343,7 +343,7 @@ public class JdbcUserDetailsManagerTests {
}
@Test
public void deleteGroupAuthorityRemovesCorrectRows() throws Exception {
public void deleteGroupAuthorityRemovesCorrectRows() {
GrantedAuthority auth = new SimpleGrantedAuthority("ROLE_A");
manager.removeGroupAuthority("GROUP_0", auth);
assertThat(
@@ -358,8 +358,7 @@ public class JdbcUserDetailsManagerTests {
// SEC-1156
@Test
public void createUserDoesNotSaveAuthoritiesIfEnableAuthoritiesIsFalse()
throws Exception {
public void createUserDoesNotSaveAuthoritiesIfEnableAuthoritiesIsFalse() {
manager.setEnableAuthorities(false);
manager.createUser(joe);
assertThat(template.queryForList(SELECT_JOE_AUTHORITIES_SQL)).isEmpty();
@@ -367,8 +366,7 @@ public class JdbcUserDetailsManagerTests {
// SEC-1156
@Test
public void updateUserDoesNotSaveAuthoritiesIfEnableAuthoritiesIsFalse()
throws Exception {
public void updateUserDoesNotSaveAuthoritiesIfEnableAuthoritiesIsFalse() {
manager.setEnableAuthorities(false);
insertJoe();
template.execute("delete from authorities where username='joe'");
@@ -33,7 +33,7 @@ public class InMemoryResourceTests {
}
@Test
public void resourceIsEqualToOneWithSameContent() throws Exception {
public void resourceIsEqualToOneWithSameContent() {
assertThat(new InMemoryResource("xxx")).isEqualTo(new InMemoryResource("xxx"));
assertThat(new InMemoryResource("xxx").equals(new InMemoryResource("xxxx"))).isFalse();
assertThat(new InMemoryResource("xxx").equals(new Object())).isFalse();
@@ -60,7 +60,7 @@ public class MethodInvocationUtilsTests {
}
@Test
public void createFromObjectLocatesExistingMethods() throws Exception {
public void createFromObjectLocatesExistingMethods() {
AdvisedTarget t = new AdvisedTarget();
// Just lie about interfaces
t.setInterfaces(new Class[] { Serializable.class, MethodInvocation.class,