Skip to content

Commit d48b869

Browse files
author
Steve Riesenberg
committed
Fix mockito usage
Issue gh-13810
1 parent d6ff58b commit d48b869

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

config/src/test/resources/org/springframework/security/config/http/CsrfConfigTests-mock-csrf-token-repository.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
2222

2323
<b:bean id="csrfTokenRepository" class="org.mockito.Mockito" factory-method="mock">
24-
<b:constructor-arg value="org.springframework.security.web.csrf.CsrfTokenRepository"/>
25-
<b:constructor-arg value="csrfTokenRepository"/>
24+
<b:constructor-arg value="org.springframework.security.web.csrf.CsrfTokenRepository" type="java.lang.Class"/>
25+
<b:constructor-arg value="csrfTokenRepository" type="java.lang.String"/>
2626
</b:bean>
2727

2828
</b:beans>

config/src/test/resources/org/springframework/security/config/http/CsrfConfigTests-mock-request-matcher.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
2222

2323
<b:bean id="requestMatcher" class="org.mockito.Mockito" factory-method="mock">
24-
<b:constructor-arg value="org.springframework.security.web.util.matcher.RequestMatcher"/>
25-
<b:constructor-arg value="requestMatcher"/>
24+
<b:constructor-arg value="org.springframework.security.web.util.matcher.RequestMatcher" type="java.lang.Class"/>
25+
<b:constructor-arg value="requestMatcher" type="java.lang.String"/>
2626
</b:bean>
2727
</b:beans>

web/src/test/java/org/springframework/security/web/context/AbstractSecurityWebApplicationInitializerTests.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@
1919
import java.util.Collections;
2020
import java.util.EnumSet;
2121
import java.util.EventListener;
22-
import java.util.HashSet;
2322
import java.util.Set;
2423

2524
import jakarta.servlet.DispatcherType;
@@ -316,14 +315,15 @@ public void onStartupWhenDefaultsThenSessionTrackingModes() {
316315
ServletContext context = mock(ServletContext.class);
317316
FilterRegistration.Dynamic registration = mock(FilterRegistration.Dynamic.class);
318317
ArgumentCaptor<DelegatingFilterProxy> proxyCaptor = ArgumentCaptor.forClass(DelegatingFilterProxy.class);
319-
given(context.addFilter(eq("springSecurityFilterChain"), proxyCaptor.capture())).willReturn(registration);
320-
ArgumentCaptor<Set<SessionTrackingMode>> modesCaptor = ArgumentCaptor
321-
.forClass(new HashSet<SessionTrackingMode>() {
322-
}.getClass());
323-
willDoNothing().given(context).setSessionTrackingModes(modesCaptor.capture());
318+
given(context.addFilter(eq("springSecurityFilterChain"), any(DelegatingFilterProxy.class)))
319+
.willReturn(registration);
320+
@SuppressWarnings("unchecked")
321+
ArgumentCaptor<Set<SessionTrackingMode>> modesCaptor = ArgumentCaptor.forClass(Set.class);
324322
new AbstractSecurityWebApplicationInitializer() {
325323
}.onStartup(context);
324+
verify(context).addFilter(eq("springSecurityFilterChain"), proxyCaptor.capture());
326325
assertProxyDefaults(proxyCaptor.getValue());
326+
verify(context).setSessionTrackingModes(modesCaptor.capture());
327327
Set<SessionTrackingMode> modes = modesCaptor.getValue();
328328
assertThat(modes).hasSize(1);
329329
assertThat(modes).containsExactly(SessionTrackingMode.COOKIE);
@@ -334,18 +334,20 @@ public void onStartupWhenSessionTrackingModesConfiguredThenUsed() {
334334
ServletContext context = mock(ServletContext.class);
335335
FilterRegistration.Dynamic registration = mock(FilterRegistration.Dynamic.class);
336336
ArgumentCaptor<DelegatingFilterProxy> proxyCaptor = ArgumentCaptor.forClass(DelegatingFilterProxy.class);
337-
given(context.addFilter(eq("springSecurityFilterChain"), proxyCaptor.capture())).willReturn(registration);
338-
ArgumentCaptor<Set<SessionTrackingMode>> modesCaptor = ArgumentCaptor
339-
.forClass(new HashSet<SessionTrackingMode>() {
340-
}.getClass());
341-
willDoNothing().given(context).setSessionTrackingModes(modesCaptor.capture());
337+
given(context.addFilter(eq("springSecurityFilterChain"), any(DelegatingFilterProxy.class)))
338+
.willReturn(registration);
339+
@SuppressWarnings("unchecked")
340+
ArgumentCaptor<Set<SessionTrackingMode>> modesCaptor = ArgumentCaptor.forClass(Set.class);
341+
willDoNothing().given(context).setSessionTrackingModes(any());
342342
new AbstractSecurityWebApplicationInitializer() {
343343
@Override
344344
public Set<SessionTrackingMode> getSessionTrackingModes() {
345345
return Collections.singleton(SessionTrackingMode.SSL);
346346
}
347347
}.onStartup(context);
348+
verify(context).addFilter(eq("springSecurityFilterChain"), proxyCaptor.capture());
348349
assertProxyDefaults(proxyCaptor.getValue());
350+
verify(context).setSessionTrackingModes(modesCaptor.capture());
349351
Set<SessionTrackingMode> modes = modesCaptor.getValue();
350352
assertThat(modes).hasSize(1);
351353
assertThat(modes).containsExactly(SessionTrackingMode.SSL);

0 commit comments

Comments
 (0)