diff --git a/.travis.yml b/.travis.yml index ad03d90f1..3bfa93892 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ cache: - $HOME/.m2 before_install: - - export GRADLE_VERSION=6.2 + - export GRADLE_VERSION=5.5.1 - wget https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-all.zip - unzip -q gradle-${GRADLE_VERSION}-all.zip - export PATH="$(pwd)/gradle-${GRADLE_VERSION}/bin:$PATH" diff --git a/build.gradle b/build.gradle index 2e9b23ecb..0ae894a8c 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ buildscript { plugins { id 'ru.vyarus.animalsniffer' version '1.5.0' - id 'net.ltgt.errorprone' version '1.1.1' + id 'net.ltgt.errorprone' version '0.8.1' } apply plugin: 'org.kordamp.gradle.markdown' @@ -129,7 +129,7 @@ allprojects { ':smack-omemo-signal', ':smack-openpgp', ].collect { project(it) } - junitVersion = '5.6.0' + junitVersion = '5.4.2' powerMockVersion = '2.0.2' commonsIoVersion = '2.6' } @@ -680,7 +680,7 @@ def getAndroidRuntimeJar() { if (androidJar.isFile()) { return androidJar } else { - throw new Exception("Can't find android.jar for API level ${androidApiLevel}. Please install corresponding SDK platform package") + throw new Exception("Can't find android.jar for $androidApiLevel API. Please install corresponding SDK platform package") } } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/proxy/ProxySocketConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/proxy/ProxySocketConnection.java index 7f31f94dc..aad3cb5bf 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/proxy/ProxySocketConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/proxy/ProxySocketConnection.java @@ -1,6 +1,6 @@ /** * - * Copyright 2015-2019 Florian Schmaus. + * Copyright 2015-2016 Florian Schmaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,16 +21,6 @@ import java.net.Socket; public interface ProxySocketConnection { - /** - * Initiate a connection to the given host on the given port. Note that the caller is responsible for closing the - * socket in case this method throws. - * - * @param socket the socket to use to initiate the connection to the proxy. - * @param host the host to connect to. - * @param port the port to connect to. - * @param timeout the timeout in milliseconds. - * @throws IOException in case an I/O error occurs. - */ void connect(Socket socket, String host, int port, int timeout) throws IOException; diff --git a/smack-core/src/main/java/org/jivesoftware/smack/proxy/Socks4ProxySocketConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/proxy/Socks4ProxySocketConnection.java index a30777a34..2c2658c99 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/proxy/Socks4ProxySocketConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/proxy/Socks4ProxySocketConnection.java @@ -16,8 +16,6 @@ */ package org.jivesoftware.smack.proxy; -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -26,8 +24,6 @@ import java.net.InetSocketAddress; import java.net.Socket; import java.nio.charset.StandardCharsets; -import org.jivesoftware.smack.util.OutputStreamUtil; - /** * Socket factory for socks4 proxy. * @@ -43,17 +39,20 @@ public class Socks4ProxySocketConnection implements ProxySocketConnection { @Override public void connect(Socket socket, String host, int port, int timeout) throws IOException { + InputStream in = null; + OutputStream out = null; String proxy_host = proxy.getProxyAddress(); int proxy_port = proxy.getProxyPort(); String user = proxy.getProxyUsername(); - socket.connect(new InetSocketAddress(proxy_host, proxy_port), timeout); - InputStream in = socket.getInputStream(); - DataInputStream dis = new DataInputStream(in); - OutputStream out = socket.getOutputStream(); + try { + socket.connect(new InetSocketAddress(proxy_host, proxy_port), timeout); + in = socket.getInputStream(); + out = socket.getOutputStream(); + socket.setTcpNoDelay(true); - ByteArrayOutputStream outBuf = new ByteArrayOutputStream(); - byte[] inBuf; + byte[] buf = new byte[1024]; + int index = 0; /* 1) CONNECT @@ -73,22 +72,25 @@ public class Socks4ProxySocketConnection implements ProxySocketConnection { of all zero bits. */ - outBuf.write(4); - outBuf.write(1); + buf[index++] = 4; + buf[index++] = 1; - outBuf.write(port >>> 8); - outBuf.write(port & 0xff); + buf[index++] = (byte) (port >>> 8); + buf[index++] = (byte) (port & 0xff); - InetAddress inetAddress = InetAddress.getByName(proxy_host); - byte[] byteAddress = inetAddress.getAddress(); - outBuf.write(byteAddress); + InetAddress inetAddress = InetAddress.getByName(proxy_host); + byte[] byteAddress = inetAddress.getAddress(); + for (int i = 0; i < byteAddress.length; i++) { + buf[index++] = byteAddress[i]; + } - if (user != null) { - byte[] userBytes = user.getBytes(StandardCharsets.UTF_8); - outBuf.write(userBytes); - } - outBuf.write(0); - OutputStreamUtil.writeResetAndFlush(outBuf, out); + if (user != null) { + byte[] userBytes = user.getBytes(StandardCharsets.UTF_8); + System.arraycopy(userBytes, 0, buf, index, user.length()); + index += user.length(); + } + buf[index++] = 0; + out.write(buf, 0, index); /* The SOCKS server checks to see whether such a request should be granted @@ -117,17 +119,43 @@ public class Socks4ProxySocketConnection implements ProxySocketConnection { The remaining fields are ignored. */ - inBuf = new byte[6]; - dis.readFully(inBuf); - if (inBuf[0] != 0) { - throw new ProxyException(ProxyInfo.ProxyType.SOCKS4, - "server returns VN " + inBuf[0]); + int len = 6; + int s = 0; + while (s < len) { + int i = in.read(buf, s, len - s); + if (i <= 0) { + throw new ProxyException(ProxyInfo.ProxyType.SOCKS4, + "stream is closed"); + } + s += i; + } + if (buf[0] != 0) { + throw new ProxyException(ProxyInfo.ProxyType.SOCKS4, + "server returns VN " + buf[0]); + } + if (buf[1] != 90) { + try { + socket.close(); + } + catch (Exception eee) { + } + String message = "ProxySOCKS4: server returns CD " + buf[1]; + throw new ProxyException(ProxyInfo.ProxyType.SOCKS4, message); + } + byte[] temp = new byte[2]; + in.read(temp, 0, 2); } - if (inBuf[1] != 90) { - String message = "ProxySOCKS4: server returns CD " + inBuf[1]; - throw new ProxyException(ProxyInfo.ProxyType.SOCKS4, message); + catch (RuntimeException e) { + throw e; + } + catch (Exception e) { + try { + socket.close(); + } + catch (Exception eee) { + } + throw new ProxyException(ProxyInfo.ProxyType.SOCKS4, e.toString()); } - inBuf = new byte[2]; - dis.readFully(inBuf); } + } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/proxy/Socks5ProxySocketConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/proxy/Socks5ProxySocketConnection.java index d81f4d65f..3c8a080e6 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/proxy/Socks5ProxySocketConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/proxy/Socks5ProxySocketConnection.java @@ -16,16 +16,15 @@ */ package org.jivesoftware.smack.proxy; -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.InetSocketAddress; import java.net.Socket; import java.nio.charset.StandardCharsets; +import java.util.logging.Logger; -import org.jivesoftware.smack.util.OutputStreamUtil; +import org.jivesoftware.smack.util.CloseableUtil; /** * Socket factory for Socks5 proxy. @@ -33,6 +32,7 @@ import org.jivesoftware.smack.util.OutputStreamUtil; * @author Atul Aggarwal */ public class Socks5ProxySocketConnection implements ProxySocketConnection { + private static final Logger LOGGER = Logger.getLogger(Socks5ProxySocketConnection.class.getName()); private final ProxyInfo proxy; @@ -43,18 +43,22 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection { @Override public void connect(Socket socket, String host, int port, int timeout) throws IOException { + InputStream in = null; + OutputStream out = null; String proxy_host = proxy.getProxyAddress(); int proxy_port = proxy.getProxyPort(); String user = proxy.getProxyUsername(); String passwd = proxy.getProxyPassword(); - socket.connect(new InetSocketAddress(proxy_host, proxy_port), timeout); - InputStream in = socket.getInputStream(); - DataInputStream dis = new DataInputStream(in); - OutputStream out = socket.getOutputStream(); + try { + socket.connect(new InetSocketAddress(proxy_host, proxy_port), timeout); + in = socket.getInputStream(); + out = socket.getOutputStream(); - ByteArrayOutputStream outBuf = new ByteArrayOutputStream(); - byte[] inBuf; + socket.setTcpNoDelay(true); + + byte[] buf = new byte[1024]; + int index = 0; /* +----+----------+----------+ @@ -77,13 +81,13 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection { o X'FF' NO ACCEPTABLE METHODS */ - outBuf.write(5); + buf[index++] = 5; - outBuf.write(2); - outBuf.write(0); // NO AUTHENTICATION REQUIRED - outBuf.write(2); // USERNAME/PASSWORD + buf[index++] = 2; + buf[index++] = 0; // NO AUTHENTICATION REQUIRED + buf[index++] = 2; // USERNAME/PASSWORD - OutputStreamUtil.writeResetAndFlush(outBuf, out); + out.write(buf, 0, index); /* The server selects from one of the methods given in METHODS, and @@ -95,18 +99,17 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection { | 1 | 1 | +----+--------+ */ - inBuf = new byte[2]; - dis.readFully(inBuf); + fill(in, buf, 2); - boolean check = false; - switch (inBuf[1] & 0xff) { - case 0: // NO AUTHENTICATION REQUIRED - check = true; - break; - case 2: // USERNAME/PASSWORD - if (user == null || passwd == null) { + boolean check = false; + switch (buf[1] & 0xff) { + case 0: // NO AUTHENTICATION REQUIRED + check = true; break; - } + case 2: // USERNAME/PASSWORD + if (user == null || passwd == null) { + break; + } /* Once the SOCKS V5 server has started, and the client has selected the @@ -127,16 +130,20 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection { PASSWD field that follows. The PASSWD field contains the password association with the given UNAME. */ - outBuf.write(1); - byte[] userBytes = user.getBytes(StandardCharsets.UTF_8); - OutputStreamUtil.writeByteSafe(outBuf, userBytes.length, "Username to long"); - outBuf.write(userBytes); + index = 0; + buf[index++] = 1; + buf[index++] = (byte) user.length(); + byte[] userBytes = user.getBytes(StandardCharsets.UTF_8); + System.arraycopy(userBytes, 0, buf, index, + user.length()); + index += user.length(); + byte[] passwordBytes = passwd.getBytes(StandardCharsets.UTF_8); + buf[index++] = (byte) passwordBytes.length; + System.arraycopy(passwordBytes, 0, buf, index, + passwd.length()); + index += passwd.length(); - byte[] passwordBytes = passwd.getBytes(StandardCharsets.UTF_8); - OutputStreamUtil.writeByteSafe(outBuf, passwordBytes.length, "Password to long"); - outBuf.write(passwordBytes); - - OutputStreamUtil.writeResetAndFlush(outBuf, out); + out.write(buf, 0, index); /* The server verifies the supplied UNAME and PASSWD, and sends the @@ -152,19 +159,19 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection { `failure' (STATUS value other than X'00') status, it MUST close the connection. */ - inBuf = new byte[2]; - dis.readFully(inBuf); - if (inBuf[1] == 0) { - check = true; - } - break; - default: - } + fill(in, buf, 2); + if (buf[1] == 0) { + check = true; + } + break; + default: + } - if (!check) { - throw new ProxyException(ProxyInfo.ProxyType.SOCKS5, - "fail in SOCKS5 proxy"); - } + if (!check) { + CloseableUtil.maybeClose(socket, LOGGER); + throw new ProxyException(ProxyInfo.ProxyType.SOCKS5, + "fail in SOCKS5 proxy"); + } /* The SOCKS request is formed as follows: @@ -192,19 +199,21 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection { order */ - outBuf.write(5); - outBuf.write(1); // CONNECT - outBuf.write(0); + index = 0; + buf[index++] = 5; + buf[index++] = 1; // CONNECT + buf[index++] = 0; - byte[] hostb = host.getBytes(StandardCharsets.UTF_8); - int len = hostb.length; - outBuf.write(3); // DOMAINNAME - OutputStreamUtil.writeByteSafe(outBuf, len, "Hostname too long"); - outBuf.write(hostb); - outBuf.write(port >>> 8); - outBuf.write(port & 0xff); + byte[] hostb = host.getBytes(StandardCharsets.UTF_8); + int len = hostb.length; + buf[index++] = 3; // DOMAINNAME + buf[index++] = (byte) len; + System.arraycopy(hostb, 0, buf, index, len); + index += len; + buf[index++] = (byte) (port >>> 8); + buf[index++] = (byte) (port & 0xff); - OutputStreamUtil.writeResetAndFlush(outBuf, out); + out.write(buf, 0, index); /* The SOCKS request information is sent by the client as soon as it has @@ -241,33 +250,49 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection { o BND.PORT server bound port in network octet order */ - inBuf = new byte[4]; - dis.readFully(inBuf); + fill(in, buf, 4); - if (inBuf[1] != 0) { - throw new ProxyException(ProxyInfo.ProxyType.SOCKS5, - "server returns " + inBuf[1]); - } + if (buf[1] != 0) { + CloseableUtil.maybeClose(socket, LOGGER); + throw new ProxyException(ProxyInfo.ProxyType.SOCKS5, + "server returns " + buf[1]); + } - final int addressBytes; - // TODO: Use Byte.toUnsignedInt() once Smack's minimum Android SDK level is 26 or higher. - final int atyp = inBuf[3] & 0xff; - switch (atyp) { - case 1: - addressBytes = 4; - break; - case 3: - byte domainnameLengthByte = dis.readByte(); - // TODO: Use Byte.toUnsignedInt() once Smack's minimum Android SDK level is 26 or higher. - addressBytes = domainnameLengthByte & 0xff; - break; - case 4: - addressBytes = 16; - break; - default: - throw new IOException("Unknown ATYP value: " + atyp); + switch (buf[3] & 0xff) { + case 1: + fill(in, buf, 6); + break; + case 3: + fill(in, buf, 1); + fill(in, buf, (buf[0] & 0xff) + 2); + break; + case 4: + fill(in, buf, 18); + break; + default: + } + } + catch (RuntimeException e) { + throw e; + } + catch (Exception e) { + CloseableUtil.maybeClose(socket, LOGGER); + // TODO convert to IOException(e) when minimum Android API level is 9 or higher + throw new IOException(e.getLocalizedMessage()); } - inBuf = new byte[addressBytes + 2]; - dis.readFully(inBuf); } + + private static void fill(InputStream in, byte[] buf, int len) + throws IOException { + int s = 0; + while (s < len) { + int i = in.read(buf, s, len - s); + if (i <= 0) { + throw new ProxyException(ProxyInfo.ProxyType.SOCKS5, "stream " + + "is closed"); + } + s += i; + } + } + } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/OutputStreamUtil.java b/smack-core/src/main/java/org/jivesoftware/smack/util/OutputStreamUtil.java deleted file mode 100644 index 9f27a09a3..000000000 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/OutputStreamUtil.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * - * Copyright 2019 Florian Schmaus - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jivesoftware.smack.util; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.OutputStream; - -public class OutputStreamUtil { - - public static void writeByteSafe(OutputStream outputStream, int i, String message) throws IOException { - if (i < 0 || i > 0xff) { - throw new IOException(message + ". The value " + i + " is not within the allowed range for bytes"); - } - outputStream.write(i); - } - - public static void writeResetAndFlush(ByteArrayOutputStream byteArrayOutputStream, OutputStream outputStream) - throws IOException { - byteArrayOutputStream.writeTo(outputStream); - byteArrayOutputStream.reset(); - outputStream.flush(); - } - -} diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/stringencoder/Base32.java b/smack-core/src/main/java/org/jivesoftware/smack/util/stringencoder/Base32.java index 9711ab8a5..12856c29a 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/stringencoder/Base32.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/stringencoder/Base32.java @@ -45,7 +45,7 @@ public class Base32 { } }; - private static final String ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; + private static final String ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ2345678"; public static StringEncoder getStringEncoder() { return base32Stringencoder; diff --git a/smack-core/src/test/java/org/jivesoftware/smack/parsing/ParsingExceptionTest.java b/smack-core/src/test/java/org/jivesoftware/smack/parsing/ParsingExceptionTest.java index 4fce7a186..c8673bc0c 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/parsing/ParsingExceptionTest.java +++ b/smack-core/src/test/java/org/jivesoftware/smack/parsing/ParsingExceptionTest.java @@ -16,8 +16,8 @@ */ package org.jivesoftware.smack.parsing; -import static org.hamcrest.MatcherAssert.assertThat; import static org.jivesoftware.smack.test.util.CharSequenceEquals.equalsCharSequence; +import static org.junit.Assert.assertThat; import java.io.IOException; diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java index e95048665..6912d8e5d 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java @@ -44,7 +44,6 @@ import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.jivesoftware.smackx.forward.packet.Forwarded; -import org.jivesoftware.smackx.mam.MamManager.MamQueryArgs; import org.jivesoftware.smackx.mam.element.MamElements; import org.jivesoftware.smackx.mam.element.MamElements.MamResultExtension; import org.jivesoftware.smackx.mam.element.MamFinIQ; diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/forward/ForwardedTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/forward/ForwardedTest.java index 983d7c887..59e8b42f4 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/forward/ForwardedTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/forward/ForwardedTest.java @@ -16,10 +16,10 @@ */ package org.jivesoftware.smackx.forward; -import static org.hamcrest.MatcherAssert.assertThat; import static org.jivesoftware.smack.test.util.CharSequenceEquals.equalsCharSequence; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; import java.util.Properties; diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/iqversion/VersionTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/iqversion/VersionTest.java index e7d317919..574bed4e9 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/iqversion/VersionTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/iqversion/VersionTest.java @@ -16,9 +16,9 @@ */ package org.jivesoftware.smackx.iqversion; -import static org.hamcrest.MatcherAssert.assertThat; import static org.jivesoftware.smack.test.util.CharSequenceEquals.equalsCharSequence; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import org.jivesoftware.smack.DummyConnection; diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/ping/PingTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/ping/PingTest.java index 95a992a68..37082a358 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/ping/PingTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/ping/PingTest.java @@ -16,10 +16,10 @@ */ package org.jivesoftware.smackx.ping; -import static org.hamcrest.MatcherAssert.assertThat; import static org.jivesoftware.smack.test.util.CharSequenceEquals.equalsCharSequence; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.jxmpp.jid.JidTestUtil.DUMMY_AT_EXAMPLE_ORG; diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/provider/PubSubProviderTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/provider/PubSubProviderTest.java index 632396b8f..59f33e43d 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/provider/PubSubProviderTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/provider/PubSubProviderTest.java @@ -16,9 +16,9 @@ */ package org.jivesoftware.smackx.pubsub.provider; -import static org.hamcrest.MatcherAssert.assertThat; import static org.jivesoftware.smack.test.util.CharSequenceEquals.equalsCharSequence; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; import java.util.List; diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java index 91374b43d..01d1a60e8 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java @@ -16,11 +16,11 @@ */ package org.jivesoftware.smackx.receipts; -import static org.hamcrest.MatcherAssert.assertThat; import static org.jivesoftware.smack.test.util.CharSequenceEquals.equalsCharSequence; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import java.util.Properties; diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/xhtmlim/provider/XHTMLExtensionProviderTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/xhtmlim/provider/XHTMLExtensionProviderTest.java index 6375c9410..41acbece8 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/xhtmlim/provider/XHTMLExtensionProviderTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/xhtmlim/provider/XHTMLExtensionProviderTest.java @@ -17,8 +17,8 @@ package org.jivesoftware.smackx.xhtmlim.provider; import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.MatcherAssert.assertThat; import static org.jivesoftware.smack.test.util.CharSequenceEquals.equalsCharSequence; +import static org.junit.Assert.assertThat; import java.io.IOException; import java.io.InputStream; diff --git a/smack-integration-test/src/test/java/org/igniterealtime/smack/inttest/unittest/SmackIntegrationTestFrameworkUnitTest.java b/smack-integration-test/src/test/java/org/igniterealtime/smack/inttest/unittest/SmackIntegrationTestFrameworkUnitTest.java index a73b432df..fe943873b 100644 --- a/smack-integration-test/src/test/java/org/igniterealtime/smack/inttest/unittest/SmackIntegrationTestFrameworkUnitTest.java +++ b/smack-integration-test/src/test/java/org/igniterealtime/smack/inttest/unittest/SmackIntegrationTestFrameworkUnitTest.java @@ -1,6 +1,6 @@ /** * - * Copyright 2015-2020 Florian Schmaus + * Copyright 2015-2019 Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ 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 java.io.IOException; @@ -44,10 +43,15 @@ import org.igniterealtime.smack.inttest.SmackIntegrationTestFramework; import org.igniterealtime.smack.inttest.SmackIntegrationTestFramework.TestRunResult; import org.junit.AfterClass; import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; public class SmackIntegrationTestFrameworkUnitTest { + @Rule + public ExpectedException expectedException = ExpectedException.none(); + private static boolean beforeClassInvoked; private static boolean afterClassInvoked; @@ -64,10 +68,10 @@ public class SmackIntegrationTestFrameworkUnitTest { @Test public void throwsRuntimeExceptionsTest() throws KeyManagementException, NoSuchAlgorithmException, SmackException, IOException, XMPPException, InterruptedException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + expectedException.expect(RuntimeException.class); + expectedException.expectMessage(ThrowsRuntimeExceptionDummyTest.RUNTIME_EXCEPTION_MESSAGE); DummySmackIntegrationTestFramework sinttest = getFrameworkForUnitTest(ThrowsRuntimeExceptionDummyTest.class); - assertThrows(RuntimeException.class, () -> { - sinttest.run(); - }); + sinttest.run(); } public static class ThrowsRuntimeExceptionDummyTest extends AbstractSmackIntegrationTest { diff --git a/smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/util/OmemoMessageBuilder.java b/smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/util/OmemoMessageBuilder.java index 1f20e39cc..e45a8cfd3 100644 --- a/smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/util/OmemoMessageBuilder.java +++ b/smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/util/OmemoMessageBuilder.java @@ -274,13 +274,13 @@ public class OmemoMessageBuilder