99import io .github .hikingc .matrixsdk .api .events .content .RoomPowerLevels ;
1010import io .github .hikingc .matrixsdk .api .identifiers .RoomAlias ;
1111import io .github .hikingc .matrixsdk .api .identifiers .RoomID ;
12+ import io .github .hikingc .matrixsdk .api .identifiers .UserID ;
1213import io .github .hikingc .matrixsdk .api .identifiers .Validator ;
1314import io .github .hikingc .matrixsdk .api .rooms .*;
1415import io .github .hikingc .matrixsdk .api .rooms .queries .CreationRoomType ;
1718import io .github .hikingc .matrixsdk .context .DiscoveryResponse ;
1819import java .util .List ;
1920import java .util .Map ;
20-
2121import org .junit .jupiter .api .BeforeAll ;
2222import org .junit .jupiter .api .BeforeEach ;
2323import org .junit .jupiter .api .Test ;
2626class RoomServiceTest {
2727
2828 private static final RoomID ROOM_ID = RoomID .parse ("!ekkTuJPNWnbuCJHvYB:kde.org" );
29+ private static final UserID USER_ID = UserID .parse ("@example:example.com" );
2930 private static final String AUTH_TOKEN = "1234" ;
3031 private static MatrixClient client ;
3132 private static DiscoveryResponse DISCOVERY_RESPONSE ;
@@ -116,51 +117,40 @@ void sendCreateRequest_WithACorrectPayload_thenReturnARoomId() {
116117 { "room_id": "%s" }
117118 """
118119 .formatted (expectedRoomId ))));
119- InitialRoomConfiguration config = new InitialRoomConfiguration (
120+ InitialRoomConfiguration config =
121+ new InitialRoomConfiguration (
120122 new InitialRoomConfiguration .CreationContent (false ), // m.federate: false
121123 List .of (
122- new InitialRoomConfiguration .StateEvent (
123- Map .of ("join_rule" , "public" ),
124- "" ,
125- "m.room.join_rules" ),
126- new InitialRoomConfiguration .StateEvent (
127- Map .of ("history_visibility" , "shared" ),
128- "" ,
129- "m.room.history_visibility" )
130- ),
124+ new InitialRoomConfiguration .StateEvent (
125+ Map .of ("join_rule" , "public" ), "" , "m.room.join_rules" ),
126+ new InitialRoomConfiguration .StateEvent (
127+ Map .of ("history_visibility" , "shared" ), "" , "m.room.history_visibility" )),
131128 List .of ("@alice:example.com" , "@bob:example.com" ),
132129 List .of (
133- new InitialRoomConfiguration .Invite3pid (
134- "alice@example.com" ,
135- "abc123_OpaqueString" ,
136- "identity.example.com" ,
137- "email" )
138- ),
130+ new InitialRoomConfiguration .Invite3pid (
131+ "alice@example.com" , "abc123_OpaqueString" , "identity.example.com" , "email" )),
139132 false , // is_direct
140133 "The Grand Duke Pub" ,
141134 new RoomPowerLevels (
142- 50 , // ban
143- Map .of (
144- "m.room.name" , 50 ,
145- "m.room.power_levels" , 100
146- ), // events
147- 0 , // eventsDefault
148- 0 , // invite
149- 50 , // kick
150- null , // notifications — not present in source JSON
151- 50 , // redact
152- 50 , // stateDefault
153- Map .of ("@alice:example.com" , 100 ), // users
154- 0 // users_default
155- ),
135+ 50 , // ban
136+ Map .of (
137+ "m.room.name" , 50 ,
138+ "m.room.power_levels" , 100 ), // events
139+ 0 , // eventsDefault
140+ 0 , // invite
141+ 50 , // kick
142+ null , // notifications — not present in source JSON
143+ 50 , // redact
144+ 50 , // stateDefault
145+ Map .of ("@alice:example.com" , 100 ), // users
146+ 0 // users_default
147+ ),
156148 CreationRoomType .PRIVATE_CHAT ,
157149 "thepub" ,
158150 "11" ,
159151 "All about happy hour" ,
160- VisibilityRoomType .PRIVATE
161- );
162- var response =
163- client .room ().create (config );
152+ VisibilityRoomType .PRIVATE );
153+ var response = client .room ().create (config );
164154 assertEquals (expectedRoomId , response );
165155 }
166156
@@ -209,7 +199,7 @@ void sendResolveAliasRequest_WithCorrectPayload_thenReturnResolvedAlias() {
209199 var response = client .room ().resolveAlias (alias );
210200
211201 assertNotNull (response );
212- assertEquals (ROOM_ID . toString () , response .roomId ());
202+ assertEquals (ROOM_ID , response .roomId ());
213203 assertFalse (response .servers ().isEmpty ());
214204 }
215205
@@ -286,7 +276,8 @@ void sendInviteRequest_WithCorrectPayload_thenHitCorrectEndpoint() {
286276 true ))
287277 .willReturn (okJson ("{}" )));
288278
289- client .room ().inviteUser (ROOM_ID , new RoomMembershipRequest ("Welcome!" , "@alice:example.com" ));
279+ client .room ().inviteUser (
280+ ROOM_ID , new RoomMembershipRequest ("Welcome!" , UserID .parse ("@alice:example.com" )));
290281
291282 verify (postRequestedFor (urlEqualTo ("/_matrix/client/v3/rooms/" + ROOM_ID + "/invite" )));
292283 }
@@ -373,14 +364,14 @@ void sendKickRequest_WithCorrectPayload_thenHitCorrectEndpoint() {
373364 """
374365 {
375366 "reason": "Test reason",
376- "user_id": "user "
367+ "user_id": "@example:example.com "
377368 }
378369 """ ,
379370 true ,
380371 true ))
381372 .willReturn (okJson ("{}" )));
382373
383- client .room ().kick (ROOM_ID , new RoomMembershipRequest ("Test reason" , "user" ));
374+ client .room ().kick (ROOM_ID , new RoomMembershipRequest ("Test reason" , USER_ID ));
384375
385376 verify (postRequestedFor (urlEqualTo ("/_matrix/client/v3/rooms/" + ROOM_ID + "/kick" )));
386377 }
@@ -394,14 +385,14 @@ void sendBanRequest_WithCorrectPayload_thenHitCorrectEndpoint() {
394385 """
395386 {
396387 "reason": "Test reason",
397- "user_id": "user "
388+ "user_id": "@example:example.com "
398389 }
399390 """ ,
400391 true ,
401392 true ))
402393 .willReturn (okJson ("{}" )));
403394
404- client .room ().ban (ROOM_ID , new RoomMembershipRequest ("Test reason" , "user" ));
395+ client .room ().ban (ROOM_ID , new RoomMembershipRequest ("Test reason" , USER_ID ));
405396
406397 verify (postRequestedFor (urlEqualTo ("/_matrix/client/v3/rooms/" + ROOM_ID + "/ban" )));
407398 }
@@ -415,14 +406,14 @@ void sendUnbanRequest_WithCorrectPayload_thenHitCorrectEndpoint() {
415406 """
416407 {
417408 "reason": "Test reason",
418- "user_id": "user "
409+ "user_id": "@example:example.com "
419410 }
420411 """ ,
421412 true ,
422413 true ))
423414 .willReturn (okJson ("{}" )));
424415
425- client .room ().unban (ROOM_ID , new RoomMembershipRequest ("Test reason" , "user" ));
416+ client .room ().unban (ROOM_ID , new RoomMembershipRequest ("Test reason" , USER_ID ));
426417
427418 verify (postRequestedFor (urlEqualTo ("/_matrix/client/v3/rooms/" + ROOM_ID + "/unban" )));
428419 }
@@ -488,7 +479,7 @@ void sendGetPublicRoomDirRequest_WithQueryParams_thenReturnDirectory() {
488479
489480 assertNotNull (response );
490481 assertNotNull (response .chunk ());
491- assertEquals ("!abc123:example.com" , response .chunk ().getFirst ().roomId ());
482+ assertEquals (RoomID . parse ( "!abc123:example.com" ) , response .chunk ().getFirst ().roomId ());
492483 assertEquals ("General" , response .chunk ().getFirst ().name ());
493484 assertEquals (1 , response .totalRoomCountEstimate ());
494485 }
@@ -520,7 +511,7 @@ void sendGetPublicRoomDirPostRequest_WithBody_thenReturnDirectory() {
520511
521512 assertNotNull (response );
522513 assertFalse (response .chunk ().isEmpty ());
523- assertEquals ("!abc123:example.com" , response .chunk ().getFirst ().roomId ());
514+ assertEquals (RoomID . parse ( "!abc123:example.com" ) , response .chunk ().getFirst ().roomId ());
524515 }
525516
526517 @ Test
0 commit comments