19
19
import java .time .Duration ;
20
20
import java .time .Instant ;
21
21
import java .util .Set ;
22
+ import java .util .UUID ;
22
23
23
24
import org .junit .jupiter .api .BeforeEach ;
24
25
import org .junit .jupiter .api .Test ;
@@ -42,6 +43,19 @@ void constructorNullSession() {
42
43
.withMessage ("session cannot be null" );
43
44
}
44
45
46
+ @ Test
47
+ void constructorWhenSessionIdGenerationStrategyThenUsesStrategy () {
48
+ MapSession session = new MapSession (new FixedSessionIdGenerationStrategy ("my-id" ));
49
+ assertThat (session .getId ()).isEqualTo ("my-id" );
50
+ }
51
+
52
+ @ Test
53
+ void constructorWhenDefaultThenUuid () {
54
+ String id = this .session .getId ();
55
+ UUID uuid = UUID .fromString (id );
56
+ assertThat (uuid ).isNotNull ();
57
+ }
58
+
45
59
@ Test
46
60
void getAttributeWhenNullThenNull () {
47
61
String result = this .session .getAttribute ("attrName" );
@@ -143,6 +157,41 @@ void getAttributeNamesAndRemove() {
143
157
assertThat (this .session .getAttributeNames ()).isEmpty ();
144
158
}
145
159
160
+ @ Test
161
+ void changeSessionIdWhenSessionIdStrategyThenUsesStrategy () {
162
+ MapSession session = new MapSession (new IncrementalSessionIdGenerationStrategy ());
163
+ String idBeforeChange = session .getId ();
164
+ String idAfterChange = session .changeSessionId ();
165
+ assertThat (idBeforeChange ).isEqualTo ("1" );
166
+ assertThat (idAfterChange ).isEqualTo ("2" );
167
+ }
168
+
169
+ static class FixedSessionIdGenerationStrategy implements SessionIdGenerationStrategy {
170
+
171
+ private final String id ;
172
+
173
+ FixedSessionIdGenerationStrategy (String id ) {
174
+ this .id = id ;
175
+ }
176
+
177
+ @ Override
178
+ public String generate () {
179
+ return this .id ;
180
+ }
181
+
182
+ }
183
+
184
+ static class IncrementalSessionIdGenerationStrategy implements SessionIdGenerationStrategy {
185
+
186
+ private int counter = 1 ;
187
+
188
+ @ Override
189
+ public String generate () {
190
+ return String .valueOf (this .counter ++);
191
+ }
192
+
193
+ }
194
+
146
195
static class CustomSession implements Session {
147
196
148
197
@ Override
0 commit comments