Browse Source

Polish more AssertJ assertions

pull/4559/merge
Antoine 9 years ago committed by Rob Winch
parent
commit
0771778b81
  1. 12
      acl/src/test/java/org/springframework/security/acls/domain/ObjectIdentityImplTests.java
  2. 8
      acl/src/test/java/org/springframework/security/acls/jdbc/SpringCacheBasedAclCacheTests.java
  3. 6
      core/src/test/java/org/springframework/security/access/hierarchicalroles/TestHelperTests.java
  4. 4
      core/src/test/java/org/springframework/security/provisioning/JdbcUserDetailsManagerTests.java
  5. 10
      itest/misc/src/integration-test/java/org/springframework/security/context/SecurityContextHolderMTTests.java
  6. 4
      openid/src/test/java/org/springframework/security/openid/OpenIDAuthenticationFilterTests.java
  7. 4
      samples/xml/gae/src/test/java/samples/gae/security/AppRoleTests.java
  8. 14
      web/src/test/java/org/springframework/security/web/authentication/preauth/j2ee/WebXmlJ2eeDefinedRolesRetrieverTests.java
  9. 4
      web/src/test/java/org/springframework/security/web/authentication/rememberme/AbstractRememberMeServicesTests.java
  10. 4
      web/src/test/java/org/springframework/security/web/authentication/rememberme/PersistentTokenBasedRememberMeServicesTests.java
  11. 14
      web/src/test/java/org/springframework/security/web/authentication/rememberme/TokenBasedRememberMeServicesTests.java
  12. 4
      web/src/test/java/org/springframework/security/web/csrf/CookieCsrfTokenRepositoryTests.java
  13. 4
      web/src/test/java/org/springframework/security/web/jackson2/SavedCookieMixinTests.java
  14. 4
      web/src/test/java/org/springframework/security/web/util/ThrowableAnalyzerTests.java

