1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-25 21:42:07 +01:00

Use assertThrows() in Socks5ByteStreamManagerTest

This commit is contained in:
Florian Schmaus 2019-06-02 11:00:37 +02:00
parent 839e347676
commit 58fc39714f

View file

@ -22,6 +22,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import java.io.IOException;
@ -140,21 +141,18 @@ public class Socks5ByteStreamManagerTest {
final XMPPConnection connection = ConnectionUtils.createMockedConnection(protocol, initiatorJID);
Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
try {
FeatureNotSupportedException e = assertThrows(FeatureNotSupportedException.class, () -> {
// build empty discover info as reply if targets features are queried
DiscoverInfo discoverInfo = new DiscoverInfo();
protocol.addResponse(discoverInfo);
// start SOCKS5 Bytestream
byteStreamManager.establishSession(targetJID);
});
fail("exception should be thrown");
}
catch (FeatureNotSupportedException e) {
assertTrue(e.getFeature().equals("SOCKS5 Bytestream"));
assertTrue(e.getJid().equals(targetJID));
}
}
/**
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if XMPP
@ -196,17 +194,16 @@ public class Socks5ByteStreamManagerTest {
protocol.addResponse(discoverItems, Verification.correspondingSenderReceiver,
Verification.requestTypeGET);
try {
SmackException e = assertThrows(SmackException.class, () -> {
// start SOCKS5 Bytestream
byteStreamManager.establishSession(targetJID, sessionID);
fail("exception should be thrown");
}
catch (SmackException e) {
});
protocol.verifyAll();
assertTrue(e.getMessage().contains("no SOCKS5 proxies available"));
}
}
/**
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if no
@ -261,17 +258,14 @@ public class Socks5ByteStreamManagerTest {
protocol.addResponse(proxyInfo, Verification.correspondingSenderReceiver,
Verification.requestTypeGET);
try {
SmackException e = assertThrows(SmackException.class, () -> {
// start SOCKS5 Bytestream
byteStreamManager.establishSession(targetJID, sessionID);
});
fail("exception should be thrown");
}
catch (SmackException e) {
protocol.verifyAll();
assertTrue(e.getMessage().contains("no SOCKS5 proxies available"));
}
}
/**
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if no
@ -325,16 +319,15 @@ public class Socks5ByteStreamManagerTest {
protocol.addResponse(proxyInfo, Verification.correspondingSenderReceiver,
Verification.requestTypeGET);
try {
SmackException e = assertThrows(SmackException.class, () -> {
// start SOCKS5 Bytestream
byteStreamManager.establishSession(targetJID, sessionID);
fail("exception should be thrown");
}
catch (SmackException e) {
});
protocol.verifyAll();
assertTrue(e.getMessage().contains("no SOCKS5 proxies available"));
}
/* retry to establish SOCKS5 Bytestream */
@ -344,13 +337,10 @@ public class Socks5ByteStreamManagerTest {
protocol.addResponse(discoverItems, Verification.correspondingSenderReceiver,
Verification.requestTypeGET);
try {
e = assertThrows(SmackException.class, () -> {
// start SOCKS5 Bytestream
byteStreamManager.establishSession(targetJID, sessionID);
fail("exception should be thrown");
}
catch (SmackException e) {
});
/*
* #verifyAll() tests if the number of requests and responses corresponds and should
* fail if the invalid proxy is queried again
@ -358,7 +348,6 @@ public class Socks5ByteStreamManagerTest {
protocol.verifyAll();
assertTrue(e.getMessage().contains("no SOCKS5 proxies available"));
}
}
/**
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if the
@ -431,17 +420,14 @@ public class Socks5ByteStreamManagerTest {
protocol.addResponse(rejectPacket, Verification.correspondingSenderReceiver,
Verification.requestTypeSET);
try {
XMPPErrorException e = assertThrows(XMPPErrorException.class, () -> {
// start SOCKS5 Bytestream
byteStreamManager.establishSession(targetJID, sessionID);
});
fail("exception should be thrown");
}
catch (XMPPErrorException e) {
protocol.verifyAll();
assertEquals(rejectPacket.getError(), e.getStanzaError());
}
}
/**
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if the
@ -516,17 +502,14 @@ public class Socks5ByteStreamManagerTest {
protocol.addResponse(streamHostUsedPacket, Verification.correspondingSenderReceiver,
Verification.requestTypeSET);
try {
SmackException e = assertThrows(SmackException.class, () -> {
// start SOCKS5 Bytestream
byteStreamManager.establishSession(targetJID, sessionID);
});
fail("exception should be thrown");
}
catch (SmackException e) {
protocol.verifyAll();
assertTrue(e.getMessage().contains("Remote user responded with unknown host"));
}
}
/**
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if
@ -609,19 +592,16 @@ public class Socks5ByteStreamManagerTest {
}, Verification.correspondingSenderReceiver, Verification.requestTypeSET);
try {
IOException e = assertThrows(IOException.class, () -> {
// start SOCKS5 Bytestream
byteStreamManager.establishSession(targetJID, sessionID);
});
fail("exception should be thrown");
}
catch (IOException e) {
// initiator can't connect to proxy because it is not running
protocol.verifyAll();
Throwable actualCause = e.getCause().getCause();
assertEquals(ConnectException.class, actualCause.getClass());
}
}
/**
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should successfully