More code clean-up and added tests for new role management approach.

fix-message-formatting
Danny van Heumen 11 years ago
parent 893e84b65d
commit 99fc21c915

@ -41,7 +41,7 @@ public class ChatRoomMemberIrcImpl
* The provider that created us. * The provider that created us.
*/ */
private final ProtocolProviderService parentProvider; private final ProtocolProviderService parentProvider;
/** /**
* Set of active roles. * Set of active roles.
*/ */
@ -61,23 +61,31 @@ public class ChatRoomMemberIrcImpl
* @param chatRoomMemberRole the role that this member has in the * @param chatRoomMemberRole the role that this member has in the
* corresponding chat room * corresponding chat room
*/ */
public ChatRoomMemberIrcImpl(ProtocolProviderService parentProvider, public ChatRoomMemberIrcImpl(final ProtocolProviderService parentProvider,
ChatRoom chatRoom, String contactID, final ChatRoom chatRoom, final String contactID,
ChatRoomMemberRole chatRoomMemberRole) final ChatRoomMemberRole chatRoomMemberRole)
{ {
if (parentProvider == null) if (parentProvider == null)
{
throw new IllegalArgumentException( throw new IllegalArgumentException(
"parent protocol provider cannot be null"); "parent protocol provider cannot be null");
}
this.parentProvider = parentProvider; this.parentProvider = parentProvider;
if (chatRoom == null) if (chatRoom == null)
{
throw new IllegalArgumentException( throw new IllegalArgumentException(
"chat room instance cannot be null"); "chat room instance cannot be null");
}
this.chatRoom = chatRoom; this.chatRoom = chatRoom;
if (contactID == null) if (contactID == null)
{
throw new IllegalArgumentException("contact ID cannot be null"); throw new IllegalArgumentException("contact ID cannot be null");
}
this.contactID = contactID; this.contactID = contactID;
if (chatRoomMemberRole == null) if (chatRoomMemberRole == null)
{
throw new IllegalArgumentException("member role cannot be null"); throw new IllegalArgumentException("member role cannot be null");
}
this.roles.add(chatRoomMemberRole); this.roles.add(chatRoomMemberRole);
} }
@ -131,13 +139,15 @@ public String getName()
/** /**
* Set a new name for this ChatRoomMember. * Set a new name for this ChatRoomMember.
* *
* @param newName * @param newName new name to set for chat room member
*/ */
public void setName(String newName) public void setName(final String newName)
{ {
if (newName == null) if (newName == null)
{
throw new IllegalArgumentException("newName cannot be null"); throw new IllegalArgumentException("newName cannot be null");
}
this.contactID = newName; this.contactID = newName;
} }
@ -157,31 +167,30 @@ public ChatRoomMemberRole getRole()
* *
* @param chatRoomMemberRole the role to be set * @param chatRoomMemberRole the role to be set
*/ */
public void setRole(ChatRoomMemberRole chatRoomMemberRole) public void setRole(final ChatRoomMemberRole chatRoomMemberRole)
{ {
// Ignore explicit set role operations, since we only allow // Ignore explicit set role operations, since we only allow
// modifications from the IRC server. // modifications from the IRC server.
LOGGER.debug("Ignoring request to set role to " LOGGER.debug("Ignoring request to set member role.");
+ chatRoomMemberRole.getRoleName());
return; return;
} }
/** /**
* Add a role. * Add a role.
* *
* @param role the new role * @param role the new role
*/ */
void addRole(ChatRoomMemberRole role) void addRole(final ChatRoomMemberRole role)
{ {
this.roles.add(role); this.roles.add(role);
} }
/** /**
* Remove a role. * Remove a role.
* *
* @param role the revoked role * @param role the revoked role
*/ */
void removeRole(ChatRoomMemberRole role) void removeRole(final ChatRoomMemberRole role)
{ {
this.roles.remove(role); this.roles.remove(role);
} }
@ -226,15 +235,15 @@ public int hashCode()
/** /**
* equality by provider protocol instance and contact ID. * equality by provider protocol instance and contact ID.
* *
* Enables the possibility to check if chat room member is same member in * Enables the possibility to check if chat room member is same member in
* different chat rooms. Values are only reliable for the same connection, * different chat rooms. Values are only reliable for the same connection,
* so also check protocol provider instance. * so also check protocol provider instance.
* *
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public boolean equals(Object obj) public boolean equals(final Object obj)
{ {
if (this == obj) if (this == obj)
return true; return true;

@ -1,9 +1,14 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.irc; package net.java.sip.communicator.impl.protocol.irc;
import org.easymock.*;
import net.java.sip.communicator.service.protocol.*;
import junit.framework.*; import junit.framework.*;
import net.java.sip.communicator.service.protocol.*;
import org.easymock.*;
public class ChatRoomMemberIrcImplTest public class ChatRoomMemberIrcImplTest
extends TestCase extends TestCase
@ -139,19 +144,10 @@ public void testRoleNull()
ChatRoomMemberIrcImpl member = ChatRoomMemberIrcImpl member =
new ChatRoomMemberIrcImpl(provider, chatroom, "user", new ChatRoomMemberIrcImpl(provider, chatroom, "user",
ChatRoomMemberRole.SILENT_MEMBER); ChatRoomMemberRole.SILENT_MEMBER);
Assert.assertSame(ChatRoomMemberRole.SILENT_MEMBER, member.getRole()); member.setRole(null);
try
{
member.setRole(null);
Assert.fail("expected IAE because of null role");
}
catch (IllegalArgumentException e)
{
// this is good
}
} }
public void testRoleChange() public void testRoleUnchange()
{ {
ChatRoom chatroom = EasyMock.createMock(ChatRoom.class); ChatRoom chatroom = EasyMock.createMock(ChatRoom.class);
ProtocolProviderService provider = ProtocolProviderService provider =
@ -160,9 +156,63 @@ public void testRoleChange()
"user", ChatRoomMemberRole.SILENT_MEMBER); "user", ChatRoomMemberRole.SILENT_MEMBER);
Assert.assertSame(ChatRoomMemberRole.SILENT_MEMBER, member.getRole()); Assert.assertSame(ChatRoomMemberRole.SILENT_MEMBER, member.getRole());
member.setRole(ChatRoomMemberRole.ADMINISTRATOR); member.setRole(ChatRoomMemberRole.ADMINISTRATOR);
Assert.assertSame(ChatRoomMemberRole.ADMINISTRATOR, member.getRole()); Assert.assertSame(ChatRoomMemberRole.SILENT_MEMBER, member.getRole());
} }
public void testAddSignificantRole()
{
ChatRoom chatroom = EasyMock.createMock(ChatRoom.class);
ProtocolProviderService provider =
EasyMock.createMock(ProtocolProviderService.class);
ChatRoomMemberIrcImpl member =
new ChatRoomMemberIrcImpl(provider, chatroom, "user",
ChatRoomMemberRole.SILENT_MEMBER);
Assert.assertSame(ChatRoomMemberRole.SILENT_MEMBER, member.getRole());
member.addRole(ChatRoomMemberRole.ADMINISTRATOR);
Assert.assertSame(ChatRoomMemberRole.ADMINISTRATOR, member.getRole());
}
public void testRemoveSignificantRole()
{
ChatRoom chatroom = EasyMock.createMock(ChatRoom.class);
ProtocolProviderService provider =
EasyMock.createMock(ProtocolProviderService.class);
ChatRoomMemberIrcImpl member =
new ChatRoomMemberIrcImpl(provider, chatroom, "user",
ChatRoomMemberRole.SILENT_MEMBER);
member.addRole(ChatRoomMemberRole.ADMINISTRATOR);
Assert.assertSame(ChatRoomMemberRole.ADMINISTRATOR, member.getRole());
member.removeRole(ChatRoomMemberRole.ADMINISTRATOR);
Assert.assertSame(ChatRoomMemberRole.SILENT_MEMBER, member.getRole());
}
public void testAddInsignificantRole()
{
ChatRoom chatroom = EasyMock.createMock(ChatRoom.class);
ProtocolProviderService provider =
EasyMock.createMock(ProtocolProviderService.class);
ChatRoomMemberIrcImpl member =
new ChatRoomMemberIrcImpl(provider, chatroom, "user",
ChatRoomMemberRole.ADMINISTRATOR);
Assert.assertSame(ChatRoomMemberRole.ADMINISTRATOR, member.getRole());
member.addRole(ChatRoomMemberRole.MEMBER);
Assert.assertSame(ChatRoomMemberRole.ADMINISTRATOR, member.getRole());
}
public void testRemoveInsignificantRole()
{
ChatRoom chatroom = EasyMock.createMock(ChatRoom.class);
ProtocolProviderService provider =
EasyMock.createMock(ProtocolProviderService.class);
ChatRoomMemberIrcImpl member =
new ChatRoomMemberIrcImpl(provider, chatroom, "user",
ChatRoomMemberRole.ADMINISTRATOR);
member.addRole(ChatRoomMemberRole.MEMBER);
Assert.assertSame(ChatRoomMemberRole.ADMINISTRATOR, member.getRole());
member.removeRole(ChatRoomMemberRole.MEMBER);
Assert.assertSame(ChatRoomMemberRole.ADMINISTRATOR, member.getRole());
}
public void testGetContact() public void testGetContact()
{ {
ChatRoom chatroom = EasyMock.createMock(ChatRoom.class); ChatRoom chatroom = EasyMock.createMock(ChatRoom.class);

@ -1,3 +1,8 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.irc; package net.java.sip.communicator.impl.protocol.irc;
import junit.framework.*; import junit.framework.*;

@ -1,10 +1,14 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.irc; package net.java.sip.communicator.impl.protocol.irc;
import java.util.*; import java.util.*;
import net.java.sip.communicator.impl.protocol.irc.ModeParser.ModeEntry;
import junit.framework.*; import junit.framework.*;
import net.java.sip.communicator.impl.protocol.irc.ModeParser.ModeEntry;
public class ModeParserTest public class ModeParserTest
extends TestCase extends TestCase

@ -1,7 +1,12 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.irc; package net.java.sip.communicator.impl.protocol.irc;
import net.java.sip.communicator.service.protocol.*;
import junit.framework.*; import junit.framework.*;
import net.java.sip.communicator.service.protocol.*;
public class ModeTest public class ModeTest
extends TestCase extends TestCase

Loading…
Cancel
Save