aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanny van Heumen <danny@dannyvanheumen.nl>2014-08-14 20:26:12 +0200
committerDanny van Heumen <danny@dannyvanheumen.nl>2014-08-14 20:26:12 +0200
commit985644f830e5e9c11f58e2eb4d9e97396f11c952 (patch)
tree1180c50bbad6b2be6fae8883607fd84d3f7e3f4d
parent262d2bfe1d02c0f47bcdf0e1d16138542d011864 (diff)
downloadjitsi-985644f830e5e9c11f58e2eb4d9e97396f11c952.zip
jitsi-985644f830e5e9c11f58e2eb4d9e97396f11c952.tar.gz
jitsi-985644f830e5e9c11f58e2eb4d9e97396f11c952.tar.bz2
Auto-prefix channel name with # if no valid prefix found.
-rw-r--r--src/net/java/sip/communicator/impl/protocol/irc/ChatRoomIrcImpl.java31
-rw-r--r--test/net/java/sip/communicator/impl/protocol/irc/ChatRoomIrcImplTest.java14
2 files changed, 22 insertions, 23 deletions
diff --git a/src/net/java/sip/communicator/impl/protocol/irc/ChatRoomIrcImpl.java b/src/net/java/sip/communicator/impl/protocol/irc/ChatRoomIrcImpl.java
index 69a7e48..a340b2f 100644
--- a/src/net/java/sip/communicator/impl/protocol/irc/ChatRoomIrcImpl.java
+++ b/src/net/java/sip/communicator/impl/protocol/irc/ChatRoomIrcImpl.java
@@ -152,7 +152,9 @@ public class ChatRoomIrcImpl
throw new IllegalArgumentException(
"chatRoomName cannot be null or empty string");
}
- this.chatRoomName = verifyName(chatRoomName);
+ this.chatRoomName =
+ verifyName(this.parentProvider.getIrcStack().getChannelTypes(),
+ chatRoomName);
this.isSystem = isSystem;
}
@@ -164,24 +166,27 @@ public class ChatRoomIrcImpl
* @throws IllegalArgumentException if name/identifier contains invalid
* characters
*/
- private String verifyName(final String name)
+ private static String verifyName(final Set<Character> channelTypes,
+ final String name)
{
final char prefix = name.charAt(0);
- if (!this.parentProvider.getIrcStack().getChannelTypes()
- .contains(prefix))
+ if (channelTypes.contains(prefix))
{
- throw new IllegalArgumentException("invalid channel prefix: "
- + prefix);
- }
- for (char c : IrcStack.SPECIAL_CHARACTERS)
- {
- if (name.contains("" + c))
+ for (char c : IrcStack.SPECIAL_CHARACTERS)
{
- throw new IllegalArgumentException(
- "chat room identifier contains illegal character: " + c);
+ if (name.contains("" + c))
+ {
+ throw new IllegalArgumentException(
+ "chat room identifier contains illegal character: " + c);
+ }
}
+ return name;
+ }
+ else
+ {
+ LOGGER.trace("Automatically added # channel prefix.");
+ return verifyName(channelTypes, "#" + name);
}
- return name;
}
/**
diff --git a/test/net/java/sip/communicator/impl/protocol/irc/ChatRoomIrcImplTest.java b/test/net/java/sip/communicator/impl/protocol/irc/ChatRoomIrcImplTest.java
index 8381e40..a10c030 100644
--- a/test/net/java/sip/communicator/impl/protocol/irc/ChatRoomIrcImplTest.java
+++ b/test/net/java/sip/communicator/impl/protocol/irc/ChatRoomIrcImplTest.java
@@ -77,18 +77,12 @@ public class ChatRoomIrcImplTest
}
}
- //@Test(expected = IllegalArgumentException.class)
- public void testIllegalNameBadPrefix()
+ //@Test
+ public void testAutoPrefixBadChannelName()
{
EasyMock.replay(this.providerMock, this.stackMock);
- try
- {
- new ChatRoomIrcImpl("!test", this.providerMock);
- fail("Should have failed with IAE.");
- }
- catch (IllegalArgumentException e)
- {
- }
+ ChatRoomIrcImpl room = new ChatRoomIrcImpl("!test", this.providerMock);
+ Assert.assertEquals("#!test", room.getIdentifier());
}
//@Test(expected = IllegalArgumentException.class)