Commit 1c2d95b8 authored by Adrien Béraud's avatar Adrien Béraud Committed by Sébastien Blin
Browse files

lrc: fix unit tests

Change-Id: I6adb46635c77ebd2d7244caed3a133a38c8597f0
parent ab5d82b8
...@@ -20,12 +20,6 @@ ...@@ -20,12 +20,6 @@
package net.jami.model; package net.jami.model;
import net.jami.model.Contact;
import net.jami.model.Conversation;
import net.jami.model.DataTransfer;
import net.jami.model.TextMessage;
import net.jami.model.Uri;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
...@@ -38,18 +32,18 @@ import static org.junit.Assert.assertEquals; ...@@ -38,18 +32,18 @@ import static org.junit.Assert.assertEquals;
*/ */
public class ConversationTest { public class ConversationTest {
private net.jami.model.Conversation conversation; private Conversation conversation;
@Before @Before
public void setUp() throws Exception { public void setUp() {
Contact contact = new Contact(1L); Contact contact = new Contact(Uri.fromString("jami://test"));
conversation = new net.jami.model.Conversation(contact); conversation = new Conversation("", contact);
} }
@Test @Test
public void init_test() throws Exception { public void init_test() {
Contact contact = new Contact(1L); Contact contact = new Contact(Uri.fromString("jami://test"));
Conversation conversation = new net.jami.model.Conversation(contact); conversation = new Conversation("", contact);
assertEquals(conversation.getContact(), contact); assertEquals(conversation.getContact(), contact);
} }
...@@ -86,7 +80,7 @@ public class ConversationTest { ...@@ -86,7 +80,7 @@ public class ConversationTest {
@Test @Test
public void addHistoryCall() throws Exception { public void addHistoryCall() throws Exception {
int oldSize = conversation.getAggregateHistory().size(); int oldSize = conversation.getAggregateHistory().size();
conversation.addHistoryCall(new HistoryCall()); conversation.addCall(new Call("Coucou", "ring:test", "1", conversation, conversation.getContact(), Call.Direction.INCOMING));
int newSize = conversation.getAggregateHistory().size(); int newSize = conversation.getAggregateHistory().size();
assertEquals(0, oldSize); assertEquals(0, oldSize);
...@@ -96,7 +90,7 @@ public class ConversationTest { ...@@ -96,7 +90,7 @@ public class ConversationTest {
@Test @Test
public void addTextMessage() throws Exception { public void addTextMessage() throws Exception {
int oldSize = conversation.getAggregateHistory().size(); int oldSize = conversation.getAggregateHistory().size();
conversation.addTextMessage(new net.jami.model.TextMessage(true, "Coucou", new net.jami.model.Uri("ring:test"), "1", "Toi")); conversation.addTextMessage(new TextMessage( "Coucou", "ring:test", "1", conversation, "Toi"));
int newSize = conversation.getAggregateHistory().size(); int newSize = conversation.getAggregateHistory().size();
assertEquals(0, oldSize); assertEquals(0, oldSize);
...@@ -150,7 +144,7 @@ public class ConversationTest { ...@@ -150,7 +144,7 @@ public class ConversationTest {
@Test @Test
public void addFileTransfer() throws Exception { public void addFileTransfer() throws Exception {
int oldSize = conversation.getAggregateHistory().size(); int oldSize = conversation.getAggregateHistory().size();
conversation.addFileTransfer(new DataTransfer(1L, "photo.jpg", true, 10L, 0L, "1", "1")); conversation.addFileTransfer(new DataTransfer(1L, "Coucoou", "ring:sfvfv", "photo.jpg", true, 10L, 0L, 0L));
int newSize = conversation.getAggregateHistory().size(); int newSize = conversation.getAggregateHistory().size();
assertEquals(0, oldSize); assertEquals(0, oldSize);
...@@ -174,7 +168,7 @@ public class ConversationTest { ...@@ -174,7 +168,7 @@ public class ConversationTest {
int random = new Random().nextInt(20); int random = new Random().nextInt(20);
for (int i = 0; i < random; i++) { for (int i = 0; i < random; i++) {
conversation.addTextMessage(new TextMessage(true, "Coucou", new Uri("ring:test"), "1", "Toi")); conversation.addTextMessage(new TextMessage( "Coucou", "ring:test", "1", conversation, "Toi"));
} }
int newSize = conversation.getAggregateHistory().size(); int newSize = conversation.getAggregateHistory().size();
......
/*
* Copyright (C) 2004-2021 Savoir-faire Linux Inc.
*
* Author: Pierre Duchemin <pierre.duchemin@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package net.jami.model;
import net.jami.model.TextMessage;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class StatusTest {
@Test
public void fromString_test() throws Exception {
net.jami.model.TextMessage.Status[] values = net.jami.model.TextMessage.Status.values();
for (net.jami.model.TextMessage.Status s : values) {
assertEquals(net.jami.model.TextMessage.Status.fromString(s.name()), s);
}
}
@Test
public void fromString_invalid_test() throws Exception {
net.jami.model.TextMessage.Status status = net.jami.model.TextMessage.Status.fromString("abc");
assertEquals(net.jami.model.TextMessage.Status.UNKNOWN, status);
}
@Test
public void fromString_null_test() throws Exception {
net.jami.model.TextMessage.Status status = net.jami.model.TextMessage.Status.fromString(null);
assertEquals(net.jami.model.TextMessage.Status.UNKNOWN, status);
}
@Test
public void fromInt_test() throws Exception {
for (int i = 0; i < 5; i++) {
net.jami.model.TextMessage.Status status = net.jami.model.TextMessage.Status.fromInt(i);
net.jami.model.TextMessage.Status[] values = net.jami.model.TextMessage.Status.values();
assertEquals(status, values[i]);
}
}
@Test
public void fromInt_invalid_test() throws Exception {
net.jami.model.TextMessage.Status status = net.jami.model.TextMessage.Status.fromInt(-1);
assertEquals(net.jami.model.TextMessage.Status.UNKNOWN, status);
}
@Test
public void toString_test() throws Exception {
TextMessage.Status[] values = net.jami.model.TextMessage.Status.values();
for (net.jami.model.TextMessage.Status s : values) {
assertEquals(s.toString(), s.name());
}
}
}
\ No newline at end of file
...@@ -19,13 +19,14 @@ ...@@ -19,13 +19,14 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
package cx.ring.model; package net.jami.model;
import net.jami.model.Uri; import net.jami.utils.Tuple;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
public class UriTest { public class UriTest {
...@@ -33,35 +34,35 @@ public class UriTest { ...@@ -33,35 +34,35 @@ public class UriTest {
@Test @Test
public void testGoodRawString() { public void testGoodRawString() {
String uri = "ring:1234567890123456789012345678901234567890"; String uri = "ring:1234567890123456789012345678901234567890";
net.jami.model.Uri test = new net.jami.model.Uri(uri); Uri test = Uri.fromString(uri);
assertTrue(test.getRawUriString().contentEquals(uri)); assertTrue(test.getRawUriString().contentEquals(uri));
} }
@Test @Test
public void testBadIPAddress() { public void testBadIPAddress() {
assertFalse(net.jami.model.Uri.isIpAddress("not an ip")); assertFalse(Uri.isIpAddress("not an ip"));
} }
@Test @Test
public void testGoodIPAddress() { public void testGoodIPAddress() {
assertTrue(net.jami.model.Uri.isIpAddress("127.0.0.1")); assertTrue(Uri.isIpAddress("127.0.0.1"));
assertTrue(net.jami.model.Uri.isIpAddress("2001:db8:0:85a3:0:0:ac1f:8001")); assertTrue(Uri.isIpAddress("2001:db8:0:85a3:0:0:ac1f:8001"));
} }
@Test @Test
public void testRingModel() { public void testRingModel() {
String uri = "ring:1234567890123456789012345678901234567890"; String uri = "ring:1234567890123456789012345678901234567890";
net.jami.model.Uri test = new net.jami.model.Uri(uri); Tuple<Uri, String> test = Uri.fromStringWithName(uri);
assertTrue(test.getDisplayName() == null); assertNull(test.second);
assertTrue(test.getScheme().contentEquals("ring:")); assertTrue(test.first.getScheme().contentEquals("ring:"));
assertTrue(test.getUriString().contentEquals("ring:1234567890123456789012345678901234567890")); assertTrue(test.first.getUri().contentEquals("ring:1234567890123456789012345678901234567890"));
} }
@Test @Test
public void testSIPModel() { public void testSIPModel() {
String uri = "100@sipuri"; String uri = "100@sipuri";
net.jami.model.Uri test = new Uri(uri); Uri test = Uri.fromString(uri);
assertTrue(test.getUsername().contentEquals("100")); assertTrue(test.getUsername().contentEquals("100"));
assertTrue(test.getHost().contentEquals("sipuri")); assertTrue(test.getHost().contentEquals("sipuri"));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment