@@ -86,9 +86,9 @@ void test_should_publish_login_event_for_john_with_attribute() {
8686 openAccountConsole ();
8787 submitLoginForm (attributeValueOfJohnDoe , password );
8888 // Then
89- KeycloakEvent loginEvent = awaitLoginEvent (attributeValueOfJohnDoe );
89+ KeycloakEvent loginEvent = awaitLoginEvent (attributeValueOfJohnDoe , "johndoe" );
9090 assertNull (loginEvent .error ());
91- assertEquals (attributeValueOfJohnDoe , loginEvent .details ().get ("username" ));
91+ assertEquals ("johndoe" , loginEvent .details ().get ("username" ));
9292 }
9393
9494 @ Test
@@ -141,7 +141,7 @@ void test_should_publish_reset_event_for_john_with_attribute() {
141141 openForgotPasswordForm ();
142142 submitResetForm (attributeValueOfJohnDoe );
143143 // Then
144- KeycloakEvent resetEvent = awaitResetPasswordEvent (attributeValueOfJohnDoe );
144+ KeycloakEvent resetEvent = awaitResetPasswordEvent (attributeValueOfJohnDoe , "johndoe" );
145145 assertNull (resetEvent .error ());
146146 }
147147
@@ -157,10 +157,10 @@ void test_should_publish_reset_error_for_unknown_attribute() {
157157 assertEquals (attributeValueOfJaneDoe , resetError .details ().get ("username" ));
158158 }
159159
160- private KeycloakEvent awaitLoginEvent (String username ) {
161- return eventsClient .awaitEvent (event -> "LOGIN" . equals (event . type () )
162- && Objects . equals ( username , event .details (). get ( "username" ))
163- && event . error () == null );
160+ private KeycloakEvent awaitLoginEvent (String ... usernames ) {
161+ return eventsClient .awaitEvent (event -> isLoginEvent (event )
162+ && event .error () == null
163+ && matchesUsernamesIfPresent ( event , usernames ) );
164164 }
165165
166166 private KeycloakEvent awaitLoginErrorEvent (String username , String expectedError ) {
@@ -169,10 +169,10 @@ private KeycloakEvent awaitLoginErrorEvent(String username, String expectedError
169169 && Objects .equals (username , event .details ().get ("username" )));
170170 }
171171
172- private KeycloakEvent awaitResetPasswordEvent (String username ) {
172+ private KeycloakEvent awaitResetPasswordEvent (String ... usernames ) {
173173 return eventsClient .awaitEvent (event -> isResetPasswordEvent (event )
174174 && event .error () == null
175- && matchesUsernameIfPresent (event , username ));
175+ && matchesUsernamesIfPresent (event , usernames ));
176176 }
177177
178178 private KeycloakEvent awaitResetPasswordErrorEvent (String username , String expectedError ) {
@@ -182,16 +182,30 @@ private KeycloakEvent awaitResetPasswordErrorEvent(String username, String expec
182182 }
183183
184184 private boolean isResetPasswordEvent (KeycloakEvent event ) {
185- return "SEND_RESET_PASSWORD" .equals (event .type ()) || "RESET_PASSWORD" .equals (event .type ());
185+ return switch (event .type ()) {
186+ case "SEND_RESET_PASSWORD" , "RESET_PASSWORD" , "SEND_RESET_PASSWORD_ERROR" , "RESET_PASSWORD_ERROR" -> true ;
187+ default -> false ;
188+ };
186189 }
187190
188191 private boolean isLoginEvent (KeycloakEvent event ) {
189192 return "LOGIN" .equals (event .type ()) || "LOGIN_ERROR" .equals (event .type ());
190193 }
191194
192- private boolean matchesUsernameIfPresent (KeycloakEvent event , String username ) {
195+ private boolean matchesUsernamesIfPresent (KeycloakEvent event , String ... usernames ) {
193196 String detailUsername = event .details ().get ("username" );
194- return detailUsername == null || Objects .equals (detailUsername , username );
197+ if (detailUsername == null ) {
198+ return true ;
199+ }
200+ if (usernames == null || usernames .length == 0 ) {
201+ return false ;
202+ }
203+ for (String username : usernames ) {
204+ if (username != null && Objects .equals (detailUsername , username )) {
205+ return true ;
206+ }
207+ }
208+ return false ;
195209 }
196210
197211 private void openAccountConsole () {
0 commit comments