From 847a39b6ab31c7550b61971114b8d968ba7cc39a Mon Sep 17 00:00:00 2001 From: vanitasvitae Date: Fri, 23 Jun 2017 12:51:07 +0200 Subject: [PATCH] Fix shouldPreserveAddressOrderOnInsertions test The test failed because the ArrayList - in contrast to the underlying Set - did not check for duplicates on insert. Under certain circumstances this lead to an index out of bounds exception because the list in the test contained duplicated entries which were not present in the set of the Socks5Proxy. I fixed the issue by only inserting the address when it was not in the list before. --- .../smackx/bytestreams/socks5/Socks5ProxyTest.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ProxyTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ProxyTest.java index a5b0859b8..a4dd53bb6 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ProxyTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ProxyTest.java @@ -102,10 +102,15 @@ public class Socks5ProxyTest { @Test public void shouldPreserveAddressOrderOnInsertions() { Socks5Proxy proxy = Socks5Proxy.getSocks5Proxy(); - List addresses = new ArrayList(proxy.getLocalAddresses()); - addresses.add("1"); - addresses.add("2"); - addresses.add("3"); + List addresses = new ArrayList<>(proxy.getLocalAddresses()); + + for (int i = 1 ; i <= 3; i++) { + String addr = Integer.toString(i); + if (!addresses.contains(addr)) { + addresses.add(addr); + } + } + for (String address : addresses) { proxy.addLocalAddress(address); }