diff --git a/acl/src/test/java/org/springframework/security/acls/domain/AuditLoggerTests.java b/acl/src/test/java/org/springframework/security/acls/domain/AuditLoggerTests.java index a905a12d44..6ac3a254b6 100644 --- a/acl/src/test/java/org/springframework/security/acls/domain/AuditLoggerTests.java +++ b/acl/src/test/java/org/springframework/security/acls/domain/AuditLoggerTests.java @@ -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. @@ -61,14 +61,14 @@ public class AuditLoggerTests { public void nonAuditableAceIsIgnored() { AccessControlEntry ace = mock(AccessControlEntry.class); logger.logIfNeeded(true, ace); - assertThat(bytes.size()).isEqualTo(0); + assertThat(bytes.size()).isZero(); } @Test public void successIsNotLoggedIfAceDoesntRequireSuccessAudit() throws Exception { when(ace.isAuditSuccess()).thenReturn(false); logger.logIfNeeded(true, ace); - assertThat(bytes.size()).isEqualTo(0); + assertThat(bytes.size()).isZero(); } @Test @@ -76,20 +76,20 @@ public class AuditLoggerTests { when(ace.isAuditSuccess()).thenReturn(true); logger.logIfNeeded(true, ace); - assertThat(bytes.toString().startsWith("GRANTED due to ACE")).isTrue(); + assertThat(bytes.toString()).startsWith("GRANTED due to ACE"); } @Test public void failureIsntLoggedIfAceDoesntRequireFailureAudit() throws Exception { when(ace.isAuditFailure()).thenReturn(false); logger.logIfNeeded(false, ace); - assertThat(bytes.size()).isEqualTo(0); + assertThat(bytes.size()).isZero(); } @Test public void failureIsLoggedIfAceRequiresFailureAudit() throws Exception { when(ace.isAuditFailure()).thenReturn(true); logger.logIfNeeded(false, ace); - assertThat(bytes.toString().startsWith("DENIED due to ACE")).isTrue(); + assertThat(bytes.toString()).startsWith("DENIED due to ACE"); } } diff --git a/cas/src/test/java/org/springframework/security/cas/userdetails/GrantedAuthorityFromAssertionAttributesUserDetailsServiceTests.java b/cas/src/test/java/org/springframework/security/cas/userdetails/GrantedAuthorityFromAssertionAttributesUserDetailsServiceTests.java index f2f2449648..4ae42580e8 100644 --- a/cas/src/test/java/org/springframework/security/cas/userdetails/GrantedAuthorityFromAssertionAttributesUserDetailsServiceTests.java +++ b/cas/src/test/java/org/springframework/security/cas/userdetails/GrantedAuthorityFromAssertionAttributesUserDetailsServiceTests.java @@ -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. @@ -57,10 +57,7 @@ public class GrantedAuthorityFromAssertionAttributesUserDetailsServiceTests { assertion, "ticket"); UserDetails user = uds.loadUserDetails(token); Set roles = AuthorityUtils.authorityListToSet(user.getAuthorities()); - assertThat(roles.size()).isEqualTo(4); - assertThat(roles).contains("role_a1"); - assertThat(roles).contains("role_a2"); - assertThat(roles).contains("role_b"); - assertThat(roles).contains("role_c"); + assertThat(roles).containsExactlyInAnyOrder( + "role_a1", "role_a2", "role_b", "role_c"); } } diff --git a/config/src/test/java/org/springframework/security/config/annotation/web/messaging/MessageSecurityMetadataSourceRegistryTests.java b/config/src/test/java/org/springframework/security/config/annotation/web/messaging/MessageSecurityMetadataSourceRegistryTests.java index cd5b50239c..912c4de7f2 100644 --- a/config/src/test/java/org/springframework/security/config/annotation/web/messaging/MessageSecurityMetadataSourceRegistryTests.java +++ b/config/src/test/java/org/springframework/security/config/annotation/web/messaging/MessageSecurityMetadataSourceRegistryTests.java @@ -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. @@ -299,7 +299,7 @@ public class MessageSecurityMetadataSourceRegistryTests { if (attrs == null) { return null; } - assertThat(attrs.size()).isEqualTo(1); + assertThat(attrs).hasSize(1); return attrs.iterator().next().toString(); } } diff --git a/config/src/test/java/org/springframework/security/config/http/FilterSecurityMetadataSourceBeanDefinitionParserTests.java b/config/src/test/java/org/springframework/security/config/http/FilterSecurityMetadataSourceBeanDefinitionParserTests.java index a5e012fd50..7b8e1ccd9d 100644 --- a/config/src/test/java/org/springframework/security/config/http/FilterSecurityMetadataSourceBeanDefinitionParserTests.java +++ b/config/src/test/java/org/springframework/security/config/http/FilterSecurityMetadataSourceBeanDefinitionParserTests.java @@ -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. @@ -65,8 +65,7 @@ public class FilterSecurityMetadataSourceBeanDefinitionParserTests { .getBean("fids"); Collection cad = fids .getAttributes(createFilterInvocation("/anything", "GET")); - assertThat(cad).isNotNull(); - assertThat(cad.contains(new SecurityConfig("ROLE_A"))).isTrue(); + assertThat(cad).contains(new SecurityConfig("ROLE_A")); } @Test @@ -80,7 +79,7 @@ public class FilterSecurityMetadataSourceBeanDefinitionParserTests { ConfigAttribute[] cad = fids .getAttributes(createFilterInvocation("/anything", "GET")) .toArray(new ConfigAttribute[0]); - assertThat(cad.length).isEqualTo(1); + assertThat(cad).hasSize(1); assertThat(cad[0].toString()).isEqualTo("hasRole('ROLE_A')"); } @@ -98,9 +97,7 @@ public class FilterSecurityMetadataSourceBeanDefinitionParserTests { .getBean("fids"); Collection cad = fids .getAttributes(createFilterInvocation("/secure", "GET")); - assertThat(cad).isNotNull(); - assertThat(cad).hasSize(1); - assertThat(cad.contains(new SecurityConfig("ROLE_A"))).isTrue(); + assertThat(cad).containsExactly(new SecurityConfig("ROLE_A")); } @Test diff --git a/config/src/test/java/org/springframework/security/config/method/GlobalMethodSecurityBeanDefinitionParserTests.java b/config/src/test/java/org/springframework/security/config/method/GlobalMethodSecurityBeanDefinitionParserTests.java index 99148b34f1..d23d9e065b 100644 --- a/config/src/test/java/org/springframework/security/config/method/GlobalMethodSecurityBeanDefinitionParserTests.java +++ b/config/src/test/java/org/springframework/security/config/method/GlobalMethodSecurityBeanDefinitionParserTests.java @@ -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. @@ -108,7 +108,7 @@ public class GlobalMethodSecurityBeanDefinitionParserTests { // SEC-1213. Check the order Advisor[] advisors = ((Advised) target).getAdvisors(); - assertThat(advisors.length).isEqualTo(1); + assertThat(advisors).hasSize(1); assertThat(((MethodSecurityMetadataSourceAdvisor) advisors[0]).getOrder()).isEqualTo(1001); } @@ -308,7 +308,7 @@ public class GlobalMethodSecurityBeanDefinitionParserTests { target = (BusinessService) appContext.getBean("target"); Object[] arg = new String[] { "joe", "bob", "sam" }; Object[] result = target.methodReturningAnArray(arg); - assertThat(result.length).isEqualTo(1); + assertThat(result).hasSize(1); assertThat(result[0]).isEqualTo("bob"); } diff --git a/config/src/test/java/org/springframework/security/config/method/InterceptMethodsBeanDefinitionDecoratorTests.java b/config/src/test/java/org/springframework/security/config/method/InterceptMethodsBeanDefinitionDecoratorTests.java index 1e9ac2682e..f4bc9faedb 100644 --- a/config/src/test/java/org/springframework/security/config/method/InterceptMethodsBeanDefinitionDecoratorTests.java +++ b/config/src/test/java/org/springframework/security/config/method/InterceptMethodsBeanDefinitionDecoratorTests.java @@ -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. @@ -66,11 +66,11 @@ public class InterceptMethodsBeanDefinitionDecoratorTests implements @Test public void targetDoesntLoseApplicationListenerInterface() { assertThat(appContext.getBeansOfType(ApplicationListener.class)).hasSize(1); - assertThat(appContext.getBeanNamesForType(ApplicationListener.class).length).isEqualTo(1); + assertThat(appContext.getBeanNamesForType(ApplicationListener.class)).hasSize(1); appContext.publishEvent(new AuthenticationSuccessEvent( new TestingAuthenticationToken("user", ""))); - assertThat(target instanceof ApplicationListener).isTrue(); + assertThat(target).isInstanceOf(ApplicationListener.class); } @Test diff --git a/core/src/test/java/org/springframework/security/access/annotation/Jsr250MethodSecurityMetadataSourceTests.java b/core/src/test/java/org/springframework/security/access/annotation/Jsr250MethodSecurityMetadataSourceTests.java index 9fdf2e3158..d437f396b9 100644 --- a/core/src/test/java/org/springframework/security/access/annotation/Jsr250MethodSecurityMetadataSourceTests.java +++ b/core/src/test/java/org/springframework/security/access/annotation/Jsr250MethodSecurityMetadataSourceTests.java @@ -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. @@ -56,7 +56,7 @@ public class Jsr250MethodSecurityMetadataSourceTests { @Test public void methodWithRolesAllowedHasCorrectAttribute() throws Exception { ConfigAttribute[] accessAttributes = findAttributes("adminMethod"); - assertThat(accessAttributes.length).isEqualTo(1); + assertThat(accessAttributes).hasSize(1); assertThat(accessAttributes[0].toString()).isEqualTo("ROLE_ADMIN"); } @@ -95,7 +95,7 @@ public class Jsr250MethodSecurityMetadataSourceTests { this.mds.setDefaultRolePrefix("CUSTOMPREFIX_"); ConfigAttribute[] accessAttributes = findAttributes("adminMethod"); - assertThat(accessAttributes.length).isEqualTo(1); + assertThat(accessAttributes).hasSize(1); assertThat(accessAttributes[0].toString()).isEqualTo("CUSTOMPREFIX_ADMIN"); } @@ -104,7 +104,7 @@ public class Jsr250MethodSecurityMetadataSourceTests { this.mds.setDefaultRolePrefix(""); ConfigAttribute[] accessAttributes = findAttributes("adminMethod"); - assertThat(accessAttributes.length).isEqualTo(1); + assertThat(accessAttributes).hasSize(1); assertThat(accessAttributes[0].toString()).isEqualTo("ADMIN"); } @@ -113,14 +113,14 @@ public class Jsr250MethodSecurityMetadataSourceTests { this.mds.setDefaultRolePrefix(null); ConfigAttribute[] accessAttributes = findAttributes("adminMethod"); - assertThat(accessAttributes.length).isEqualTo(1); + assertThat(accessAttributes).hasSize(1); assertThat(accessAttributes[0].toString()).isEqualTo("ADMIN"); } @Test public void alreadyHasDefaultPrefix() throws Exception { ConfigAttribute[] accessAttributes = findAttributes("roleAdminMethod"); - assertThat(accessAttributes.length).isEqualTo(1); + assertThat(accessAttributes).hasSize(1); assertThat(accessAttributes[0].toString()).isEqualTo("ROLE_ADMIN"); } diff --git a/core/src/test/java/org/springframework/security/access/annotation/SecuredAnnotationSecurityMetadataSourceTests.java b/core/src/test/java/org/springframework/security/access/annotation/SecuredAnnotationSecurityMetadataSourceTests.java index 8bdd5ed575..669c6bcf6e 100644 --- a/core/src/test/java/org/springframework/security/access/annotation/SecuredAnnotationSecurityMetadataSourceTests.java +++ b/core/src/test/java/org/springframework/security/access/annotation/SecuredAnnotationSecurityMetadataSourceTests.java @@ -137,8 +137,6 @@ public class SecuredAnnotationSecurityMetadataSourceTests { Collection attrs = this.mds.findAttributes(method, BusinessService.class); - assertThat(attrs).isNotNull(); - // expect 2 attributes assertThat(attrs).hasSize(2); @@ -147,7 +145,7 @@ public class SecuredAnnotationSecurityMetadataSourceTests { // should have 2 SecurityConfigs for (ConfigAttribute sc : attrs) { - assertThat(sc instanceof SecurityConfig).isTrue(); + assertThat(sc).isInstanceOf(SecurityConfig.class); if (sc.getAttribute().equals("ROLE_USER")) { user = true; @@ -158,7 +156,7 @@ public class SecuredAnnotationSecurityMetadataSourceTests { } // expect to have ROLE_USER and ROLE_ADMIN - assertThat(user && admin).isTrue(); + assertThat(user).isEqualTo(admin).isTrue(); } // SEC-1491 @@ -168,8 +166,7 @@ public class SecuredAnnotationSecurityMetadataSourceTests { new CustomSecurityAnnotationMetadataExtractor()); Collection attrs = mds.findAttributes( CustomAnnotatedService.class); - assertThat(attrs).hasSize(1); - assertThat(attrs.toArray()[0]).isEqualTo(SecurityEnum.ADMIN); + assertThat(attrs).containsOnly(SecurityEnum.ADMIN); } @Test @@ -181,8 +178,8 @@ public class SecuredAnnotationSecurityMetadataSourceTests { ConfigAttribute[] attrs = mds.getAttributes(annotatedAtClassLevel).toArray( new ConfigAttribute[0]); - assertThat(attrs.length).isEqualTo(1); - assertThat(attrs[0].getAttribute()).isEqualTo("CUSTOM"); + assertThat(attrs).hasSize(1); + assertThat(attrs).extracting("attribute").containsOnly("CUSTOM"); } @Test @@ -194,8 +191,8 @@ public class SecuredAnnotationSecurityMetadataSourceTests { ConfigAttribute[] attrs = mds.getAttributes(annotatedAtInterfaceLevel).toArray( new ConfigAttribute[0]); - assertThat(attrs.length).isEqualTo(1); - assertThat(attrs[0].getAttribute()).isEqualTo("CUSTOM"); + assertThat(attrs).hasSize(1); + assertThat(attrs).extracting("attribute").containsOnly("CUSTOM"); } @Test @@ -206,15 +203,15 @@ public class SecuredAnnotationSecurityMetadataSourceTests { ConfigAttribute[] attrs = mds.getAttributes(annotatedAtMethodLevel).toArray( new ConfigAttribute[0]); - assertThat(attrs.length).isEqualTo(1); - assertThat(attrs[0].getAttribute()).isEqualTo("CUSTOM"); + assertThat(attrs).hasSize(1); + assertThat(attrs).extracting("attribute").containsOnly("CUSTOM"); } @Test public void proxyFactoryInterfaceAttributesFound() throws Exception { MockMethodInvocation mi = MethodInvocationFactory.createSec2150MethodInvocation(); Collection attributes = mds.getAttributes(mi); - assertThat(attributes.size()).isEqualTo(1); + assertThat(attributes).hasSize(1); assertThat(attributes).extracting("attribute").containsOnly("ROLE_PERSON"); } diff --git a/core/src/test/java/org/springframework/security/access/expression/method/PrePostAnnotationSecurityMetadataSourceTests.java b/core/src/test/java/org/springframework/security/access/expression/method/PrePostAnnotationSecurityMetadataSourceTests.java index 0d34abfbd9..a855719428 100644 --- a/core/src/test/java/org/springframework/security/access/expression/method/PrePostAnnotationSecurityMetadataSourceTests.java +++ b/core/src/test/java/org/springframework/security/access/expression/method/PrePostAnnotationSecurityMetadataSourceTests.java @@ -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. @@ -89,7 +89,7 @@ public class PrePostAnnotationSecurityMetadataSourceTests { ConfigAttribute[] attrs = mds.getAttributes(voidImpl1).toArray( new ConfigAttribute[0]); - assertThat(attrs.length).isEqualTo(1); + assertThat(attrs).hasSize(1); assertThat(attrs[0] instanceof PreInvocationExpressionAttribute).isTrue(); PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0]; assertThat(pre.getAuthorizeExpression()).isNotNull(); @@ -102,7 +102,7 @@ public class PrePostAnnotationSecurityMetadataSourceTests { ConfigAttribute[] attrs = mds.getAttributes(voidImpl2).toArray( new ConfigAttribute[0]); - assertThat(attrs.length).isEqualTo(1); + assertThat(attrs).hasSize(1); assertThat(attrs[0] instanceof PreInvocationExpressionAttribute).isTrue(); PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0]; assertThat(pre.getAuthorizeExpression().getExpressionString()).isEqualTo("someExpression"); @@ -115,7 +115,7 @@ public class PrePostAnnotationSecurityMetadataSourceTests { ConfigAttribute[] attrs = mds.getAttributes(voidImpl3).toArray( new ConfigAttribute[0]); - assertThat(attrs.length).isEqualTo(1); + assertThat(attrs).hasSize(1); assertThat(attrs[0] instanceof PreInvocationExpressionAttribute).isTrue(); PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0]; assertThat(pre.getAuthorizeExpression().getExpressionString()).isEqualTo("permitAll"); @@ -128,7 +128,7 @@ public class PrePostAnnotationSecurityMetadataSourceTests { ConfigAttribute[] attrs = mds.getAttributes(listImpl1).toArray( new ConfigAttribute[0]); - assertThat(attrs.length).isEqualTo(2); + assertThat(attrs).hasSize(2); assertThat(attrs[0] instanceof PreInvocationExpressionAttribute).isTrue(); assertThat(attrs[1] instanceof PostInvocationExpressionAttribute).isTrue(); PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0]; @@ -143,7 +143,7 @@ public class PrePostAnnotationSecurityMetadataSourceTests { ConfigAttribute[] attrs = mds.getAttributes(notherListImpl1).toArray( new ConfigAttribute[0]); - assertThat(attrs.length).isEqualTo(1); + assertThat(attrs).hasSize(1); assertThat(attrs[0] instanceof PreInvocationExpressionAttribute).isTrue(); PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0]; assertThat(pre.getFilterExpression()).isNotNull(); @@ -157,7 +157,7 @@ public class PrePostAnnotationSecurityMetadataSourceTests { ConfigAttribute[] attrs = mds.getAttributes(notherListImpl2).toArray( new ConfigAttribute[0]); - assertThat(attrs.length).isEqualTo(1); + assertThat(attrs).hasSize(1); assertThat(attrs[0] instanceof PreInvocationExpressionAttribute).isTrue(); PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0]; assertThat(pre.getFilterExpression()).isNotNull(); @@ -171,7 +171,7 @@ public class PrePostAnnotationSecurityMetadataSourceTests { ConfigAttribute[] attrs = mds.getAttributes(annotatedAtClassLevel).toArray( new ConfigAttribute[0]); - assertThat(attrs.length).isEqualTo(1); + assertThat(attrs).hasSize(1); } @Test @@ -179,7 +179,7 @@ public class PrePostAnnotationSecurityMetadataSourceTests { ConfigAttribute[] attrs = mds.getAttributes(annotatedAtInterfaceLevel).toArray( new ConfigAttribute[0]); - assertThat(attrs.length).isEqualTo(1); + assertThat(attrs).hasSize(1); } @Test @@ -187,14 +187,14 @@ public class PrePostAnnotationSecurityMetadataSourceTests { ConfigAttribute[] attrs = mds.getAttributes(annotatedAtMethodLevel).toArray( new ConfigAttribute[0]); - assertThat(attrs.length).isEqualTo(1); + assertThat(attrs).hasSize(1); } @Test public void proxyFactoryInterfaceAttributesFound() throws Exception { MockMethodInvocation mi = MethodInvocationFactory.createSec2150MethodInvocation(); Collection attributes = mds.getAttributes(mi); - assertThat(attributes.size()).isEqualTo(1); + assertThat(attributes).hasSize(1); Expression expression = (Expression) ReflectionTestUtils.getField(attributes .iterator().next(), "authorizeExpression"); assertThat(expression.getExpressionString()).isEqualTo("hasRole('ROLE_PERSON')"); diff --git a/core/src/test/java/org/springframework/security/access/vote/AbstractAccessDecisionManagerTests.java b/core/src/test/java/org/springframework/security/access/vote/AbstractAccessDecisionManagerTests.java index 2e92ba10da..bc381e8d14 100644 --- a/core/src/test/java/org/springframework/security/access/vote/AbstractAccessDecisionManagerTests.java +++ b/core/src/test/java/org/springframework/security/access/vote/AbstractAccessDecisionManagerTests.java @@ -87,7 +87,7 @@ public class AbstractAccessDecisionManagerTests { list.add(voter); list.add(denyVoter); MockDecisionManagerImpl mock = new MockDecisionManagerImpl(list); - assertThat(mock.getDecisionVoters().size()).isEqualTo(list.size()); + assertThat(mock.getDecisionVoters()).hasSize(list.size()); } @Test diff --git a/core/src/test/java/org/springframework/security/core/parameters/DefaultSecurityParameterNameDiscovererTests.java b/core/src/test/java/org/springframework/security/core/parameters/DefaultSecurityParameterNameDiscovererTests.java index 57c309ba50..d0c1ab8073 100644 --- a/core/src/test/java/org/springframework/security/core/parameters/DefaultSecurityParameterNameDiscovererTests.java +++ b/core/src/test/java/org/springframework/security/core/parameters/DefaultSecurityParameterNameDiscovererTests.java @@ -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. @@ -47,7 +47,7 @@ public class DefaultSecurityParameterNameDiscovererTests { List discoverers = (List) ReflectionTestUtils .getField(discoverer, "parameterNameDiscoverers"); - assertThat(discoverers.size()).isEqualTo(2); + assertThat(discoverers).hasSize(2); ParameterNameDiscoverer annotationDisc = discoverers.get(0); assertThat(annotationDisc).isInstanceOf(AnnotationParameterNameDiscoverer.class); @@ -67,7 +67,7 @@ public class DefaultSecurityParameterNameDiscovererTests { List discoverers = (List) ReflectionTestUtils .getField(discoverer, "parameterNameDiscoverers"); - assertThat(discoverers.size()).isEqualTo(3); + assertThat(discoverers).hasSize(3); assertThat(discoverers.get(0)).isInstanceOf( LocalVariableTableParameterNameDiscoverer.class); @@ -77,7 +77,7 @@ public class DefaultSecurityParameterNameDiscovererTests { annotationDisc, "annotationClassesToUse"); assertThat(annotationsToUse).containsOnly("org.springframework.security.access.method.P", P.class.getName()); - assertThat(discoverers.get(2).getClass()).isEqualTo( + assertThat(discoverers.get(2)).isInstanceOf( DefaultParameterNameDiscoverer.class); } } diff --git a/crypto/src/test/java/org/springframework/security/crypto/bcrypt/BCryptTests.java b/crypto/src/test/java/org/springframework/security/crypto/bcrypt/BCryptTests.java index e2fa5c298a..87ce274acc 100644 --- a/crypto/src/test/java/org/springframework/security/crypto/bcrypt/BCryptTests.java +++ b/crypto/src/test/java/org/springframework/security/crypto/bcrypt/BCryptTests.java @@ -218,21 +218,21 @@ public class BCryptTests { @Test public void decodingCharsOutsideAsciiGivesNoResults() { byte[] ba = BCrypt.decode_base64("ππππππππ", 1); - assertThat(ba.length).isEqualTo(0); + assertThat(ba).isEmpty(); } @Test public void decodingStopsWithFirstInvalidCharacter() { - assertThat(BCrypt.decode_base64("....", 1).length).isEqualTo(1); - assertThat(BCrypt.decode_base64(" ....", 1).length).isEqualTo(0); + assertThat(BCrypt.decode_base64("....", 1)).hasSize(1); + assertThat(BCrypt.decode_base64(" ....", 1)).isEmpty(); } @Test public void decodingOnlyProvidesAvailableBytes() { - assertThat(BCrypt.decode_base64("", 1).length).isEqualTo(0); - assertThat(BCrypt.decode_base64("......", 3).length).isEqualTo(3); - assertThat(BCrypt.decode_base64("......", 4).length).isEqualTo(4); - assertThat(BCrypt.decode_base64("......", 5).length).isEqualTo(4); + assertThat(BCrypt.decode_base64("", 1)).isEmpty(); + assertThat(BCrypt.decode_base64("......", 3)).hasSize(3); + assertThat(BCrypt.decode_base64("......", 4)).hasSize(4); + assertThat(BCrypt.decode_base64("......", 5)).hasSize(4); } /** @@ -268,8 +268,8 @@ public class BCryptTests { @Test public void genSaltGeneratesCorrectSaltPrefix() { - assertThat(BCrypt.gensalt(4).startsWith("$2a$04$")).isTrue(); - assertThat(BCrypt.gensalt(31).startsWith("$2a$31$")).isTrue(); + assertThat(BCrypt.gensalt(4)).startsWith("$2a$04$"); + assertThat(BCrypt.gensalt(31)).startsWith("$2a$31$"); } @Test(expected = IllegalArgumentException.class) diff --git a/crypto/src/test/java/org/springframework/security/crypto/codec/Utf8Tests.java b/crypto/src/test/java/org/springframework/security/crypto/codec/Utf8Tests.java index 5c576d3d89..d6cc64a40a 100644 --- a/crypto/src/test/java/org/springframework/security/crypto/codec/Utf8Tests.java +++ b/crypto/src/test/java/org/springframework/security/crypto/codec/Utf8Tests.java @@ -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. @@ -30,7 +30,7 @@ public class Utf8Tests { @Test public void utf8EncodesAndDecodesCorrectly() throws Exception { byte[] bytes = Utf8.encode("6048b75ed560785c"); - assertThat(bytes.length).isEqualTo(16); + assertThat(bytes).hasSize(16); assertThat(Arrays.equals("6048b75ed560785c".getBytes("UTF-8"), bytes)).isTrue(); String decoded = Utf8.decode(bytes); diff --git a/crypto/src/test/java/org/springframework/security/crypto/keygen/KeyGeneratorsTests.java b/crypto/src/test/java/org/springframework/security/crypto/keygen/KeyGeneratorsTests.java index fc619d8431..26cf721bbb 100644 --- a/crypto/src/test/java/org/springframework/security/crypto/keygen/KeyGeneratorsTests.java +++ b/crypto/src/test/java/org/springframework/security/crypto/keygen/KeyGeneratorsTests.java @@ -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. @@ -29,7 +29,7 @@ public class KeyGeneratorsTests { BytesKeyGenerator keyGenerator = KeyGenerators.secureRandom(); assertThat(keyGenerator.getKeyLength()).isEqualTo(8); byte[] key = keyGenerator.generateKey(); - assertThat(key.length).isEqualTo(8); + assertThat(key).hasSize(8); byte[] key2 = keyGenerator.generateKey(); assertThat(Arrays.equals(key, key2)).isFalse(); } @@ -39,7 +39,7 @@ public class KeyGeneratorsTests { BytesKeyGenerator keyGenerator = KeyGenerators.secureRandom(21); assertThat(keyGenerator.getKeyLength()).isEqualTo(21); byte[] key = keyGenerator.generateKey(); - assertThat(key.length).isEqualTo(21); + assertThat(key).hasSize(21); byte[] key2 = keyGenerator.generateKey(); assertThat(Arrays.equals(key, key2)).isFalse(); } @@ -49,7 +49,7 @@ public class KeyGeneratorsTests { BytesKeyGenerator keyGenerator = KeyGenerators.shared(21); assertThat(keyGenerator.getKeyLength()).isEqualTo(21); byte[] key = keyGenerator.generateKey(); - assertThat(key.length).isEqualTo(21); + assertThat(key).hasSize(21); byte[] key2 = keyGenerator.generateKey(); assertThat(Arrays.equals(key, key2)).isTrue(); } @@ -59,7 +59,7 @@ public class KeyGeneratorsTests { StringKeyGenerator keyGenerator = KeyGenerators.string(); String hexStringKey = keyGenerator.generateKey(); assertThat(hexStringKey.length()).isEqualTo(16); - assertThat(Hex.decode(hexStringKey).length).isEqualTo(8); + assertThat(Hex.decode(hexStringKey)).hasSize(8); String hexStringKey2 = keyGenerator.generateKey(); assertThat(hexStringKey.equals(hexStringKey2)).isFalse(); } diff --git a/crypto/src/test/java/org/springframework/security/crypto/util/EncodingUtilsTests.java b/crypto/src/test/java/org/springframework/security/crypto/util/EncodingUtilsTests.java index ceaefafe03..b9eb3450e9 100644 --- a/crypto/src/test/java/org/springframework/security/crypto/util/EncodingUtilsTests.java +++ b/crypto/src/test/java/org/springframework/security/crypto/util/EncodingUtilsTests.java @@ -57,7 +57,7 @@ public class EncodingUtilsTests { (byte) 67, (byte) 0xC0, (byte) 0xC1, (byte) 0xC2 }; byte[] two = new byte[] { (byte) 0xFF, (byte) 65, (byte) 66 }; byte[] subArray = EncodingUtils.subArray(bytes, 1, 4); - assertThat(subArray.length).isEqualTo(3); + assertThat(subArray).hasSize(3); assertThat(Arrays.equals(two, subArray)).isTrue(); } diff --git a/ldap/src/integration-test/java/org/springframework/security/ldap/SpringSecurityLdapTemplateITests.java b/ldap/src/integration-test/java/org/springframework/security/ldap/SpringSecurityLdapTemplateITests.java index 1bf4934e61..40eca85a2f 100644 --- a/ldap/src/integration-test/java/org/springframework/security/ldap/SpringSecurityLdapTemplateITests.java +++ b/ldap/src/integration-test/java/org/springframework/security/ldap/SpringSecurityLdapTemplateITests.java @@ -157,7 +157,7 @@ public class SpringSecurityLdapTemplateITests extends AbstractLdapIntegrationTes protected void assertAttributeValue(Map> record, String attributeName, String... values) { assertThat(record.containsKey(attributeName)).isTrue(); - assertThat(record.get(attributeName).size()).isEqualTo(values.length); + assertThat(record.get(attributeName)).hasSize(values.length); for (int i = 0; i < values.length; i++) { assertThat(record.get(attributeName).get(i)).isEqualTo(values[i]); } diff --git a/ldap/src/integration-test/java/org/springframework/security/ldap/userdetails/NestedLdapAuthoritiesPopulatorTests.java b/ldap/src/integration-test/java/org/springframework/security/ldap/userdetails/NestedLdapAuthoritiesPopulatorTests.java index 88e373a927..486e53a99d 100644 --- a/ldap/src/integration-test/java/org/springframework/security/ldap/userdetails/NestedLdapAuthoritiesPopulatorTests.java +++ b/ldap/src/integration-test/java/org/springframework/security/ldap/userdetails/NestedLdapAuthoritiesPopulatorTests.java @@ -122,7 +122,7 @@ public class NestedLdapAuthoritiesPopulatorTests extends AbstractLdapIntegration circularJavaDevelopers, jDevelopers, groovyDevelopers)); LdapAuthority[] ldapAuthorities = authorities.toArray(new LdapAuthority[0]); - assertThat(ldapAuthorities.length).isEqualTo(5); + assertThat(ldapAuthorities).hasSize(5); // closure group assertThat(ldapAuthorities[0].getAttributes().containsKey("member")).isTrue(); assertThat(ldapAuthorities[0].getAttributes().get("member")).isNotNull(); diff --git a/messaging/src/test/java/org/springframework/security/messaging/access/expression/ExpressionBasedMessageSecurityMetadataSourceFactoryTests.java b/messaging/src/test/java/org/springframework/security/messaging/access/expression/ExpressionBasedMessageSecurityMetadataSourceFactoryTests.java index 878f07e49c..701e7def8b 100644 --- a/messaging/src/test/java/org/springframework/security/messaging/access/expression/ExpressionBasedMessageSecurityMetadataSourceFactoryTests.java +++ b/messaging/src/test/java/org/springframework/security/messaging/access/expression/ExpressionBasedMessageSecurityMetadataSourceFactoryTests.java @@ -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. @@ -80,7 +80,7 @@ public class ExpressionBasedMessageSecurityMetadataSourceFactoryTests { Collection attrs = source.getAttributes(message); - assertThat(attrs.size()).isEqualTo(1); + assertThat(attrs).hasSize(1); ConfigAttribute attr = attrs.iterator().next(); assertThat(attr).isInstanceOf(MessageExpressionConfigAttribute.class); assertThat( @@ -94,7 +94,7 @@ public class ExpressionBasedMessageSecurityMetadataSourceFactoryTests { Collection attrs = source.getAttributes(message); - assertThat(attrs.size()).isEqualTo(1); + assertThat(attrs).hasSize(1); ConfigAttribute attr = attrs.iterator().next(); assertThat(attr).isInstanceOf(MessageExpressionConfigAttribute.class); assertThat( diff --git a/samples/javaconfig/data/src/test/java/samples/data/SecurityMessageRepositoryTests.java b/samples/javaconfig/data/src/test/java/samples/data/SecurityMessageRepositoryTests.java index cf3055e3c5..fd0068f427 100644 --- a/samples/javaconfig/data/src/test/java/samples/data/SecurityMessageRepositoryTests.java +++ b/samples/javaconfig/data/src/test/java/samples/data/SecurityMessageRepositoryTests.java @@ -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. @@ -63,7 +63,7 @@ public class SecurityMessageRepositoryTests { public void findAllOnlyToCurrentUser() { Long expectedId = user.getId(); List messages = repository.findAll(); - assertThat(messages.size()).isEqualTo(3); + assertThat(messages).hasSize(3); for (Message m : messages) { assertThat(m.getTo().getId()).isEqualTo(expectedId); } diff --git a/samples/xml/dms/src/test/java/sample/DmsIntegrationTests.java b/samples/xml/dms/src/test/java/sample/DmsIntegrationTests.java index b631f86a64..d3780c7964 100644 --- a/samples/xml/dms/src/test/java/sample/DmsIntegrationTests.java +++ b/samples/xml/dms/src/test/java/sample/DmsIntegrationTests.java @@ -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. @@ -102,7 +102,7 @@ public class DmsIntegrationTests extends AbstractTransactionalJUnit4SpringContex System.out.println("------ Test for username: " + username + " ------"); AbstractElement[] rootElements = this.documentDao .findElements(Directory.ROOT_DIRECTORY); - assertThat(rootElements.length).isEqualTo(3); + assertThat(rootElements).hasSize(3); Directory homeDir = null; Directory nonHomeDir = null; for (int i = 0; i < rootElements.length; i++) { @@ -117,12 +117,12 @@ public class DmsIntegrationTests extends AbstractTransactionalJUnit4SpringContex System.out.println("Non-home directory..: " + nonHomeDir.getFullName()); AbstractElement[] homeElements = this.documentDao.findElements(homeDir); - assertThat(homeElements.length).isEqualTo(12); // confidential and shared + assertThat(homeElements).hasSize(12); // confidential and shared // directories, // plus 10 files AbstractElement[] nonHomeElements = this.documentDao.findElements(nonHomeDir); - assertThat(nonHomeElements.length).isEqualTo(shouldBeFiltered ? 11 : 12); // cannot + assertThat(nonHomeElements).hasSize(shouldBeFiltered ? 11 : 12); // cannot // see // the user's // "confidential" diff --git a/test/src/test/java/org/springframework/security/test/web/servlet/request/SecurityMockMvcRequestPostProcessorsCertificateTests.java b/test/src/test/java/org/springframework/security/test/web/servlet/request/SecurityMockMvcRequestPostProcessorsCertificateTests.java index 1104f73130..d3649800e4 100644 --- a/test/src/test/java/org/springframework/security/test/web/servlet/request/SecurityMockMvcRequestPostProcessorsCertificateTests.java +++ b/test/src/test/java/org/springframework/security/test/web/servlet/request/SecurityMockMvcRequestPostProcessorsCertificateTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 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. @@ -58,7 +58,7 @@ public class SecurityMockMvcRequestPostProcessorsCertificateTests { X509Certificate[] certificates = (X509Certificate[]) postProcessedRequest .getAttribute("javax.servlet.request.X509Certificate"); - assertThat(certificates.length).isEqualTo(1); + assertThat(certificates).hasSize(1); assertThat(certificates[0].getSubjectDN().getName()).isEqualTo( "CN=rod, OU=Spring Security, O=Spring Framework"); } diff --git a/web/src/test/java/org/springframework/security/web/authentication/logout/CookieClearingLogoutHandlerTests.java b/web/src/test/java/org/springframework/security/web/authentication/logout/CookieClearingLogoutHandlerTests.java index d9ab2a58b5..2e3d95f857 100644 --- a/web/src/test/java/org/springframework/security/web/authentication/logout/CookieClearingLogoutHandlerTests.java +++ b/web/src/test/java/org/springframework/security/web/authentication/logout/CookieClearingLogoutHandlerTests.java @@ -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. @@ -38,10 +38,10 @@ public class CookieClearingLogoutHandlerTests { request.setContextPath(""); CookieClearingLogoutHandler handler = new CookieClearingLogoutHandler("my_cookie"); handler.logout(request, response, mock(Authentication.class)); - assertThat(response.getCookies().length).isEqualTo(1); + assertThat(response.getCookies()).hasSize(1); for (Cookie c : response.getCookies()) { assertThat(c.getPath()).isEqualTo("/"); - assertThat(c.getMaxAge()).isEqualTo(0); + assertThat(c.getMaxAge()).isZero(); } } @@ -53,10 +53,10 @@ public class CookieClearingLogoutHandlerTests { CookieClearingLogoutHandler handler = new CookieClearingLogoutHandler( "my_cookie", "my_cookie_too"); handler.logout(request, response, mock(Authentication.class)); - assertThat(response.getCookies().length).isEqualTo(2); + assertThat(response.getCookies()).hasSize(2); for (Cookie c : response.getCookies()) { assertThat(c.getPath()).isEqualTo("/app"); - assertThat(c.getMaxAge()).isEqualTo(0); + assertThat(c.getMaxAge()).isZero(); } } } diff --git a/web/src/test/java/org/springframework/security/web/authentication/preauth/j2ee/J2eeBasedPreAuthenticatedWebAuthenticationDetailsSourceTests.java b/web/src/test/java/org/springframework/security/web/authentication/preauth/j2ee/J2eeBasedPreAuthenticatedWebAuthenticationDetailsSourceTests.java index 0772381368..cc7cbf0cd5 100644 --- a/web/src/test/java/org/springframework/security/web/authentication/preauth/j2ee/J2eeBasedPreAuthenticatedWebAuthenticationDetailsSourceTests.java +++ b/web/src/test/java/org/springframework/security/web/authentication/preauth/j2ee/J2eeBasedPreAuthenticatedWebAuthenticationDetailsSourceTests.java @@ -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. @@ -124,7 +124,7 @@ public class J2eeBasedPreAuthenticatedWebAuthenticationDetailsSourceTests { PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails details = (PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails) o; List gas = details.getGrantedAuthorities(); assertThat(gas).as("Granted authorities should not be null").isNotNull(); - assertThat(gas.size()).isEqualTo(expectedRoles.length); + assertThat(gas).hasSize(expectedRoles.length); Collection expectedRolesColl = Arrays.asList(expectedRoles); Collection gasRolesSet = new HashSet(); diff --git a/web/src/test/java/org/springframework/security/web/authentication/preauth/j2ee/WebXmlJ2eeDefinedRolesRetrieverTests.java b/web/src/test/java/org/springframework/security/web/authentication/preauth/j2ee/WebXmlJ2eeDefinedRolesRetrieverTests.java index b32ef5760e..ebac35d37b 100644 --- a/web/src/test/java/org/springframework/security/web/authentication/preauth/j2ee/WebXmlJ2eeDefinedRolesRetrieverTests.java +++ b/web/src/test/java/org/springframework/security/web/authentication/preauth/j2ee/WebXmlJ2eeDefinedRolesRetrieverTests.java @@ -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. @@ -49,7 +49,7 @@ public class WebXmlJ2eeDefinedRolesRetrieverTests { Set j2eeRoles = rolesRetriever.getMappableAttributes(); assertThat(j2eeRoles).isNotNull(); assertThat(j2eeRoles.size()).withFailMessage("J2eeRoles expected size: " + ROLE1TO4_EXPECTED_ROLES.size() - + ", actual size: " + j2eeRoles.size()).isEqualTo(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); } diff --git a/web/src/test/java/org/springframework/security/web/authentication/rememberme/AbstractRememberMeServicesTests.java b/web/src/test/java/org/springframework/security/web/authentication/rememberme/AbstractRememberMeServicesTests.java index 6771afd566..a2ddfe7f0d 100644 --- a/web/src/test/java/org/springframework/security/web/authentication/rememberme/AbstractRememberMeServicesTests.java +++ b/web/src/test/java/org/springframework/security/web/authentication/rememberme/AbstractRememberMeServicesTests.java @@ -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. @@ -98,11 +98,7 @@ public class AbstractRememberMeServicesTests { assertThat(encoded.endsWith("=")).isFalse(); String[] decoded = services.decodeCookie(encoded); - assertThat(decoded.length).isEqualTo(4); - assertThat(decoded[0]).isEqualTo("name"); - assertThat(decoded[1]).isEqualTo("cookie"); - assertThat(decoded[2]).isEqualTo("tokens"); - assertThat(decoded[3]).isEqualTo("blah"); + assertThat(decoded).containsExactly("name", "cookie", "tokens", "blah"); } @Test @@ -112,13 +108,13 @@ public class AbstractRememberMeServicesTests { MockRememberMeServices services = new MockRememberMeServices(uds); String[] decoded = services.decodeCookie(services.encodeCookie(cookie)); - assertThat(decoded.length).isEqualTo(4); + assertThat(decoded).hasSize(4); assertThat(decoded[0]).isEqualTo("http://id.openid.zz"); // Check https (SEC-1410) cookie[0] = "https://id.openid.zz"; decoded = services.decodeCookie(services.encodeCookie(cookie)); - assertThat(decoded.length).isEqualTo(4); + assertThat(decoded).hasSize(4); assertThat(decoded[0]).isEqualTo("https://id.openid.zz"); } diff --git a/web/src/test/java/org/springframework/security/web/authentication/www/DigestAuthUtilsTests.java b/web/src/test/java/org/springframework/security/web/authentication/www/DigestAuthUtilsTests.java index a6840a7897..c5e5e0e025 100644 --- a/web/src/test/java/org/springframework/security/web/authentication/www/DigestAuthUtilsTests.java +++ b/web/src/test/java/org/springframework/security/web/authentication/www/DigestAuthUtilsTests.java @@ -144,11 +144,11 @@ public class DigestAuthUtilsTests { @Test public void testSplitWorksWithDifferentDelimiters() { - assertThat(DigestAuthUtils.split("18/rod", "/").length).isEqualTo(2); + assertThat(DigestAuthUtils.split("18/rod", "/")).hasSize(2); assertThat(DigestAuthUtils.split("18/rod", "!")).isNull(); // only guarantees to split at FIRST delimiter, not EACH delimiter - assertThat(DigestAuthUtils.split("18|rod|foo|bar", "|").length).isEqualTo(2); + assertThat(DigestAuthUtils.split("18|rod|foo|bar", "|")).hasSize(2); } public void testAuthorizationHeaderWithCommasIsSplitCorrectly() { @@ -157,6 +157,6 @@ public class DigestAuthUtilsTests { String[] parts = DigestAuthUtils.splitIgnoringQuotes(header, ','); - assertThat(parts.length).isEqualTo(8); + assertThat(parts).hasSize(8); } } diff --git a/web/src/test/java/org/springframework/security/web/authentication/www/DigestAuthenticationEntryPointTests.java b/web/src/test/java/org/springframework/security/web/authentication/www/DigestAuthenticationEntryPointTests.java index 9c7483b2bb..6433cbb4dc 100644 --- a/web/src/test/java/org/springframework/security/web/authentication/www/DigestAuthenticationEntryPointTests.java +++ b/web/src/test/java/org/springframework/security/web/authentication/www/DigestAuthenticationEntryPointTests.java @@ -47,7 +47,7 @@ public class DigestAuthenticationEntryPointTests { String decodedNonce = new String(Base64.decodeBase64(nonce.getBytes())); String[] nonceTokens = StringUtils.delimitedListToStringArray(decodedNonce, ":"); - assertThat(nonceTokens.length).isEqualTo(2); + assertThat(nonceTokens).hasSize(2); String expectedNonceSignature = DigestUtils.md5Hex(nonceTokens[0] + ":" + "key"); assertThat(nonceTokens[1]).isEqualTo(expectedNonceSignature); diff --git a/web/src/test/java/org/springframework/security/web/header/writers/CacheControlHeadersWriterTests.java b/web/src/test/java/org/springframework/security/web/header/writers/CacheControlHeadersWriterTests.java index ca4f816c33..3b6ed7cac5 100644 --- a/web/src/test/java/org/springframework/security/web/header/writers/CacheControlHeadersWriterTests.java +++ b/web/src/test/java/org/springframework/security/web/header/writers/CacheControlHeadersWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 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. @@ -60,13 +60,11 @@ public class CacheControlHeadersWriterTests { public void writeHeaders() { this.writer.writeHeaders(this.request, this.response); - assertThat(this.response.getHeaderNames().size()).isEqualTo(3); - assertThat(this.response.getHeaderValues("Cache-Control")).isEqualTo( - Arrays.asList("no-cache, no-store, max-age=0, must-revalidate")); - assertThat(this.response.getHeaderValues("Pragma")) - .isEqualTo(Arrays.asList("no-cache")); - assertThat(this.response.getHeaderValues("Expires")) - .isEqualTo(Arrays.asList("0")); + assertThat(this.response.getHeaderNames()).hasSize(3); + assertThat(this.response.getHeaderValues("Cache-Control")).containsExactly( + "no-cache, no-store, max-age=0, must-revalidate"); + assertThat(this.response.getHeaderValues("Pragma")).containsOnly("no-cache"); + assertThat(this.response.getHeaderValues("Expires")).containsOnly("0"); } @Test @@ -80,13 +78,11 @@ public class CacheControlHeadersWriterTests { this.writer.writeHeaders(this.request, this.response); - assertThat(this.response.getHeaderNames().size()).isEqualTo(3); - assertThat(this.response.getHeaderValues("Cache-Control")).isEqualTo( - Arrays.asList("no-cache, no-store, max-age=0, must-revalidate")); - assertThat(this.response.getHeaderValues("Pragma")) - .isEqualTo(Arrays.asList("no-cache")); - assertThat(this.response.getHeaderValues("Expires")) - .isEqualTo(Arrays.asList("0")); + assertThat(this.response.getHeaderNames()).hasSize(3); + assertThat(this.response.getHeaderValues("Cache-Control")).containsExactly( + "no-cache, no-store, max-age=0, must-revalidate"); + assertThat(this.response.getHeaderValues("Pragma")).containsOnly("no-cache"); + assertThat(this.response.getHeaderValues("Expires")).containsOnly("0"); } // gh-2953 diff --git a/web/src/test/java/org/springframework/security/web/header/writers/ContentSecurityPolicyHeaderWriterTests.java b/web/src/test/java/org/springframework/security/web/header/writers/ContentSecurityPolicyHeaderWriterTests.java index c73f7a6806..616841535a 100644 --- a/web/src/test/java/org/springframework/security/web/header/writers/ContentSecurityPolicyHeaderWriterTests.java +++ b/web/src/test/java/org/springframework/security/web/header/writers/ContentSecurityPolicyHeaderWriterTests.java @@ -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. @@ -43,7 +43,7 @@ public class ContentSecurityPolicyHeaderWriterTests { public void writeHeadersContentSecurityPolicyDefault() { writer.writeHeaders(request, response); - assertThat(response.getHeaderNames().size()).isEqualTo(1); + assertThat(response.getHeaderNames()).hasSize(1); assertThat(response.getHeader("Content-Security-Policy")).isEqualTo(DEFAULT_POLICY_DIRECTIVES); } @@ -56,7 +56,7 @@ public class ContentSecurityPolicyHeaderWriterTests { writer = new ContentSecurityPolicyHeaderWriter(policyDirectives); writer.writeHeaders(request, response); - assertThat(response.getHeaderNames().size()).isEqualTo(1); + assertThat(response.getHeaderNames()).hasSize(1); assertThat(response.getHeader("Content-Security-Policy")).isEqualTo(policyDirectives); } @@ -65,7 +65,7 @@ public class ContentSecurityPolicyHeaderWriterTests { writer.setReportOnly(true); writer.writeHeaders(request, response); - assertThat(response.getHeaderNames().size()).isEqualTo(1); + assertThat(response.getHeaderNames()).hasSize(1); assertThat(response.getHeader("Content-Security-Policy-Report-Only")).isEqualTo(DEFAULT_POLICY_DIRECTIVES); } @@ -77,7 +77,7 @@ public class ContentSecurityPolicyHeaderWriterTests { writer.setReportOnly(true); writer.writeHeaders(request, response); - assertThat(response.getHeaderNames().size()).isEqualTo(1); + assertThat(response.getHeaderNames()).hasSize(1); assertThat(response.getHeader("Content-Security-Policy-Report-Only")).isEqualTo(policyDirectives); } diff --git a/web/src/test/java/org/springframework/security/web/header/writers/HstsHeaderWriterTests.java b/web/src/test/java/org/springframework/security/web/header/writers/HstsHeaderWriterTests.java index 3e7435e8c3..7c7ab5d68a 100644 --- a/web/src/test/java/org/springframework/security/web/header/writers/HstsHeaderWriterTests.java +++ b/web/src/test/java/org/springframework/security/web/header/writers/HstsHeaderWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 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. @@ -50,7 +50,7 @@ public class HstsHeaderWriterTests { writer.writeHeaders(request, response); - assertThat(response.getHeaderNames().size()).isEqualTo(1); + assertThat(response.getHeaderNames()).hasSize(1); assertThat(response.getHeader("Strict-Transport-Security")).isEqualTo( "max-age=15768000"); } @@ -62,7 +62,7 @@ public class HstsHeaderWriterTests { writer.writeHeaders(request, response); - assertThat(response.getHeaderNames().size()).isEqualTo(1); + assertThat(response.getHeaderNames()).hasSize(1); assertThat(response.getHeader("Strict-Transport-Security")).isEqualTo( "max-age=15768000"); } @@ -73,7 +73,7 @@ public class HstsHeaderWriterTests { writer.writeHeaders(request, response); - assertThat(response.getHeaderNames().size()).isEqualTo(1); + assertThat(response.getHeaderNames()).hasSize(1); assertThat(response.getHeader("Strict-Transport-Security")).isEqualTo( "max-age=15768000 ; includeSubDomains"); } @@ -84,7 +84,7 @@ public class HstsHeaderWriterTests { writer.writeHeaders(request, response); - assertThat(response.getHeaderNames().size()).isEqualTo(1); + assertThat(response.getHeaderNames()).hasSize(1); assertThat(response.getHeader("Strict-Transport-Security")).isEqualTo( "max-age=31536000"); } @@ -93,7 +93,7 @@ public class HstsHeaderWriterTests { public void writeHeadersDefaultValues() { writer.writeHeaders(request, response); - assertThat(response.getHeaderNames().size()).isEqualTo(1); + assertThat(response.getHeaderNames()).hasSize(1); assertThat(response.getHeader("Strict-Transport-Security")).isEqualTo( "max-age=31536000 ; includeSubDomains"); } @@ -104,7 +104,7 @@ public class HstsHeaderWriterTests { writer.writeHeaders(request, response); - assertThat(response.getHeaderNames().size()).isEqualTo(1); + assertThat(response.getHeaderNames()).hasSize(1); assertThat(response.getHeader("Strict-Transport-Security")).isEqualTo( "max-age=31536000"); } @@ -115,7 +115,7 @@ public class HstsHeaderWriterTests { writer.writeHeaders(request, response); - assertThat(response.getHeaderNames().size()).isEqualTo(1); + assertThat(response.getHeaderNames()).hasSize(1); assertThat(response.getHeader("Strict-Transport-Security")).isEqualTo( "max-age=1 ; includeSubDomains"); } @@ -136,7 +136,7 @@ public class HstsHeaderWriterTests { writer.writeHeaders(request, response); - assertThat(response.getHeaderNames().size()).isEqualTo(1); + assertThat(response.getHeaderNames()).hasSize(1); assertThat(response.getHeader("Strict-Transport-Security")).isEqualTo( "max-age=31536000 ; includeSubDomains"); } diff --git a/web/src/test/java/org/springframework/security/web/header/writers/ReferrerPolicyHeaderWriterTests.java b/web/src/test/java/org/springframework/security/web/header/writers/ReferrerPolicyHeaderWriterTests.java index b3332d23d2..d13b80ba49 100644 --- a/web/src/test/java/org/springframework/security/web/header/writers/ReferrerPolicyHeaderWriterTests.java +++ b/web/src/test/java/org/springframework/security/web/header/writers/ReferrerPolicyHeaderWriterTests.java @@ -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. @@ -46,7 +46,7 @@ public class ReferrerPolicyHeaderWriterTests { public void writeHeadersReferrerPolicyDefault() { this.writer.writeHeaders(this.request, this.response); - assertThat(this.response.getHeaderNames().size()).isEqualTo(1); + assertThat(this.response.getHeaderNames()).hasSize(1); assertThat(this.response.getHeader("Referrer-Policy")).isEqualTo(DEFAULT_REFERRER_POLICY); } @@ -56,7 +56,7 @@ public class ReferrerPolicyHeaderWriterTests { this.writer.writeHeaders(this.request, this.response); - assertThat(this.response.getHeaderNames().size()).isEqualTo(1); + assertThat(this.response.getHeaderNames()).hasSize(1); assertThat(this.response.getHeader("Referrer-Policy")).isEqualTo("same-origin"); } diff --git a/web/src/test/java/org/springframework/security/web/header/writers/StaticHeaderWriterTests.java b/web/src/test/java/org/springframework/security/web/header/writers/StaticHeaderWriterTests.java index 1eff6351e2..4cd3d41d40 100644 --- a/web/src/test/java/org/springframework/security/web/header/writers/StaticHeaderWriterTests.java +++ b/web/src/test/java/org/springframework/security/web/header/writers/StaticHeaderWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 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. @@ -90,7 +90,7 @@ public class StaticHeaderWriterTests { factory.writeHeaders(request, response); - assertThat(response.getHeaderNames().size()).isEqualTo(2); + assertThat(response.getHeaderNames()).hasSize(2); assertThat(response.getHeaderValues(pragma.getName())).isEqualTo( pragma.getValues()); assertThat(response.getHeaderValues(cacheControl.getName())).isEqualTo( diff --git a/web/src/test/java/org/springframework/security/web/header/writers/XContentTypeOptionsHeaderWriterTests.java b/web/src/test/java/org/springframework/security/web/header/writers/XContentTypeOptionsHeaderWriterTests.java index 6ad535de72..36424d7aaa 100644 --- a/web/src/test/java/org/springframework/security/web/header/writers/XContentTypeOptionsHeaderWriterTests.java +++ b/web/src/test/java/org/springframework/security/web/header/writers/XContentTypeOptionsHeaderWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 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. @@ -17,8 +17,6 @@ package org.springframework.security.web.header.writers; import static org.assertj.core.api.Assertions.assertThat; -import java.util.Arrays; - import org.junit.Before; import org.junit.Test; import org.springframework.mock.web.MockHttpServletRequest; @@ -47,8 +45,8 @@ public class XContentTypeOptionsHeaderWriterTests { public void writeHeaders() { writer.writeHeaders(request, response); - assertThat(response.getHeaderNames().size()).isEqualTo(1); - assertThat(response.getHeaderValues("X-Content-Type-Options")).isEqualTo( - Arrays.asList("nosniff")); + assertThat(response.getHeaderNames()).hasSize(1); + assertThat(response.getHeaderValues("X-Content-Type-Options")).containsExactly( + "nosniff"); } } diff --git a/web/src/test/java/org/springframework/security/web/header/writers/XXssProtectionHeaderWriterTests.java b/web/src/test/java/org/springframework/security/web/header/writers/XXssProtectionHeaderWriterTests.java index 55b102cb6b..65cf3e352b 100644 --- a/web/src/test/java/org/springframework/security/web/header/writers/XXssProtectionHeaderWriterTests.java +++ b/web/src/test/java/org/springframework/security/web/header/writers/XXssProtectionHeaderWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 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. @@ -17,8 +17,6 @@ package org.springframework.security.web.header.writers; import static org.assertj.core.api.Assertions.assertThat; -import java.util.Arrays; - import org.junit.Before; import org.junit.Test; import org.springframework.mock.web.MockHttpServletRequest; @@ -47,9 +45,8 @@ public class XXssProtectionHeaderWriterTests { public void writeHeaders() { writer.writeHeaders(request, response); - assertThat(response.getHeaderNames().size()).isEqualTo(1); - assertThat(response.getHeaderValues("X-XSS-Protection")).isEqualTo( - Arrays.asList("1; mode=block")); + assertThat(response.getHeaderNames()).hasSize(1); + assertThat(response.getHeaderValues("X-XSS-Protection")).containsOnly("1; mode=block"); } @Test @@ -58,9 +55,8 @@ public class XXssProtectionHeaderWriterTests { writer.writeHeaders(request, response); - assertThat(response.getHeaderNames().size()).isEqualTo(1); - assertThat(response.getHeaderValues("X-XSS-Protection")).isEqualTo( - Arrays.asList("1")); + assertThat(response.getHeaderNames()).hasSize(1); + assertThat(response.getHeaderValues("X-XSS-Protection")).containsOnly("1"); } @Test @@ -70,9 +66,8 @@ public class XXssProtectionHeaderWriterTests { writer.writeHeaders(request, response); - assertThat(response.getHeaderNames().size()).isEqualTo(1); - assertThat(response.getHeaderValues("X-XSS-Protection")).isEqualTo( - Arrays.asList("0")); + assertThat(response.getHeaderNames()).hasSize(1); + assertThat(response.getHeaderValues("X-XSS-Protection")).containsOnly("0"); } @Test @@ -81,9 +76,8 @@ public class XXssProtectionHeaderWriterTests { writer.writeHeaders(request, response); - assertThat(response.getHeaderNames().size()).isEqualTo(1); - assertThat(response.getHeaderValues("X-XSS-Protection")).isEqualTo( - Arrays.asList("0")); + assertThat(response.getHeaderNames()).hasSize(1); + assertThat(response.getHeaderValues("X-XSS-Protection")).containsOnly("0"); } @Test(expected = IllegalArgumentException.class) diff --git a/web/src/test/java/org/springframework/security/web/header/writers/frameoptions/FrameOptionsHeaderWriterTests.java b/web/src/test/java/org/springframework/security/web/header/writers/frameoptions/FrameOptionsHeaderWriterTests.java index d5696743a2..e501287217 100644 --- a/web/src/test/java/org/springframework/security/web/header/writers/frameoptions/FrameOptionsHeaderWriterTests.java +++ b/web/src/test/java/org/springframework/security/web/header/writers/frameoptions/FrameOptionsHeaderWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 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. @@ -82,7 +82,7 @@ public class FrameOptionsHeaderWriterTests { writer.writeHeaders(request, response); - assertThat(response.getHeaderNames().size()).isEqualTo(1); + assertThat(response.getHeaderNames()).hasSize(1); assertThat(response.getHeader(XFrameOptionsHeaderWriter.XFRAME_OPTIONS_HEADER)) .isEqualTo("ALLOW-FROM " + allowFromValue); } @@ -93,7 +93,7 @@ public class FrameOptionsHeaderWriterTests { writer.writeHeaders(request, response); - assertThat(response.getHeaderNames().size()).isEqualTo(1); + assertThat(response.getHeaderNames()).hasSize(1); assertThat(response.getHeader(XFrameOptionsHeaderWriter.XFRAME_OPTIONS_HEADER)) .isEqualTo("DENY"); } @@ -104,7 +104,7 @@ public class FrameOptionsHeaderWriterTests { writer.writeHeaders(request, response); - assertThat(response.getHeaderNames().size()).isEqualTo(1); + assertThat(response.getHeaderNames()).hasSize(1); assertThat(response.getHeader(XFrameOptionsHeaderWriter.XFRAME_OPTIONS_HEADER)) .isEqualTo("SAMEORIGIN"); } @@ -117,7 +117,7 @@ public class FrameOptionsHeaderWriterTests { writer = new XFrameOptionsHeaderWriter(XFrameOptionsMode.DENY); writer.writeHeaders(request, response); - assertThat(response.getHeaderNames().size()).isEqualTo(1); + assertThat(response.getHeaderNames()).hasSize(1); assertThat(response.getHeader(XFrameOptionsHeaderWriter.XFRAME_OPTIONS_HEADER)) .isEqualTo("DENY"); } diff --git a/web/src/test/java/org/springframework/security/web/savedrequest/SavedRequestAwareWrapperTests.java b/web/src/test/java/org/springframework/security/web/savedrequest/SavedRequestAwareWrapperTests.java index 6b73def2b2..604489270a 100644 --- a/web/src/test/java/org/springframework/security/web/savedrequest/SavedRequestAwareWrapperTests.java +++ b/web/src/test/java/org/springframework/security/web/savedrequest/SavedRequestAwareWrapperTests.java @@ -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. @@ -48,7 +48,7 @@ public class SavedRequestAwareWrapperTests { MockHttpServletRequest savedRequest = new MockHttpServletRequest(); savedRequest.setCookies(new Cookie[] { new Cookie("cookie", "fromsaved") }); SavedRequestAwareWrapper wrapper = createWrapper(savedRequest, newRequest); - assertThat(wrapper.getCookies().length).isEqualTo(1); + assertThat(wrapper.getCookies()).hasSize(1); assertThat(wrapper.getCookies()[0].getValue()).isEqualTo("fromnew"); } @@ -89,7 +89,7 @@ public class SavedRequestAwareWrapperTests { wrappedRequest.setParameter("action", "bar"); assertThat(wrapper.getParameter("action")).isEqualTo("bar"); // Both values should be set, but "bar" should be first - assertThat(wrapper.getParameterValues("action").length).isEqualTo(2); + assertThat(wrapper.getParameterValues("action")).hasSize(2); assertThat(wrapper.getParameterValues("action")[0]).isEqualTo("bar"); } @@ -100,9 +100,9 @@ public class SavedRequestAwareWrapperTests { MockHttpServletRequest wrappedRequest = new MockHttpServletRequest(); wrappedRequest.setParameter("action", "foo"); SavedRequestAwareWrapper wrapper = createWrapper(savedRequest, wrappedRequest); - assertThat(wrapper.getParameterValues("action").length).isEqualTo(1); + assertThat(wrapper.getParameterValues("action")).hasSize(1); assertThat(wrapper.getParameterMap()).hasSize(1); - assertThat(((String[]) wrapper.getParameterMap().get("action")).length).isEqualTo(1); + assertThat(((String[]) wrapper.getParameterMap().get("action"))).hasSize(1); } @Test @@ -135,7 +135,7 @@ public class SavedRequestAwareWrapperTests { assertThat(wrapper.getParameterValues("action")).isEqualTo(new Object[] { "bar", "foo" }); // Check map is consistent String[] valuesFromMap = (String[]) wrapper.getParameterMap().get("action"); - assertThat(valuesFromMap.length).isEqualTo(2); + assertThat(valuesFromMap).hasSize(2); assertThat(valuesFromMap[0]).isEqualTo("bar"); }