aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDanny van Heumen <danny@dannyvanheumen.nl>2014-08-11 22:51:06 +0200
committerDanny van Heumen <danny@dannyvanheumen.nl>2014-08-11 22:51:06 +0200
commiteb8fe613fce57f7728dd2d8e030e2a786371b539 (patch)
tree8f5d4ee5b5cad5612ada6df9cece07e60f68c4f9 /test
parentda4c5dbae7205be8f86fb9fa421ce90e147efbdd (diff)
downloadjitsi-eb8fe613fce57f7728dd2d8e030e2a786371b539.zip
jitsi-eb8fe613fce57f7728dd2d8e030e2a786371b539.tar.gz
jitsi-eb8fe613fce57f7728dd2d8e030e2a786371b539.tar.bz2
Added additional tests.
Diffstat (limited to 'test')
-rw-r--r--test/net/java/sip/communicator/impl/protocol/irc/ChatRoomIrcImplTest.java271
-rw-r--r--test/net/java/sip/communicator/impl/protocol/irc/MessageIrcImplTest.java84
2 files changed, 355 insertions, 0 deletions
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 c745a98..8381e40 100644
--- a/test/net/java/sip/communicator/impl/protocol/irc/ChatRoomIrcImplTest.java
+++ b/test/net/java/sip/communicator/impl/protocol/irc/ChatRoomIrcImplTest.java
@@ -1,8 +1,10 @@
package net.java.sip.communicator.impl.protocol.irc;
+import java.io.*;
import java.util.*;
import junit.framework.*;
+import net.java.sip.communicator.service.protocol.*;
import org.easymock.*;
@@ -160,4 +162,273 @@ public class ChatRoomIrcImplTest
Assert.assertFalse(room.isJoined());
Assert.assertTrue(room.isJoined());
}
+
+ //@Test
+ public void testIsPersistentRoom()
+ {
+ EasyMock.replay(this.providerMock, this.stackMock);
+ ChatRoomIrcImpl room =
+ new ChatRoomIrcImpl("#my-cool-channel", this.providerMock);
+ Assert.assertTrue(room.isPersistent());
+ }
+
+ //@Test
+ public void testDestroyRoom()
+ {
+ EasyMock.replay(this.providerMock, this.stackMock);
+ ChatRoomIrcImpl room =
+ new ChatRoomIrcImpl("#my-cool-channel", this.providerMock);
+ Assert.assertTrue(room.destroy("whatever", null));
+ }
+
+ //@Test
+ public void testSetLocalUserNull()
+ {
+ EasyMock.replay(this.providerMock, this.stackMock);
+ ChatRoomIrcImpl room =
+ new ChatRoomIrcImpl("#my-cool-channel", this.providerMock);
+ try
+ {
+ room.setLocalUser(null);
+ Assert.fail("Should have failed with IAE.");
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ }
+
+ //@Test
+ public void testSetLocalUser()
+ {
+ EasyMock.replay(this.providerMock, this.stackMock);
+ ChatRoomIrcImpl room =
+ new ChatRoomIrcImpl("#my-cool-channel", this.providerMock);
+ Assert.assertEquals(ChatRoomMemberRole.SILENT_MEMBER,
+ room.getUserRole());
+
+ ChatRoomMemberIrcImpl user =
+ EasyMock.createMock(ChatRoomMemberIrcImpl.class);
+ EasyMock.expect(user.getRole())
+ .andReturn(ChatRoomMemberRole.ADMINISTRATOR)
+ .andReturn(ChatRoomMemberRole.MEMBER);
+ EasyMock.replay(user);
+ room.setLocalUser(user);
+ Assert.assertEquals(ChatRoomMemberRole.ADMINISTRATOR,
+ room.getUserRole());
+ // simulate changing user role by returning a different value the second
+ // time
+ Assert.assertEquals(ChatRoomMemberRole.MEMBER, room.getUserRole());
+ }
+
+ //@Test
+ public void testMemberCount()
+ {
+ ChatRoomMemberIrcImpl user =
+ EasyMock.createMock(ChatRoomMemberIrcImpl.class);
+ EasyMock.replay(this.providerMock, this.stackMock, user);
+ ChatRoomIrcImpl room =
+ new ChatRoomIrcImpl("#my-cool-channel", this.providerMock);
+ Assert.assertEquals(0, room.getMembersCount());
+
+ // add a user
+ room.addChatRoomMember("user", user);
+ Assert.assertEquals(1, room.getMembersCount());
+
+ room.clearChatRoomMemberList();
+ Assert.assertEquals(0, room.getMembersCount());
+ }
+
+ //@Test
+ public void testAddMember()
+ {
+ ChatRoomMemberIrcImpl user =
+ EasyMock.createMock(ChatRoomMemberIrcImpl.class);
+ EasyMock.replay(this.providerMock, this.stackMock, user);
+ ChatRoomIrcImpl room =
+ new ChatRoomIrcImpl("#my-cool-channel", this.providerMock);
+ Assert.assertNull(room.getChatRoomMember("user"));
+
+ // add a user
+ room.addChatRoomMember("user", user);
+ Assert.assertSame(user, room.getChatRoomMember("user"));
+ }
+
+ //@Test
+ public void testRemoveMember()
+ {
+ ChatRoomMemberIrcImpl user =
+ EasyMock.createMock(ChatRoomMemberIrcImpl.class);
+ EasyMock.replay(this.providerMock, this.stackMock, user);
+ ChatRoomIrcImpl room =
+ new ChatRoomIrcImpl("#my-cool-channel", this.providerMock);
+ room.addChatRoomMember("user", user);
+ Assert.assertSame(user, room.getChatRoomMember("user"));
+
+ // remove a user
+ room.removeChatRoomMember("user");
+ Assert.assertNull(room.getChatRoomMember("user"));
+ }
+
+ //@Test
+ public void testEqualsSame()
+ {
+ EasyMock.replay(this.providerMock, this.stackMock);
+ ChatRoomIrcImpl room =
+ new ChatRoomIrcImpl("#my-cool-channel", this.providerMock);
+ Assert.assertTrue(room.equals(room));
+ }
+
+ //@Test
+ public void testEqualsNull()
+ {
+ EasyMock.replay(this.providerMock, this.stackMock);
+ ChatRoomIrcImpl room =
+ new ChatRoomIrcImpl("#my-cool-channel", this.providerMock);
+ Assert.assertFalse(room.equals(null));
+ }
+
+ //@Test
+ public void testEqualsOtherClassInstance()
+ {
+ EasyMock.replay(this.providerMock, this.stackMock);
+ ChatRoomIrcImpl room =
+ new ChatRoomIrcImpl("#my-cool-channel", this.providerMock);
+ Assert.assertFalse(room.equals(new Object()));
+ }
+
+ //@Test
+ public void testEqualsOtherProviderInstance()
+ {
+ ProtocolProviderServiceIrcImpl providerMock2 =
+ EasyMock.createMock(ProtocolProviderServiceIrcImpl.class);
+ EasyMock.expect(providerMock2.getIrcStack()).andReturn(this.stackMock);
+ EasyMock.expect(this.stackMock.getChannelTypes()).andReturn(
+ Collections.unmodifiableSet(Sets.newHashSet('#', '$')));
+ EasyMock.replay(this.providerMock, this.stackMock, providerMock2);
+ ChatRoomIrcImpl room =
+ new ChatRoomIrcImpl("#my-cool-channel", this.providerMock);
+ ChatRoomIrcImpl room2 =
+ new ChatRoomIrcImpl("#my-cool-channel", providerMock2);
+ Assert.assertFalse(room.equals(room2));
+ }
+
+ //@Test
+ public void testEqualsOtherRoomInstance()
+ {
+ EasyMock.expect(this.providerMock.getIrcStack()).andReturn(stackMock);
+ EasyMock.expect(this.stackMock.getChannelTypes()).andReturn(
+ Collections.unmodifiableSet(Sets.newHashSet('#', '$')));
+ EasyMock.replay(this.providerMock, this.stackMock);
+ ChatRoomIrcImpl room =
+ new ChatRoomIrcImpl("#my-cool-channel", this.providerMock);
+ ChatRoomIrcImpl room2 =
+ new ChatRoomIrcImpl("#my-cool-channel-2", this.providerMock);
+ Assert.assertFalse(room.equals(room2));
+ }
+
+ //@Test
+ public void testEqualsSameRoomRepresentation()
+ {
+ EasyMock.expect(this.providerMock.getIrcStack()).andReturn(stackMock);
+ EasyMock.expect(this.stackMock.getChannelTypes()).andReturn(
+ Collections.unmodifiableSet(Sets.newHashSet('#', '$')));
+ EasyMock.replay(this.providerMock, this.stackMock);
+ ChatRoomIrcImpl room =
+ new ChatRoomIrcImpl("#my-cool-channel", this.providerMock);
+ ChatRoomIrcImpl room2 =
+ new ChatRoomIrcImpl("#my-cool-channel", this.providerMock);
+ Assert.assertTrue(room.equals(room2));
+ }
+
+ //@Test
+ public void testGetChatRoomSubject()
+ {
+ EasyMock.replay(this.providerMock, this.stackMock);
+ ChatRoomIrcImpl room =
+ new ChatRoomIrcImpl("#my-cool-channel", this.providerMock);
+ Assert.assertEquals("", room.getSubject());
+ }
+
+ //@Test
+ public void testSetChatRoomSubject() throws OperationFailedException
+ {
+ final String newSubject = "My test subject!";
+ this.stackMock.setSubject(EasyMock.anyObject(ChatRoomIrcImpl.class),
+ EasyMock.eq(newSubject));
+ EasyMock.expectLastCall();
+ EasyMock.expect(this.providerMock.getIrcStack()).andReturn(
+ this.stackMock);
+ this.stackMock.setSubject(EasyMock.anyObject(ChatRoomIrcImpl.class),
+ EasyMock.eq(newSubject));
+ EasyMock.expectLastCall();
+ EasyMock.replay(this.providerMock, this.stackMock);
+ ChatRoomIrcImpl room =
+ new ChatRoomIrcImpl("#my-cool-channel", this.providerMock);
+
+ // set a subject
+ Assert.assertEquals("", room.getSubject());
+ room.setSubject(newSubject);
+ // setting subject happens as a result of server accepting topic change,
+ // so it should not change immediately
+ Assert.assertEquals("", room.getSubject());
+ }
+
+ // @Test(expected = OperationFailedException.class)
+ public void testSetChatRoomSubjectFailedByIndirectIOException()
+ throws OperationFailedException
+ {
+ final String newSubject = "My test subject!";
+ this.stackMock.setSubject(EasyMock.anyObject(ChatRoomIrcImpl.class),
+ EasyMock.eq(newSubject));
+ EasyMock.expectLastCall().andThrow(
+ new RuntimeException("Some error", new IOException("Real cause")));
+ EasyMock.expect(this.providerMock.getIrcStack()).andReturn(
+ this.stackMock);
+ this.stackMock.setSubject(EasyMock.anyObject(ChatRoomIrcImpl.class),
+ EasyMock.eq(newSubject));
+ EasyMock.expectLastCall();
+ EasyMock.replay(this.providerMock, this.stackMock);
+ ChatRoomIrcImpl room =
+ new ChatRoomIrcImpl("#my-cool-channel", this.providerMock);
+
+ // set a subject
+ Assert.assertEquals("", room.getSubject());
+ try
+ {
+ room.setSubject(newSubject);
+ Assert.fail("Should have failed with OFE.");
+ }
+ catch (OperationFailedException e)
+ {
+ }
+ }
+
+ // @Test(expected = OperationFailedException.class)
+ public void testSetChatRoomSubjectFailedByOtherRuntimeException()
+ throws OperationFailedException
+ {
+ final String newSubject = "My test subject!";
+ this.stackMock.setSubject(EasyMock.anyObject(ChatRoomIrcImpl.class),
+ EasyMock.eq(newSubject));
+ EasyMock.expectLastCall().andThrow(new RuntimeException("Some error"));
+ EasyMock.expect(this.providerMock.getIrcStack()).andReturn(
+ this.stackMock);
+ this.stackMock.setSubject(EasyMock.anyObject(ChatRoomIrcImpl.class),
+ EasyMock.eq(newSubject));
+ EasyMock.expectLastCall();
+ EasyMock.replay(this.providerMock, this.stackMock);
+ ChatRoomIrcImpl room =
+ new ChatRoomIrcImpl("#my-cool-channel", this.providerMock);
+
+ // set a subject
+ Assert.assertEquals("", room.getSubject());
+ try
+ {
+ room.setSubject(newSubject);
+ Assert.fail("Should have failed with OFE.");
+ }
+ catch (OperationFailedException e)
+ {
+ }
+ }
}
diff --git a/test/net/java/sip/communicator/impl/protocol/irc/MessageIrcImplTest.java b/test/net/java/sip/communicator/impl/protocol/irc/MessageIrcImplTest.java
index 44e9987..02eabd2 100644
--- a/test/net/java/sip/communicator/impl/protocol/irc/MessageIrcImplTest.java
+++ b/test/net/java/sip/communicator/impl/protocol/irc/MessageIrcImplTest.java
@@ -2,6 +2,8 @@ package net.java.sip.communicator.impl.protocol.irc;
import junit.framework.*;
+import org.easymock.*;
+
public class MessageIrcImplTest
extends TestCase
{
@@ -46,4 +48,86 @@ public class MessageIrcImplTest
Assert.assertFalse(message.isAction());
Assert.assertTrue(message.isCommand());
}
+
+ public void testNewMessageFromIRC()
+ {
+ MessageIrcImpl message =
+ MessageIrcImpl.newMessageFromIRC("Hello world.");
+ Assert.assertEquals("Hello world.", message.getContent());
+ Assert.assertEquals(MessageIrcImpl.HTML_MIME_TYPE,
+ message.getContentType());
+ Assert.assertEquals(MessageIrcImpl.DEFAULT_MIME_ENCODING,
+ message.getEncoding());
+ Assert.assertNull(message.getSubject());
+ }
+
+ public void testNewActionFromIRC()
+ {
+ final String text = "Hello world.";
+
+ // Test with chat room member.
+ ChatRoomMemberIrcImpl chatRoomMember =
+ EasyMock.createMock(ChatRoomMemberIrcImpl.class);
+ EasyMock.expect(chatRoomMember.getContactAddress())
+ .andReturn("IamUser");
+ EasyMock.replay(chatRoomMember);
+ MessageIrcImpl message =
+ MessageIrcImpl.newActionFromIRC(chatRoomMember, text);
+ Assert.assertEquals(Utils.styleAsAction(text, "IamUser"),
+ message.getContent());
+ Assert.assertEquals(MessageIrcImpl.HTML_MIME_TYPE,
+ message.getContentType());
+ Assert.assertEquals(MessageIrcImpl.DEFAULT_MIME_ENCODING,
+ message.getEncoding());
+ Assert.assertNull(message.getSubject());
+
+ // Test with contact.
+ ContactIrcImpl contact = EasyMock.createMock(ContactIrcImpl.class);
+ EasyMock.expect(contact.getAddress()).andReturn("IamUser");
+ EasyMock.replay(contact);
+ message = MessageIrcImpl.newActionFromIRC(contact, text);
+ Assert.assertEquals(Utils.styleAsAction(text, "IamUser"),
+ message.getContent());
+ Assert.assertEquals(MessageIrcImpl.HTML_MIME_TYPE,
+ message.getContentType());
+ Assert.assertEquals(MessageIrcImpl.DEFAULT_MIME_ENCODING,
+ message.getEncoding());
+ Assert.assertNull(message.getSubject());
+
+ }
+
+ public void testNewNoticeFromIRC()
+ {
+ final String text = "Hello world.";
+
+ // Test with chat room member.
+ ChatRoomMemberIrcImpl chatRoomMember =
+ EasyMock.createMock(ChatRoomMemberIrcImpl.class);
+ EasyMock.expect(chatRoomMember.getContactAddress())
+ .andReturn("IamUser");
+ EasyMock.replay(chatRoomMember);
+ MessageIrcImpl message =
+ MessageIrcImpl.newNoticeFromIRC(chatRoomMember, text);
+ Assert.assertEquals(Utils.styleAsNotice(text, "IamUser"),
+ message.getContent());
+ Assert.assertEquals(MessageIrcImpl.HTML_MIME_TYPE,
+ message.getContentType());
+ Assert.assertEquals(MessageIrcImpl.DEFAULT_MIME_ENCODING,
+ message.getEncoding());
+ Assert.assertNull(message.getSubject());
+
+ // Test with contact.
+ ContactIrcImpl contact = EasyMock.createMock(ContactIrcImpl.class);
+ EasyMock.expect(contact.getAddress()).andReturn("IamUser");
+ EasyMock.replay(contact);
+ message = MessageIrcImpl.newNoticeFromIRC(contact, text);
+ Assert.assertEquals(Utils.styleAsNotice(text, "IamUser"),
+ message.getContent());
+ Assert.assertEquals(MessageIrcImpl.HTML_MIME_TYPE,
+ message.getContentType());
+ Assert.assertEquals(MessageIrcImpl.DEFAULT_MIME_ENCODING,
+ message.getEncoding());
+ Assert.assertNull(message.getSubject());
+
+ }
}