12
acl/src/test/java/org/springframework/security/acls/domain/ObjectIdentityImplTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -137,9 +137,9 @@ public class ObjectIdentityImplTests { @@ -137,9 +137,9 @@ public class ObjectIdentityImplTests {
String string = "SOME_STRING";
assertThat(string).isNotSameAs(obj);
assertThat(obj.equals(null)).isFalse();
assertThat(obj.equals("DIFFERENT_OBJECT_TYPE")).isFalse();
assertThat(obj.equals(new ObjectIdentityImpl(DOMAIN_CLASS, Long.valueOf(2)))).isFalse();
assertThat(obj).isNotNull();
assertThat(obj).isNotEqualTo("DIFFERENT_OBJECT_TYPE");
assertThat(obj).isNotEqualTo(new ObjectIdentityImpl(DOMAIN_CLASS, Long.valueOf(2)));
assertThat(obj).isNotEqualTo(new ObjectIdentityImpl(
"org.springframework.security.acls.domain.ObjectIdentityImplTests$MockOtherIdDomainObject",
Long.valueOf(1)));
@ -151,7 +151,7 @@ public class ObjectIdentityImplTests { @@ -151,7 +151,7 @@ public class ObjectIdentityImplTests {
public void hashcodeIsDifferentForDifferentJavaTypes() throws Exception {
ObjectIdentity obj = new ObjectIdentityImpl(Object.class, Long.valueOf(1));
ObjectIdentity obj2 = new ObjectIdentityImpl(String.class, Long.valueOf(1));
assertThat(obj.hashCode() == obj2.hashCode()).isFalse();
assertThat(obj.hashCode()).isNotEqualTo(obj2.hashCode());
}
@Test
@ -175,7 +175,7 @@ public class ObjectIdentityImplTests { @@ -175,7 +175,7 @@ public class ObjectIdentityImplTests {
public void stringAndNumericIdsAreNotEqual() throws Exception {
ObjectIdentity obj = new ObjectIdentityImpl(Object.class, "1000");
ObjectIdentity obj2 = new ObjectIdentityImpl(Object.class, Long.valueOf(1000));
assertThat(obj.equals(obj2)).isFalse();
assertThat(obj).isNotEqualTo(obj2);
}
// ~ Inner Classes

8
acl/src/test/java/org/springframework/security/acls/jdbc/SpringCacheBasedAclCacheTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -104,17 +104,17 @@ public class SpringCacheBasedAclCacheTests { @@ -104,17 +104,17 @@ public class SpringCacheBasedAclCacheTests {
// Try to evict an entry that doesn't exist
myCache.evictFromCache(Long.valueOf(3));
myCache.evictFromCache(new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(102)));
assertThat(4).isEqualTo(realCache.size());
assertThat(realCache).hasSize(4);
myCache.evictFromCache(Long.valueOf(1));
assertThat(2).isEqualTo(realCache.size());
assertThat(realCache).hasSize(2);
// Check the second object inserted
assertThat(acl2).isEqualTo(myCache.getFromCache(Long.valueOf(2)));
assertThat(acl2).isEqualTo(myCache.getFromCache(identity2));
myCache.evictFromCache(identity2);
assertThat(0).isEqualTo(realCache.size());
assertThat(realCache).isEmpty();
}
@SuppressWarnings("rawtypes")

6
core/src/test/java/org/springframework/security/access/hierarchicalroles/TestHelperTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -181,12 +181,12 @@ public class TestHelperTests { @@ -181,12 +181,12 @@ public class TestHelperTests {
public void testCreateAuthorityList() {
List<GrantedAuthority> authorities1 = HierarchicalRolesTestHelper
.createAuthorityList("ROLE_A");
assertThat(1).isEqualTo(authorities1.size());
assertThat(authorities1).hasSize(1);
assertThat(authorities1.get(0).getAuthority()).isEqualTo("ROLE_A");
List<GrantedAuthority> authorities2 = HierarchicalRolesTestHelper
.createAuthorityList("ROLE_A", "ROLE_C");
assertThat(2).isEqualTo(authorities2.size());
assertThat(authorities2).hasSize(2);
assertThat(authorities2.get(0).getAuthority()).isEqualTo("ROLE_A");
assertThat(authorities2.get(1).getAuthority()).isEqualTo("ROLE_C");
}

4
core/src/test/java/org/springframework/security/provisioning/JdbcUserDetailsManagerTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -262,7 +262,7 @@ public class JdbcUserDetailsManagerTests { @@ -262,7 +262,7 @@ public class JdbcUserDetailsManagerTests {
manager.renameGroup("GROUP_0", "GROUP_X");
assertThat(template.queryForObject("select id from groups where group_name = 'GROUP_X'",
Integer.class)).isEqualTo(0);
Integer.class)).isZero();
}
@Test

10
itest/misc/src/integration-test/java/org/springframework/security/context/SecurityContextHolderMTTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -45,14 +45,14 @@ public class SecurityContextHolderMTTests extends TestCase{ @@ -45,14 +45,14 @@ public class SecurityContextHolderMTTests extends TestCase{
assertThat(new SecurityContextHolder().toString().isTrue()
.lastIndexOf("SecurityContextHolder[strategy='org.springframework.security.context.InheritableThreadLocalSecurityContextHolderStrategy'") != -1);
loadStartAndWaitForThreads(true, "Main_", NUM_THREADS, false, true);
assertThat(errors).as("Thread errors detected; review log output for details").isEqualTo(0);
assertThat(errors).as("Thread errors detected; review log output for details").isZero();
}
public void testSynchronizationGlobal() throws Exception {
SecurityContextHolder.clearContext();
SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_GLOBAL);
loadStartAndWaitForThreads(true, "Main_", NUM_THREADS, true, false);
assertThat(errors).as("Thread errors detected; review log output for details").isEqualTo(0);
assertThat(errors).as("Thread errors detected; review log output for details").isZero();
}
public void testSynchronizationInheritableThreadLocal()
@ -60,14 +60,14 @@ public class SecurityContextHolderMTTests extends TestCase{ @@ -60,14 +60,14 @@ public class SecurityContextHolderMTTests extends TestCase{
SecurityContextHolder.clearContext();
SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
loadStartAndWaitForThreads(true, "Main_", NUM_THREADS, false, true);
assertThat(errors).as("Thread errors detected; review log output for details").isEqualTo(0);
assertThat(errors).as("Thread errors detected; review log output for details").isZero();
}
public void testSynchronizationThreadLocal() throws Exception {
SecurityContextHolder.clearContext();
SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_THREADLOCAL);
loadStartAndWaitForThreads(true, "Main_", NUM_THREADS, false, false);
assertThat(errors).as("Thread errors detected; review log output for details").isEqualTo(0);
assertThat(errors).as("Thread errors detected; review log output for details").isZero();
}
private void startAndRun(Thread[] threads) {

4
openid/src/test/java/org/springframework/security/openid/OpenIDAuthenticationFilterTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -103,7 +103,7 @@ public class OpenIDAuthenticationFilterTests { @@ -103,7 +103,7 @@ public class OpenIDAuthenticationFilterTests {
URI returnTo = new URI(filter.buildReturnToUrl(req));
String query = returnTo.getRawQuery();
assertThat(count(query, '=')).isEqualTo(1);
assertThat(count(query, '&')).isEqualTo(0);
assertThat(count(query, '&')).isZero();
}
/**

4
samples/xml/gae/src/test/java/samples/gae/security/AppRoleTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -37,7 +37,7 @@ public class AppRoleTests { @@ -37,7 +37,7 @@ public class AppRoleTests {
public void bitsAreCorrect() throws Exception {
// If this fails, someone has modified the Enum and the Datastore is probably
// corrupt!
assertThat(ADMIN.getBit()).isEqualTo(0);
assertThat(ADMIN.getBit()).isZero();
assertThat(NEW_USER.getBit()).isEqualTo(1);
assertThat(USER.getBit()).isEqualTo(2);
}

14
web/src/test/java/org/springframework/security/web/authentication/preauth/j2ee/WebXmlJ2eeDefinedRolesRetrieverTests.java

@ -30,8 +30,8 @@ public class WebXmlJ2eeDefinedRolesRetrieverTests { @@ -30,8 +30,8 @@ public class WebXmlJ2eeDefinedRolesRetrieverTests {
@Test
public void testRole1To4Roles() throws Exception {
List<String> ROLE1TO4_EXPECTED_ROLES = Arrays.asList(new String[] { "Role1",
"Role2", "Role3", "Role4" });
List<String> ROLE1TO4_EXPECTED_ROLES = Arrays.asList("Role1",
"Role2", "Role3", "Role4");
final Resource webXml = new ClassPathResource("webxml/Role1-4.web.xml");
WebXmlMappableAttributesRetriever rolesRetriever = new WebXmlMappableAttributesRetriever();
@ -47,11 +47,9 @@ public class WebXmlJ2eeDefinedRolesRetrieverTests { @@ -47,11 +47,9 @@ public class WebXmlJ2eeDefinedRolesRetrieverTests {
rolesRetriever.afterPropertiesSet();
Set<String> j2eeRoles = rolesRetriever.getMappableAttributes();
assertThat(j2eeRoles).isNotNull();
assertThat(j2eeRoles.size()).withFailMessage("J2eeRoles expected size: " + ROLE1TO4_EXPECTED_ROLES.size()
+ ", actual size: " + j2eeRoles).hasSize(ROLE1TO4_EXPECTED_ROLES.size());
assertThat(j2eeRoles).withFailMessage("J2eeRoles expected contents (arbitrary order).isTrue(): "
+ ROLE1TO4_EXPECTED_ROLES + ", actual content: " + j2eeRoles).containsAll(ROLE1TO4_EXPECTED_ROLES);
assertThat(j2eeRoles).isNotNull()
.hasSameSizeAs(ROLE1TO4_EXPECTED_ROLES)
.containsAll(ROLE1TO4_EXPECTED_ROLES);
}
@Test
@ -69,6 +67,6 @@ public class WebXmlJ2eeDefinedRolesRetrieverTests { @@ -69,6 +67,6 @@ public class WebXmlJ2eeDefinedRolesRetrieverTests {
});
rolesRetriever.afterPropertiesSet();
Set<String> j2eeRoles = rolesRetriever.getMappableAttributes();
assertThat(j2eeRoles).withFailMessage("actual size: " + j2eeRoles.size() + "J2eeRoles expected size: 0").isEmpty();
assertThat(j2eeRoles).isEmpty();
}
}

4
web/src/test/java/org/springframework/security/web/authentication/rememberme/AbstractRememberMeServicesTests.java

@ -421,7 +421,7 @@ public class AbstractRememberMeServicesTests { @@ -421,7 +421,7 @@ public class AbstractRememberMeServicesTests {
Cookie cookie = response.getCookie(
AbstractRememberMeServices.SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY);
assertThat(cookie.getVersion()).isEqualTo(0);
assertThat(cookie.getVersion()).isZero();
}
@Test
@ -453,7 +453,7 @@ public class AbstractRememberMeServicesTests { @@ -453,7 +453,7 @@ public class AbstractRememberMeServicesTests {
Cookie returnedCookie = response.getCookie(
AbstractRememberMeServices.SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY);
assertThat(returnedCookie).isNotNull();
assertThat(returnedCookie.getMaxAge()).isEqualTo(0);
assertThat(returnedCookie.getMaxAge()).isZero();
}
// ~ Inner Classes

4
web/src/test/java/org/springframework/security/web/authentication/rememberme/PersistentTokenBasedRememberMeServicesTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -135,7 +135,7 @@ public class PersistentTokenBasedRememberMeServicesTests { @@ -135,7 +135,7 @@ public class PersistentTokenBasedRememberMeServicesTests {
"somepass", "SOME_AUTH"));
Cookie returnedCookie = response.getCookie("mycookiename");
assertThat(returnedCookie).isNotNull();
assertThat(returnedCookie.getMaxAge()).isEqualTo(0);
assertThat(returnedCookie.getMaxAge()).isZero();
// SEC-1280
services.logout(request, response, null);

14
web/src/test/java/org/springframework/security/web/authentication/rememberme/TokenBasedRememberMeServicesTests.java

@ -136,7 +136,7 @@ public class TokenBasedRememberMeServicesTests { @@ -136,7 +136,7 @@ public class TokenBasedRememberMeServicesTests {
Cookie returnedCookie = response
.getCookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY);
assertThat(returnedCookie).isNotNull();
assertThat(returnedCookie.getMaxAge()).isEqualTo(0);
assertThat(returnedCookie.getMaxAge()).isZero();
}
@Test
@ -153,7 +153,7 @@ public class TokenBasedRememberMeServicesTests { @@ -153,7 +153,7 @@ public class TokenBasedRememberMeServicesTests {
Cookie returnedCookie = response
.getCookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY);
assertThat(returnedCookie).isNotNull();
assertThat(returnedCookie.getMaxAge()).isEqualTo(0);
assertThat(returnedCookie.getMaxAge()).isZero();
}
@Test
@ -169,7 +169,7 @@ public class TokenBasedRememberMeServicesTests { @@ -169,7 +169,7 @@ public class TokenBasedRememberMeServicesTests {
Cookie returnedCookie = response
.getCookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY);
assertThat(returnedCookie).isNotNull();
assertThat(returnedCookie.getMaxAge()).isEqualTo(0);
assertThat(returnedCookie.getMaxAge()).isZero();
}
@Test
@ -190,7 +190,7 @@ public class TokenBasedRememberMeServicesTests { @@ -190,7 +190,7 @@ public class TokenBasedRememberMeServicesTests {
Cookie returnedCookie = response
.getCookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY);
assertThat(returnedCookie).isNotNull();
assertThat(returnedCookie.getMaxAge()).isEqualTo(0);
assertThat(returnedCookie.getMaxAge()).isZero();
}
@Test
@ -207,7 +207,7 @@ public class TokenBasedRememberMeServicesTests { @@ -207,7 +207,7 @@ public class TokenBasedRememberMeServicesTests {
Cookie returnedCookie = response
.getCookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY);
assertThat(returnedCookie).isNotNull();
assertThat(returnedCookie.getMaxAge()).isEqualTo(0);
assertThat(returnedCookie.getMaxAge()).isZero();
}
@Test
@ -227,7 +227,7 @@ public class TokenBasedRememberMeServicesTests { @@ -227,7 +227,7 @@ public class TokenBasedRememberMeServicesTests {
Cookie returnedCookie = response
.getCookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY);
assertThat(returnedCookie).isNotNull();
assertThat(returnedCookie.getMaxAge()).isEqualTo(0);
assertThat(returnedCookie.getMaxAge()).isZero();
}
@Test
@ -270,7 +270,7 @@ public class TokenBasedRememberMeServicesTests { @@ -270,7 +270,7 @@ public class TokenBasedRememberMeServicesTests {
Cookie cookie = response.getCookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY);
assertThat(cookie).isNotNull();
assertThat(cookie.getMaxAge()).isEqualTo(0);
assertThat(cookie.getMaxAge()).isZero();
}
@Test

4
web/src/test/java/org/springframework/security/web/csrf/CookieCsrfTokenRepositoryTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -106,7 +106,7 @@ public class CookieCsrfTokenRepositoryTests { @@ -106,7 +106,7 @@ public class CookieCsrfTokenRepositoryTests {
Cookie tokenCookie = this.response
.getCookie(CookieCsrfTokenRepository.DEFAULT_CSRF_COOKIE_NAME);
assertThat(tokenCookie.getMaxAge()).isEqualTo(0);
assertThat(tokenCookie.getMaxAge()).isZero();
assertThat(tokenCookie.getName())
.isEqualTo(CookieCsrfTokenRepository.DEFAULT_CSRF_COOKIE_NAME);
assertThat(tokenCookie.getPath()).isEqualTo(this.request.getContextPath());

4
web/src/test/java/org/springframework/security/web/jackson2/SavedCookieMixinTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 the original author or authors.
* Copyright 2015-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -97,7 +97,7 @@ public class SavedCookieMixinTests extends AbstractMixinTests { @@ -97,7 +97,7 @@ public class SavedCookieMixinTests extends AbstractMixinTests {
assertThat(savedCookie.getName()).isEqualTo("SESSION");
assertThat(savedCookie.getValue()).isEqualTo("123456789");
assertThat(savedCookie.isSecure()).isEqualTo(false);
assertThat(savedCookie.getVersion()).isEqualTo(0);
assertThat(savedCookie.getVersion()).isZero();
assertThat(savedCookie.getComment()).isNull();
}
}

4
web/src/test/java/org/springframework/security/web/util/ThrowableAnalyzerTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -168,7 +168,7 @@ public class ThrowableAnalyzerTests { @@ -168,7 +168,7 @@ public class ThrowableAnalyzerTests {
};
assertThat(analyzer.getRegisteredTypes().length).withFailMessage(
"Unexpected number of registered types").isEqualTo(0);
"Unexpected number of registered types").isZero();
Throwable t = this.testTrace[0];
Throwable[] chain = analyzer.determineCauseChain(t);

Loading…
Cancel
Save