1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-22 14:22:05 +01:00

Reworked some Jingle unit tests to use Junit's "expected="

Also don't use randomString() because then the unit tests also depend
on the correct behavior of it.
This commit is contained in:
Florian Schmaus 2017-06-17 16:08:32 +02:00
parent 2b11074950
commit 08a4ee4eb2
5 changed files with 54 additions and 66 deletions

View file

@ -17,7 +17,6 @@
package org.jivesoftware.smackx.jingle;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.fail;
import org.jivesoftware.smack.test.util.SmackTestSuite;
@ -38,12 +37,10 @@ public class JingleActionTest extends SmackTestSuite {
for (JingleAction a : JingleAction.values()) {
assertEquals(a, JingleAction.fromString(a.toString()));
}
}
try {
JingleAction inexistentAction = JingleAction.fromString("inexistent-action");
fail();
} catch (IllegalArgumentException e) {
// Expected
}
@Test(expected = IllegalArgumentException.class)
public void nonExistendEnumTest() {
JingleAction.fromString("inexistent-action");
}
}

View file

@ -20,7 +20,6 @@ import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertNotSame;
import static junit.framework.TestCase.assertNull;
import static junit.framework.TestCase.fail;
import org.jivesoftware.smack.test.util.SmackTestSuite;
@ -33,25 +32,25 @@ import org.junit.Test;
*/
public class JingleContentTest extends SmackTestSuite {
@Test(expected = NullPointerException.class)
public void emptyBuilderThrowsTest() {
JingleContent.Builder builder = JingleContent.getBuilder();
builder.build();
}
@Test(expected = IllegalArgumentException.class)
public void onlyCreatorBuilderThrowsTest() {
JingleContent.Builder builder = JingleContent.getBuilder();
builder.setCreator(JingleContent.Creator.initiator);
builder.build();
}
@Test
public void parserTest() {
JingleContent.Builder builder = JingleContent.getBuilder();
try {
builder.build();
fail();
} catch (NullPointerException e) {
// Expected
}
builder.setCreator(JingleContent.Creator.initiator);
try {
builder.build();
fail();
} catch (IllegalArgumentException e) {
// Expected
}
builder.setName("A name");
JingleContent content = builder.build();

View file

@ -17,7 +17,6 @@
package org.jivesoftware.smackx.jingle;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.fail;
import org.jivesoftware.smack.test.util.SmackTestSuite;
@ -41,12 +40,10 @@ public class JingleErrorTest extends SmackTestSuite {
assertEquals("<unsupported-info xmlns='urn:xmpp:jingle:errors:1'/>",
JingleError.fromString("unsupported-info").toXML().toString());
assertEquals("unknown-session", JingleError.fromString("unknown-session").getMessage());
}
try {
JingleError.fromString("inexistent-error");
fail();
} catch (IllegalArgumentException e) {
// Expected
}
@Test(expected = IllegalArgumentException.class)
public void illegalArgumentTest() {
JingleError.fromString("inexistent-error");
}
}

View file

@ -17,7 +17,6 @@
package org.jivesoftware.smackx.jingle;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.fail;
import org.jivesoftware.smack.test.util.SmackTestSuite;
@ -66,26 +65,22 @@ public class JingleReasonTest extends SmackTestSuite {
JingleReason.IncompatibleParameters.toXML().toString());
assertEquals("<reason><alternative-session><sid>1234</sid></alternative-session></reason>",
JingleReason.AlternativeSession("1234").toXML().toString());
// Alternative sessionID must not be empty
try {
JingleReason.AlternativeSession("");
fail();
} catch (NullPointerException e) {
// Expected
}
// Alternative sessionID must not be null
try {
JingleReason.AlternativeSession(null);
fail();
} catch (NullPointerException e) {
// Expected
}
}
try {
JingleReason.Reason nonExistent = JingleReason.Reason.fromString("illegal-reason");
fail();
} catch (IllegalArgumentException e) {
// Expected
}
@Test(expected = NullPointerException.class)
public void alternativeSessionEmptyStringTest() {
// Alternative sessionID must not be empty
JingleReason.AlternativeSession("");
}
@Test(expected = NullPointerException.class)
public void alternativeSessionNullStringTest() {
// Alternative sessionID must not be null
JingleReason.AlternativeSession(null);
}
@Test(expected = IllegalArgumentException.class)
public void illegalArgumentTest() {
JingleReason.Reason.fromString("illegal-reason");
}
}

View file

@ -19,10 +19,8 @@ package org.jivesoftware.smackx.jingle;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertTrue;
import static junit.framework.TestCase.fail;
import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.jingle.element.Jingle;
import org.jivesoftware.smackx.jingle.element.JingleAction;
@ -37,25 +35,27 @@ import org.jxmpp.stringprep.XmppStringprepException;
*/
public class JingleTest extends SmackTestSuite {
@Test
public void parserTest() throws XmppStringprepException {
String sessionId = StringUtils.randomString(24);
@Test(expected = IllegalArgumentException.class)
public void emptyBuilderTest() {
Jingle.Builder builder = Jingle.getBuilder();
builder.build();
}
@Test(expected = NullPointerException.class)
public void onlySessionIdBuilderTest() {
String sessionId = "testSessionId";
Jingle.Builder builder = Jingle.getBuilder();
try {
builder.build();
fail();
} catch (IllegalArgumentException e) {
// Expected
}
builder.setSessionId(sessionId);
builder.build();
}
try {
builder.build();
fail();
} catch (NullPointerException e) {
// Expected
}
@Test
public void parserTest() throws XmppStringprepException {
String sessionId = "testSessionId";
Jingle.Builder builder = Jingle.getBuilder();
builder.setSessionId(sessionId);
builder.setAction(JingleAction.session_initiate);
FullJid romeo = JidCreate.fullFrom("romeo@montague.lit/orchard");