Skip to content

Commit ea3dc89

Browse files
committed
sinttest: Remove boilerplate around nickname{One,Two,Three}
Remove the boilerplate around nickname{One,Two,Three} by moving it into AbstractMultiUserChatIntegrationTest. This allows us to drop a lot of lines in MUC related integration tests, reducing the noise in test methods.
1 parent 7907182 commit ea3dc89

File tree

5 files changed

+32
-128
lines changed

5 files changed

+32
-128
lines changed

smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/AbstractMultiUserChatIntegrationTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ public abstract class AbstractMultiUserChatIntegrationTest extends AbstractSmack
5656
final MultiUserChatManager mucManagerThree;
5757
final DomainBareJid mucService;
5858

59+
final Resourcepart nicknameOne = Resourcepart.from("one-" + randomString);
60+
final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
61+
final Resourcepart nicknameThree = Resourcepart.from("three-" + randomString);
62+
5963
public AbstractMultiUserChatIntegrationTest(SmackIntegrationTestEnvironment environment)
6064
throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException,
6165
InterruptedException, TestNotPossibleException, MucAlreadyJoinedException, MissingMucCreationAcknowledgeException, NotAMucServiceException, XmppStringprepException {
@@ -77,7 +81,7 @@ public AbstractMultiUserChatIntegrationTest(SmackIntegrationTestEnvironment envi
7781
EntityBareJid mucAddress = JidCreate.entityBareFrom(Localpart.from(roomNameLocal), service.getDomain());
7882
multiUserChat = mucManagerOne.getMultiUserChat(mucAddress);
7983

80-
createMuc(multiUserChat, "test");
84+
createMuc(multiUserChat, nicknameOne);
8185

8286
needle = service;
8387
break;
@@ -140,6 +144,11 @@ static void createMuc(MultiUserChat muc, Resourcepart resourceName) throws
140144
muc.create(resourceName).makeInstant();
141145
}
142146

147+
/**
148+
* @deprecated use {@link #createMuc(MultiUserChat, Resourcepart)} instead.
149+
*/
150+
@Deprecated
151+
// TODO: Remove in Smack 4.6
143152
static void createMuc(MultiUserChat muc, String nickname) throws
144153
XmppStringprepException, MultiUserChatException.MucAlreadyJoinedException,
145154
XMPPException.XMPPErrorException, SmackException.NotConnectedException,

smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatEntityIntegrationTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public void mucTestForDiscoveringRooms() throws Exception {
130130
public void mucTestForDiscoveringRoomInfo() throws Exception {
131131
EntityBareJid mucAddress = getRandomRoom("discoinfo");
132132
MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
133-
createMuc(mucAsSeenByOne, Resourcepart.from("one-" + randomString));
133+
createMuc(mucAsSeenByOne, nicknameOne);
134134

135135
DiscoverInfo discoInfo;
136136
try {
@@ -157,7 +157,7 @@ public void mucTestForDiscoveringRoomInfo() throws Exception {
157157
public void mucTestForDiscoveringRoomItems() throws Exception {
158158
EntityBareJid mucAddress = getRandomRoom("discoitems");
159159
MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
160-
createMuc(mucAsSeenByOne, Resourcepart.from("one-" + randomString));
160+
createMuc(mucAsSeenByOne, nicknameOne);
161161

162162
DiscoverItems roomItems;
163163
try {
@@ -181,7 +181,6 @@ public void mucTestForDiscoveringRoomItems() throws Exception {
181181
public void mucTestForRejectingDiscoOnRoomOccupantByNonOccupant() throws Exception {
182182
EntityBareJid mucAddress = getRandomRoom("discoitems");
183183
MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
184-
final Resourcepart nicknameOne = Resourcepart.from("one-" + randomString);
185184
createMuc(mucAsSeenByOne, nicknameOne);
186185
final EntityFullJid mucAsSeenByOneUserJid = mucAsSeenByOne.getMyRoomJid();
187186
// Ensure that we do not invoke discoverItems() with null below. This should not happen, as the room JID should

smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatIntegrationTest.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ public void processMessage(Message message) {
7878
}
7979
});
8080

81-
createMuc(mucAsSeenByOne, "one-" + randomString);
82-
mucAsSeenByTwo.join(Resourcepart.from("two-" + randomString));
81+
createMuc(mucAsSeenByOne, nicknameOne);
82+
mucAsSeenByTwo.join(nicknameTwo);
8383
mucAsSeenByOne.sendMessage(mucMessage);
8484

8585
try {
@@ -104,7 +104,7 @@ public void mucDestroyOwnerTest() throws TimeoutException, Exception {
104104
EntityBareJid mucAddress = getRandomRoom("destroy-owner");
105105

106106
MultiUserChat muc = mucManagerOne.getMultiUserChat(mucAddress);
107-
createMuc(muc, Resourcepart.from("one-" + randomString));
107+
createMuc(muc, nicknameOne);
108108

109109
// These would be a test implementation bug, not assertion failure.
110110
if (!mucManagerOne.getJoinedRooms().contains(mucAddress)) {
@@ -152,10 +152,10 @@ public void mucDestroyTestOccupant() throws TimeoutException, Exception {
152152

153153
MultiUserChat mucAsSeenByOwner = mucManagerOne.getMultiUserChat(mucAddress);
154154
MultiUserChat mucAsSeenByParticipant = mucManagerTwo.getMultiUserChat(mucAddress);
155-
createMuc(mucAsSeenByOwner, Resourcepart.from("one-" + randomString));
155+
createMuc(mucAsSeenByOwner, nicknameOne);
156156

157157
// These would be a test implementation bug, not assertion failure.
158-
mucAsSeenByParticipant.join(Resourcepart.from("two-" + randomString));
158+
mucAsSeenByParticipant.join(nicknameTwo);
159159
if (!mucManagerTwo.getJoinedRooms().contains(mucAddress)) {
160160
tryDestroy(mucAsSeenByOwner);
161161
throw new IllegalStateException("Expected user to have joined a room '" + mucAddress + "' (but does not appear to have done so).");
@@ -195,7 +195,7 @@ public void mucNameChangeTest()
195195
EntityBareJid mucAddress = getRandomRoom("muc-name-change");
196196

197197
MultiUserChat muc = mucManagerOne.getMultiUserChat(mucAddress);
198-
createMuc(muc, Resourcepart.from("one-" + randomString));
198+
createMuc(muc, nicknameOne);
199199

200200
final String newRoomName = "New Room Name (" + randomString + ")";
201201

@@ -221,9 +221,6 @@ public void mucTestVisitorNotAllowedToChangeSubject() throws XmppStringprepExcep
221221
final MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
222222
final MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
223223

224-
final Resourcepart nicknameOne = Resourcepart.from("one-" + randomString);
225-
final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
226-
227224
createMuc(mucAsSeenByOne, nicknameOne);
228225
try {
229226
MucConfigFormManager configFormManager = mucAsSeenByOne.getConfigFormManager();
@@ -255,7 +252,6 @@ public void mucTestChangeRoomName() throws XmppStringprepException, MucAlreadyJo
255252
XMPPErrorException, NotConnectedException, InterruptedException, TestNotPossibleException {
256253
final EntityBareJid mucAddress = getRandomRoom("change-room-name");
257254
final MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
258-
final Resourcepart nicknameOne = Resourcepart.from("one-" + randomString);
259255

260256
createMuc(mucAsSeenByOne, nicknameOne);
261257
try {

smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatOccupantIntegrationTest.java

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ public void mucJoinEventOrderingTest() throws Exception {
9292
MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
9393
MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
9494

95-
final Resourcepart nicknameOne = Resourcepart.from("one-" + randomString);
96-
final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
9795
final ResultSyncPoint<String, Exception> subjectResultSyncPoint = new ResultSyncPoint<>();
9896
final List<Stanza> results = new ArrayList<>();
9997
final StanzaListener stanzaListener = stanza -> {
@@ -174,7 +172,7 @@ public void mucSendBeforeJoiningTest() throws Exception {
174172
MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
175173
MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
176174

177-
createMuc(mucAsSeenByOne, "one-" + randomString);
175+
createMuc(mucAsSeenByOne, nicknameOne);
178176
try {
179177
ResultSyncPoint<Message, Exception> errorMessageResultSyncPoint = new ResultSyncPoint<>();
180178
conTwo.addStanzaListener(packet -> errorMessageResultSyncPoint.signal((Message) packet), ForEveryMessage.INSTANCE);
@@ -214,10 +212,6 @@ public void mucJoinPresenceInformationTest() throws Exception {
214212
MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
215213
MultiUserChat mucAsSeenByThree = mucManagerThree.getMultiUserChat(mucAddress);
216214

217-
final Resourcepart nicknameOne = Resourcepart.from("one-" + randomString);
218-
final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
219-
final Resourcepart nicknameThree = Resourcepart.from("three-" + randomString);
220-
221215
createMuc(mucAsSeenByOne, nicknameOne);
222216
try {
223217
SimpleResultSyncPoint oneSeesTwo = new SimpleResultSyncPoint();
@@ -273,10 +267,6 @@ public void mucJoinPresenceBroadcastTest() throws Exception {
273267
MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
274268
MultiUserChat mucAsSeenByThree = mucManagerThree.getMultiUserChat(mucAddress);
275269

276-
final Resourcepart nicknameOne = Resourcepart.from("one-" + randomString);
277-
final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
278-
final Resourcepart nicknameThree = Resourcepart.from("three-" + randomString);
279-
280270
createMuc(mucAsSeenByOne, nicknameOne);
281271
try {
282272
mucAsSeenByTwo.join(nicknameTwo);
@@ -331,9 +321,6 @@ public void mucJoinNonAnonymousRoomTest() throws Exception {
331321
MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
332322
MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
333323

334-
final Resourcepart nicknameOne = Resourcepart.from("one-" + randomString);
335-
final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
336-
337324
createMucNonAnonymous(mucAsSeenByOne, nicknameOne);
338325
try {
339326
final ResultSyncPoint<Presence, ?> participantOneSyncPoint = new ResultSyncPoint<>();
@@ -388,10 +375,6 @@ public void mucJoinSemiAnonymousRoomReceivedByNonModeratorTest() throws Exceptio
388375
MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
389376
MultiUserChat mucAsSeenByThree = mucManagerThree.getMultiUserChat(mucAddress);
390377

391-
final Resourcepart nicknameOne = Resourcepart.from("one-" + randomString);
392-
final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
393-
final Resourcepart nicknameThree = Resourcepart.from("three-" + randomString);
394-
395378
createMucSemiAnonymous(mucAsSeenByOne, nicknameOne);
396379
try {
397380
mucAsSeenByTwo.join(nicknameTwo);
@@ -433,10 +416,6 @@ public void mucJoinSemiAnonymousRoomReceivedByModeratorTest() throws Exception {
433416
MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
434417
MultiUserChat mucAsSeenByThree = mucManagerThree.getMultiUserChat(mucAddress);
435418

436-
final Resourcepart nicknameOne = Resourcepart.from("one-" + randomString);
437-
final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
438-
final Resourcepart nicknameThree = Resourcepart.from("three-" + randomString);
439-
440419
createMucSemiAnonymous(mucAsSeenByOne, nicknameOne);
441420
try {
442421
// Second pass: participant two is now a moderator
@@ -476,9 +455,6 @@ public void mucJoinPasswordProtectedWithoutPasswordRoomTest() throws Exception {
476455
MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
477456
MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
478457

479-
final Resourcepart nicknameOne = Resourcepart.from("one-" + randomString);
480-
final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
481-
482458
final String correctPassword = StringUtils.insecureRandomString(8);
483459

484460
createMuc(mucAsSeenByOne, nicknameOne);
@@ -513,9 +489,6 @@ public void mucJoinPasswordProtectedRoomWrongPasswordTest() throws Exception {
513489
MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
514490
MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
515491

516-
final Resourcepart nicknameOne = Resourcepart.from("one-" + randomString);
517-
final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
518-
519492
final String correctPassword = StringUtils.insecureRandomString(8);
520493

521494
createMuc(mucAsSeenByOne, nicknameOne);
@@ -551,9 +524,6 @@ public void mucJoinPasswordProtectedRoomCorrectPasswordTest() throws Exception {
551524
MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
552525
MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
553526

554-
final Resourcepart nicknameOne = Resourcepart.from("one-" + randomString);
555-
final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
556-
557527
final String correctPassword = StringUtils.insecureRandomString(8);
558528

559529
createMuc(mucAsSeenByOne, nicknameOne);
@@ -594,9 +564,6 @@ public void mucJoinMembersOnlyRoomTest() throws Exception {
594564
MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
595565
MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
596566

597-
final Resourcepart nicknameOne = Resourcepart.from("one-" + randomString);
598-
final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
599-
600567
try {
601568
createMembersOnlyMuc(mucAsSeenByOne, nicknameOne);
602569

@@ -632,9 +599,6 @@ public void mucBannedUserJoinRoomTest() throws Exception {
632599
MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
633600
MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
634601

635-
final Resourcepart nicknameOne = Resourcepart.from("one-" + randomString);
636-
final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
637-
638602
try {
639603
createMuc(mucAsSeenByOne, nicknameOne);
640604

@@ -668,8 +632,6 @@ public void mucNicknameConflictJoinRoomTest() throws Exception {
668632
MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
669633
MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
670634

671-
final Resourcepart nicknameOne = Resourcepart.from("one-" + randomString);
672-
673635
try {
674636
createMuc(mucAsSeenByOne, nicknameOne);
675637

@@ -703,10 +665,6 @@ public void mucMaxUsersLimitJoinRoomTest() throws Exception {
703665
MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
704666
MultiUserChat mucAsSeenByThree = mucManagerThree.getMultiUserChat(mucAddress);
705667

706-
final Resourcepart nicknameOne = Resourcepart.from("one-" + randomString);
707-
final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
708-
final Resourcepart nicknameThree = Resourcepart.from("three-" + randomString);
709-
710668
createMuc(mucAsSeenByOne, nicknameOne);
711669
try {
712670
setMaxUsers(mucAsSeenByOne, 2);
@@ -783,10 +741,6 @@ public void mucMaxUsersLimitAdminCanStillJoinRoomTest() throws Exception {
783741
MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
784742
MultiUserChat mucAsSeenByThree = mucManagerThree.getMultiUserChat(mucAddress);
785743

786-
final Resourcepart nicknameOne = Resourcepart.from("one-" + randomString);
787-
final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
788-
final Resourcepart nicknameThree = Resourcepart.from("three-" + randomString);
789-
790744
createMuc(mucAsSeenByOne, nicknameOne);
791745
try {
792746
setMaxUsers(mucAsSeenByOne, 2);
@@ -835,10 +789,6 @@ public void mucMaxUsersLimitOwnerCanStillJoinRoomTest() throws Exception {
835789
MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
836790
MultiUserChat mucAsSeenByThree = mucManagerThree.getMultiUserChat(mucAddress);
837791

838-
final Resourcepart nicknameOne = Resourcepart.from("one-" + randomString);
839-
final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
840-
final Resourcepart nicknameThree = Resourcepart.from("three-" + randomString);
841-
842792
createMuc(mucAsSeenByOne, nicknameOne);
843793
try {
844794
setMaxUsers(mucAsSeenByOne, 2);
@@ -891,9 +841,6 @@ public void mucJoinLockedRoomTest() throws Exception {
891841
MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
892842
MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
893843

894-
final Resourcepart nicknameOne = Resourcepart.from("one-" + randomString);
895-
final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
896-
897844
// Note the absence of handle.makeInstant() here. The room is still being created at this point, until a
898845
// configuration is set.
899846
mucAsSeenByOne.create(nicknameOne);
@@ -928,9 +875,6 @@ public void mucJoinRoomWithPublicLoggingTest() throws Exception {
928875
final MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
929876
final MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
930877

931-
final Resourcepart nicknameOne = Resourcepart.from("one-" + randomString);
932-
final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
933-
934878
createMuc(mucAsSeenByOne, nicknameOne);
935879

936880
try {
@@ -969,7 +913,6 @@ public void mucChangeNicknameInformationTest() throws Exception {
969913
MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
970914
MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
971915

972-
final Resourcepart nicknameOne = Resourcepart.from("one-" + randomString);
973916
final Resourcepart nicknameTwoOriginal = Resourcepart.from("two-original-" + randomString);
974917
final Resourcepart nicknameTwoNew = Resourcepart.from("two-new-" + randomString);
975918

@@ -1064,7 +1007,6 @@ public void mucBlockChangeNicknameInformationTest() throws Exception {
10641007
MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
10651008
MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
10661009

1067-
final Resourcepart nicknameOne = Resourcepart.from("one-" + randomString);
10681010
final Resourcepart nicknameTwoOriginal = Resourcepart.from("two-original-" + randomString);
10691011

10701012
createMuc(mucAsSeenByOne, nicknameOne);

0 commit comments

Comments
 (0)