diff options
-rw-r--r-- | src/net/java/sip/communicator/impl/protocol/irc/ChatRoomIrcImpl.java | 31 | ||||
-rw-r--r-- | test/net/java/sip/communicator/impl/protocol/irc/ChatRoomIrcImplTest.java | 14 |
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) |