1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-12-06 05:01:12 +01:00

sinttest: migrate to JUnit5, drop JUnit4

The before/after class annotations are now no longer borrowed from
JUnit.

Also some integration tests used @After and/or @Before from JUnit,
which was never supported nor had any effected. Those methods got
deleted. But since there appears to be a desire for such a
functionality in sinttest, we should consider adding one.
This commit is contained in:
Florian Schmaus 2020-04-12 21:54:18 +02:00
parent fdeaaf368e
commit e8fef260e6
47 changed files with 248 additions and 221 deletions

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2019 Florian Schmaus
* Copyright 2019-2020 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,15 +16,15 @@
*/
package org.igniterealtime.smack.inttest;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.lang.reflect.Method;
import java.util.List;
import org.jivesoftware.smack.AbstractXMPPConnection;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class SmackIntegrationTestFrameWorkTest {

View file

@ -16,7 +16,7 @@
*/
package org.igniterealtime.smack.inttest;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.lang.reflect.InvocationTargetException;
import java.security.KeyManagementException;
@ -26,7 +26,7 @@ import org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection;
import org.jivesoftware.smack.c2s.ModularXmppClientToServerConnectionConfiguration;
import org.jivesoftware.smack.tcp.XmppTcpTransportModuleDescriptor;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.jxmpp.stringprep.XmppStringprepException;
public class SmackIntegrationTestXmppConnectionManagerTest {

View file

@ -17,10 +17,10 @@
package org.igniterealtime.smack.inttest.unittest;
import static org.igniterealtime.smack.inttest.SmackIntegrationTestUnitTestUtil.getFrameworkForUnitTest;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
@ -38,25 +38,27 @@ import org.jivesoftware.smack.packet.StanzaError;
import org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest;
import org.igniterealtime.smack.inttest.DummySmackIntegrationTestFramework;
import org.igniterealtime.smack.inttest.FailedTest;
import org.igniterealtime.smack.inttest.SmackIntegrationTest;
import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment;
import org.igniterealtime.smack.inttest.SmackIntegrationTestFramework;
import org.igniterealtime.smack.inttest.SmackIntegrationTestFramework.TestRunResult;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.igniterealtime.smack.inttest.annotations.AfterClass;
import org.igniterealtime.smack.inttest.annotations.BeforeClass;
import org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
public class SmackIntegrationTestFrameworkUnitTest {
private static boolean beforeClassInvoked;
private static boolean afterClassInvoked;
@BeforeClass
@BeforeAll
public static void prepareSinttestUnitTest() {
SmackIntegrationTestFramework.SINTTEST_UNIT_TEST = true;
}
@AfterClass
@AfterAll
public static void disallowSinntestUnitTest() {
SmackIntegrationTestFramework.SINTTEST_UNIT_TEST = false;
}
@ -125,8 +127,8 @@ public class SmackIntegrationTestFrameworkUnitTest {
DummySmackIntegrationTestFramework sinttest = getFrameworkForUnitTest(BeforeAfterClassTest.class);
sinttest.run();
assertTrue("A before class method should have been executed to this time", beforeClassInvoked);
assertTrue("A after class method should have been executed to this time", afterClassInvoked);
assertTrue(beforeClassInvoked, "A before class method should have been executed to this time");
assertTrue(afterClassInvoked, "A after class method should have been executed to this time");
}
public static class BeforeAfterClassTest extends AbstractSmackIntegrationTest {
@ -147,8 +149,8 @@ public class SmackIntegrationTestFrameworkUnitTest {
@SmackIntegrationTest
public void test() {
assertTrue("A before class method should have been executed to this time", beforeClassInvoked);
assertFalse("A after class method shouldn't have been executed to this time", afterClassInvoked);
assertTrue(beforeClassInvoked, "A before class method should have been executed to this time");
assertFalse(afterClassInvoked, "A after class method shouldn't have been executed to this time");
}
}
}

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2015 Florian Schmaus
* Copyright 2015-2020 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,14 +16,15 @@
*/
package org.igniterealtime.smack.inttest.util;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import org.jivesoftware.smack.util.Async;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class ResultSyncPointTest {
@ -44,7 +45,7 @@ public class ResultSyncPointTest {
assertEquals(result, receivedResult);
}
@Test(expected = TestException.class)
@Test
public void exceptionTestResultSyncPoint() throws Exception {
final CyclicBarrier barrier = new CyclicBarrier(2);
final ResultSyncPoint<String, TestException> rsp = new ResultSyncPoint<>();
@ -56,7 +57,7 @@ public class ResultSyncPointTest {
}
});
barrier.await();
rsp.waitForResult(60 * 1000);
assertThrows(TestException.class, () -> rsp.waitForResult(60 * 1000));
}
private static class TestException extends Exception {