|
48 | 48 | import java.util.TreeSet;
|
49 | 49 | import java.util.logging.Level;
|
50 | 50 | import java.util.logging.Logger;
|
| 51 | +import java.util.stream.Collectors; |
51 | 52 |
|
52 | 53 | import org.jivesoftware.smack.AbstractXMPPConnection;
|
53 | 54 | import org.jivesoftware.smack.ConnectionConfiguration;
|
|
57 | 58 | import org.jivesoftware.smack.SmackException;
|
58 | 59 | import org.jivesoftware.smack.SmackException.NoResponseException;
|
59 | 60 | import org.jivesoftware.smack.SmackException.NotConnectedException;
|
| 61 | +import org.jivesoftware.smack.XMPPConnection; |
60 | 62 | import org.jivesoftware.smack.XMPPException;
|
61 | 63 | import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
62 | 64 | import org.jivesoftware.smack.util.StringUtils;
|
@@ -483,7 +485,13 @@ private void runTests(Set<Class<? extends AbstractSmackIntTest>> classes)
|
483 | 485 | for (Method testMethod : smackIntegrationTestMethods) {
|
484 | 486 | switch (testType) {
|
485 | 487 | case Normal: {
|
486 |
| - ConcreteTest.Executor concreteTestExecutor = () -> testMethod.invoke(test); |
| 488 | + ConcreteTest.Executor concreteTestExecutor = () -> { |
| 489 | + AbstractSmackIntegrationTest abstractTest = (AbstractSmackIntegrationTest) test; |
| 490 | + |
| 491 | + throwIfDisconnectedConnections(abstractTest, testMethod, "Cannot execute test of"); |
| 492 | + testMethod.invoke(test); |
| 493 | + throwIfDisconnectedConnections(abstractTest, testMethod, "There where disconnected connections after executing"); |
| 494 | + }; |
487 | 495 | ConcreteTest concreteTest = new ConcreteTest(testType, testMethod, concreteTestExecutor);
|
488 | 496 | concreteTests.add(concreteTest);
|
489 | 497 | }
|
@@ -1111,4 +1119,12 @@ static TestMethodParameterType determineTestMethodParameterType(Method testMetho
|
1111 | 1119 | return null;
|
1112 | 1120 | }
|
1113 | 1121 |
|
| 1122 | + private static void throwIfDisconnectedConnections(AbstractSmackIntegrationTest abstractTest, Method testMethod, String message) throws IOException { |
| 1123 | + List<XMPPConnection> disconnectedConnections = abstractTest.connections.stream().filter(c -> !c.isConnected()).collect(Collectors.toList()); |
| 1124 | + if (disconnectedConnections.isEmpty()) return; |
| 1125 | + |
| 1126 | + throw new IOException(message + " " + testMethod.getDeclaringClass().getSimpleName() + "." |
| 1127 | + + testMethod.getName() + ", as not all connections are connected. Disconnected connections: " |
| 1128 | + + disconnectedConnections); |
| 1129 | + } |
1114 | 1130 | }
|
0 commit comments