1
0
mirror of synced 2026-08-03 16:56:56 +00:00

Use diamond type

This commit is contained in:
Johnny Lim
2017-11-20 02:25:30 +09:00
committed by Rob Winch
parent cfe40358bd
commit 57353d18e5
221 changed files with 423 additions and 428 deletions
@@ -57,7 +57,7 @@ public class BusinessServiceImpl<E extends Entity> implements BusinessService {
}
public List<Object> methodReturningAList(String userName, String arg2) {
return new ArrayList<Object>();
return new ArrayList<>();
}
public Object[] methodReturningAnArray(Object[] someArray) {
@@ -51,7 +51,7 @@ public class ExpressionProtectedBusinessServiceImpl implements BusinessService {
}
public List<Object> methodReturningAList(String userName, String arg2) {
return new ArrayList<Object>();
return new ArrayList<>();
}
@PostFilter("filterObject == 'bob'")
@@ -57,7 +57,7 @@ public class Jsr250BusinessServiceImpl implements BusinessService {
}
public List<?> methodReturningAList(String userName, String arg2) {
return new ArrayList<Object>();
return new ArrayList<>();
}
public Object[] methodReturningAnArray(Object[] someArray) {
@@ -35,7 +35,7 @@ public class Jsr250VoterTests {
// SEC-1443
@Test
public void supportsMultipleRolesCorrectly() throws Exception {
List<ConfigAttribute> attrs = new ArrayList<ConfigAttribute>();
List<ConfigAttribute> attrs = new ArrayList<>();
Jsr250Voter voter = new Jsr250Voter();
attrs.add(new Jsr250SecurityConfig("A"));
@@ -50,7 +50,7 @@ public class MethodExpressionVoterTests {
@Test
public void hasRoleExpressionDeniesUserWithoutRole() throws Exception {
List<ConfigAttribute> cad = new ArrayList<ConfigAttribute>(1);
List<ConfigAttribute> cad = new ArrayList<>(1);
cad.add(new PreInvocationExpressionAttribute(null, null, "hasRole('joedoesnt')"));
MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(),
methodTakingAnArray());
@@ -63,7 +63,7 @@ public abstract class HierarchicalRolesTestHelper {
return null;
}
List<String> result = new ArrayList<String>(authorities.size());
List<String> result = new ArrayList<>(authorities.size());
for (GrantedAuthority authority : authorities) {
result.add(authority.getAuthority());
}
@@ -71,7 +71,7 @@ public abstract class HierarchicalRolesTestHelper {
}
public static List<GrantedAuthority> createAuthorityList(final String... roles) {
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(roles.length);
List<GrantedAuthority> authorities = new ArrayList<>(roles.length);
for (final String role : roles) {
// Use non SimpleGrantedAuthority (SEC-863)
@@ -35,7 +35,7 @@ public class RoleHierarchyImplTests {
@Test
public void testRoleHierarchyWithNullOrEmptyAuthorities() {
List<GrantedAuthority> authorities0 = null;
List<GrantedAuthority> authorities1 = new ArrayList<GrantedAuthority>();
List<GrantedAuthority> authorities1 = new ArrayList<>();
RoleHierarchyImpl roleHierarchyImpl = new RoleHierarchyImpl();
roleHierarchyImpl.setHierarchy("ROLE_A > ROLE_B");
@@ -85,22 +85,22 @@ public class TestHelperTests {
Collection<GrantedAuthority> authorities5 = AuthorityUtils.createAuthorityList(
"ROLE_A", "ROLE_A");
List<String> authoritiesStrings1 = new ArrayList<String>();
List<String> authoritiesStrings1 = new ArrayList<>();
authoritiesStrings1.add("ROLE_A");
authoritiesStrings1.add("ROLE_B");
List<String> authoritiesStrings2 = new ArrayList<String>();
List<String> authoritiesStrings2 = new ArrayList<>();
authoritiesStrings2.add("ROLE_B");
authoritiesStrings2.add("ROLE_A");
List<String> authoritiesStrings3 = new ArrayList<String>();
List<String> authoritiesStrings3 = new ArrayList<>();
authoritiesStrings3.add("ROLE_A");
authoritiesStrings3.add("ROLE_C");
List<String> authoritiesStrings4 = new ArrayList<String>();
List<String> authoritiesStrings4 = new ArrayList<>();
authoritiesStrings4.add("ROLE_A");
List<String> authoritiesStrings5 = new ArrayList<String>();
List<String> authoritiesStrings5 = new ArrayList<>();
authoritiesStrings5.add("ROLE_A");
authoritiesStrings5.add("ROLE_A");
@@ -60,7 +60,7 @@ public class AbstractAclVoterTests {
public void correctArgumentIsSelectedFromMultipleArgs() throws Exception {
voter.setProcessDomainObjectClass(String.class);
MethodInvocation mi = MethodInvocationUtils.create(new TestClass(),
"methodTakingAListAndAString", new ArrayList<Object>(), "The Argument");
"methodTakingAListAndAString", new ArrayList<>(), "The Argument");
assertThat(voter.getDomainObjectInstance(mi)).isEqualTo("The Argument");
}
@@ -38,7 +38,7 @@ import org.springframework.security.core.Authentication;
* @author Ben Alex
*/
public class AffirmativeBasedTests {
private final List<ConfigAttribute> attrs = new ArrayList<ConfigAttribute>();
private final List<ConfigAttribute> attrs = new ArrayList<>();
private final Authentication user = new TestingAuthenticationToken("somebody",
"password", "ROLE_1", "ROLE_2");
private AffirmativeBased mgr;
@@ -27,7 +27,6 @@ import org.junit.Test;
import org.springframework.context.MessageSource;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.GrantedAuthority;
/**
* Tests {@link ProviderManager}.
@@ -318,12 +317,12 @@ public class ProviderManagerTests {
private TestingAuthenticationToken createAuthenticationToken() {
return new TestingAuthenticationToken("name", "password",
new ArrayList<GrantedAuthority>(0));
new ArrayList<>(0));
}
private ProviderManager makeProviderManager() throws Exception {
MockProvider provider1 = new MockProvider();
List<AuthenticationProvider> providers = new ArrayList<AuthenticationProvider>();
List<AuthenticationProvider> providers = new ArrayList<>();
providers.add(provider1);
return new ProviderManager(providers);
@@ -561,14 +561,14 @@ public class DaoAuthenticationProviderTests {
int sampleSize = 100;
List<Long> userFoundTimes = new ArrayList<Long>(sampleSize);
List<Long> userFoundTimes = new ArrayList<>(sampleSize);
for (int i = 0; i < sampleSize; i++) {
long start = System.currentTimeMillis();
provider.authenticate(foundUser);
userFoundTimes.add(System.currentTimeMillis() - start);
}
List<Long> userNotFoundTimes = new ArrayList<Long>(sampleSize);
List<Long> userNotFoundTimes = new ArrayList<>(sampleSize);
for (int i = 0; i < sampleSize; i++) {
long start = System.currentTimeMillis();
try {
@@ -26,7 +26,7 @@ import org.springframework.security.core.userdetails.UserCache;
import org.springframework.security.core.userdetails.UserDetails;
public class MockUserCache implements UserCache {
private Map<String, UserDetails> cache = new HashMap<String, UserDetails>();
private Map<String, UserDetails> cache = new HashMap<>();
public UserDetails getUserFromCache(String username) {
return (User) cache.get(username);
@@ -16,7 +16,6 @@
package org.springframework.security.authentication.jaas;
import java.security.Principal;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -44,8 +43,8 @@ public class SecurityContextLoginModuleTests {
// ================================================================================================
private SecurityContextLoginModule module = null;
private Subject subject = new Subject(false, new HashSet<Principal>(),
new HashSet<Object>(), new HashSet<Object>());
private Subject subject = new Subject(false, new HashSet<>(),
new HashSet<>(), new HashSet<>());
private UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(
"principal", "credentials");
@@ -127,7 +126,7 @@ public class SecurityContextLoginModuleTests {
public void testNullAuthenticationInSecurityContextIgnored() throws Exception {
this.module = new SecurityContextLoginModule();
Map<String, String> options = new HashMap<String, String>();
Map<String, String> options = new HashMap<>();
options.put("ignoreMissingAuthentication", "true");
this.module.initialize(this.subject, null, null, options);
@@ -32,7 +32,7 @@ public class TestAuthorityGranter implements AuthorityGranter {
// ========================================================================================================
public Set<String> grant(Principal principal) {
Set<String> rtnSet = new HashSet<String>();
Set<String> rtnSet = new HashSet<>();
if (principal.getName().equals("TEST_PRINCIPAL")) {
rtnSet.add("ROLE_TEST1");
@@ -58,7 +58,7 @@ public class RememberMeAuthenticationTokenTests {
}
try {
List<GrantedAuthority> authsContainingNull = new ArrayList<GrantedAuthority>();
List<GrantedAuthority> authsContainingNull = new ArrayList<>();
authsContainingNull.add(null);
new RememberMeAuthenticationToken("key", "Test", authsContainingNull);
fail("Should have thrown IllegalArgumentException");
@@ -78,29 +78,29 @@ public class DelegatingSecurityContextCallableTests {
@Test(expected = IllegalArgumentException.class)
public void constructorNullDelegate() {
new DelegatingSecurityContextCallable<Object>(null);
new DelegatingSecurityContextCallable<>(null);
}
@Test(expected = IllegalArgumentException.class)
public void constructorNullDelegateNonNullSecurityContext() {
new DelegatingSecurityContextCallable<Object>(null, securityContext);
new DelegatingSecurityContextCallable<>(null, securityContext);
}
@Test(expected = IllegalArgumentException.class)
public void constructorNullDelegateAndSecurityContext() {
new DelegatingSecurityContextCallable<Object>(null, null);
new DelegatingSecurityContextCallable<>(null, null);
}
@Test(expected = IllegalArgumentException.class)
public void constructorNullSecurityContext() {
new DelegatingSecurityContextCallable<Object>(delegate, null);
new DelegatingSecurityContextCallable<>(delegate, null);
}
// --- call ---
@Test
public void call() throws Exception {
callable = new DelegatingSecurityContextCallable<Object>(delegate,
callable = new DelegatingSecurityContextCallable<>(delegate,
securityContext);
assertWrapped(callable);
}
@@ -108,7 +108,7 @@ public class DelegatingSecurityContextCallableTests {
@Test
public void callDefaultSecurityContext() throws Exception {
SecurityContextHolder.setContext(securityContext);
callable = new DelegatingSecurityContextCallable<Object>(delegate);
callable = new DelegatingSecurityContextCallable<>(delegate);
SecurityContextHolder.clearContext(); // ensure callable is what sets up the
// SecurityContextHolder
assertWrapped(callable);
@@ -119,7 +119,7 @@ public class DelegatingSecurityContextCallableTests {
public void callOnSameThread() throws Exception {
originalSecurityContext = securityContext;
SecurityContextHolder.setContext(originalSecurityContext);
callable = new DelegatingSecurityContextCallable<Object>(delegate,
callable = new DelegatingSecurityContextCallable<>(delegate,
securityContext);
assertWrapped(callable.call());
}
@@ -156,7 +156,7 @@ public class DelegatingSecurityContextCallableTests {
// SEC-2682
@Test
public void toStringDelegates() {
callable = new DelegatingSecurityContextCallable<Object>(delegate,
callable = new DelegatingSecurityContextCallable<>(delegate,
securityContext);
assertThat(callable.toString()).isEqualTo(delegate.toString());
}
@@ -128,7 +128,7 @@ public class SimpleRoles2GrantedAuthoritiesMapperTests {
String[] expectedGas) {
List<GrantedAuthority> result = mapper
.getGrantedAuthorities(Arrays.asList(roles));
Collection<String> resultColl = new ArrayList<String>(result.size());
Collection<String> resultColl = new ArrayList<>(result.size());
for (int i = 0; i < result.size(); i++) {
resultColl.add(result.get(i).getAuthority());
}
@@ -30,7 +30,7 @@ import org.springframework.security.core.authority.AuthorityUtils;
* @author Luke Taylor
*/
public class MockUserDetailsService implements UserDetailsService {
private Map<String, User> users = new HashMap<String, User>();
private Map<String, User> users = new HashMap<>();
private List<GrantedAuthority> auths = AuthorityUtils
.createAuthorityList("ROLE_USER");
@@ -56,7 +56,7 @@ public class UserTests {
@Test
public void hashLookupOnlyDependsOnUsername() throws Exception {
User user1 = new User("rod", "koala", true, true, true, true, ROLE_12);
Set<UserDetails> users = new HashSet<UserDetails>();
Set<UserDetails> users = new HashSet<>();
users.add(user1);
assertThat(users).contains(new User("rod", "koala", true, true, true, true,
@@ -26,7 +26,6 @@ import org.junit.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
@@ -138,7 +137,7 @@ public class UsernamePasswordAuthenticationTokenMixinTests extends AbstractMixin
NonUserPrincipal principal = new NonUserPrincipal();
principal.setUsername("admin");
UsernamePasswordAuthenticationToken token =
new UsernamePasswordAuthenticationToken(principal, null, new ArrayList<GrantedAuthority>());
new UsernamePasswordAuthenticationToken(principal, null, new ArrayList<>());
String actualJson = mapper.writeValueAsString(token);
JSONAssert.assertEquals(AUTHENTICATED_NON_USER_PRINCIPAL_JSON, actualJson, true);
}
@@ -359,7 +359,7 @@ public class JdbcUserDetailsManagerTests {
}
private class MockUserCache implements UserCache {
private Map<String, UserDetails> cache = new HashMap<String, UserDetails>();
private Map<String, UserDetails> cache = new HashMap<>();
public UserDetails getUserFromCache(String username) {
return (User) cache.get(username);