17
17
package org .springframework .boot .autoconfigure .session ;
18
18
19
19
import java .util .Collections ;
20
- import java .util .EnumSet ;
21
20
22
21
import javax .servlet .DispatcherType ;
23
22
23
+ import org .assertj .core .api .InstanceOfAssertFactories ;
24
24
import org .junit .jupiter .api .Test ;
25
25
import org .mockito .InOrder ;
26
26
41
41
import org .springframework .session .web .http .HeaderHttpSessionIdResolver ;
42
42
import org .springframework .session .web .http .HttpSessionIdResolver ;
43
43
import org .springframework .session .web .http .SessionRepositoryFilter ;
44
- import org .springframework .test .util .ReflectionTestUtils ;
45
44
46
45
import static org .assertj .core .api .Assertions .assertThat ;
47
46
import static org .mockito .ArgumentMatchers .any ;
@@ -112,13 +111,13 @@ void autoConfigWhenSpringSessionTimeoutIsNotSetShouldUseServerSessionTimeout() {
112
111
.run ((context ) -> assertThat (context .getBean (SessionProperties .class ).getTimeout ()).hasSeconds (3 ));
113
112
}
114
113
115
- @ SuppressWarnings ("unchecked" )
116
114
@ Test
117
115
void filterIsRegisteredWithAsyncErrorAndRequestDispatcherTypes () {
118
116
this .contextRunner .withUserConfiguration (SessionRepositoryConfiguration .class ).run ((context ) -> {
119
117
FilterRegistrationBean <?> registration = context .getBean (FilterRegistrationBean .class );
120
118
assertThat (registration .getFilter ()).isSameAs (context .getBean (SessionRepositoryFilter .class ));
121
- assertThat ((EnumSet <DispatcherType >) ReflectionTestUtils .getField (registration , "dispatcherTypes" ))
119
+ assertThat (registration )
120
+ .extracting ("dispatcherTypes" , InstanceOfAssertFactories .iterable (DispatcherType .class ))
122
121
.containsOnly (DispatcherType .ASYNC , DispatcherType .ERROR , DispatcherType .REQUEST );
123
122
});
124
123
}
@@ -132,25 +131,25 @@ void filterOrderCanBeCustomizedWithCustomStore() {
132
131
});
133
132
}
134
133
135
- @ SuppressWarnings ("unchecked" )
136
134
@ Test
137
135
void filterDispatcherTypesCanBeCustomized () {
138
136
this .contextRunner .withUserConfiguration (SessionRepositoryConfiguration .class )
139
137
.withPropertyValues ("spring.session.servlet.filter-dispatcher-types=error, request" ).run ((context ) -> {
140
138
FilterRegistrationBean <?> registration = context .getBean (FilterRegistrationBean .class );
141
- assertThat ((EnumSet <DispatcherType >) ReflectionTestUtils .getField (registration , "dispatcherTypes" ))
139
+ assertThat (registration )
140
+ .extracting ("dispatcherTypes" , InstanceOfAssertFactories .iterable (DispatcherType .class ))
142
141
.containsOnly (DispatcherType .ERROR , DispatcherType .REQUEST );
143
142
});
144
143
}
145
144
146
- @ SuppressWarnings ("unchecked" )
147
145
@ Test
148
146
void emptyFilterDispatcherTypesDoNotThrowException () {
149
147
this .contextRunner .withUserConfiguration (SessionRepositoryConfiguration .class )
150
148
.withPropertyValues ("spring.session.servlet.filter-dispatcher-types=" ).run ((context ) -> {
151
149
FilterRegistrationBean <?> registration = context .getBean (FilterRegistrationBean .class );
152
- Object dispatcherTypes = ReflectionTestUtils .getField (registration , "dispatcherTypes" );
153
- assertThat ((EnumSet <DispatcherType >) dispatcherTypes ).isEmpty ();
150
+ assertThat (registration )
151
+ .extracting ("dispatcherTypes" , InstanceOfAssertFactories .iterable (DispatcherType .class ))
152
+ .isEmpty ();
154
153
});
155
154
}
156
155
@@ -177,11 +176,8 @@ void autoConfiguredCookieSerializerIsUsedBySessionRepositoryFilter() {
177
176
this .contextRunner .withUserConfiguration (SessionRepositoryConfiguration .class )
178
177
.withPropertyValues ("server.port=0" ).run ((context ) -> {
179
178
SessionRepositoryFilter <?> filter = context .getBean (SessionRepositoryFilter .class );
180
- CookieHttpSessionIdResolver sessionIdResolver = (CookieHttpSessionIdResolver ) ReflectionTestUtils
181
- .getField (filter , "httpSessionIdResolver" );
182
- DefaultCookieSerializer cookieSerializer = (DefaultCookieSerializer ) ReflectionTestUtils
183
- .getField (sessionIdResolver , "cookieSerializer" );
184
- assertThat (cookieSerializer ).isSameAs (context .getBean (DefaultCookieSerializer .class ));
179
+ assertThat (filter ).extracting ("httpSessionIdResolver" ).extracting ("cookieSerializer" )
180
+ .isSameAs (context .getBean (DefaultCookieSerializer .class ));
185
181
});
186
182
}
187
183
0 commit comments