From a3221e745a9e92f16237a3ba65145fceff343037 Mon Sep 17 00:00:00 2001 From: Wang Date: Sat, 14 Nov 2020 20:33:17 -0600 Subject: [PATCH 1/3] Fix flaky test domain by modifying assert to use containsAnyOrder --- .../db/whois/api/rdap/RdapObjectMapperTest.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/whois-api/src/test/java/net/ripe/db/whois/api/rdap/RdapObjectMapperTest.java b/whois-api/src/test/java/net/ripe/db/whois/api/rdap/RdapObjectMapperTest.java index 37495fa8fc..ad427ff4c3 100644 --- a/whois-api/src/test/java/net/ripe/db/whois/api/rdap/RdapObjectMapperTest.java +++ b/whois-api/src/test/java/net/ripe/db/whois/api/rdap/RdapObjectMapperTest.java @@ -26,11 +26,13 @@ import org.mockito.runners.MockitoJUnitRunner; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Optional; import static net.ripe.db.whois.common.domain.CIString.ciString; +import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.emptyIterable; @@ -290,9 +292,16 @@ public void domain() { assertThat(result.getUnicodeName(), is(nullValue())); assertThat(result.getNameservers(), hasSize(2)); - assertThat(result.getNameservers().get(0).getLdhName(), is("ns.1.net")); - assertThat(result.getNameservers().get(1).getLdhName(), is("ns.foo.net.0.0.193.in-addr.arpa")); - assertThat(result.getNameservers().get(1).getIpAddresses().getIpv4().get(0), is("10.0.0.0/32")); + List NameServersList = new ArrayList (); + NameServersList.add(result.getNameservers().get(0).getLdhName()); + NameServersList.add(result.getNameservers().get(1).getLdhName()); + assertThat(NameServersList, containsInAnyOrder("ns.1.net", "ns.foo.net.0.0.193.in-addr.arpa")); + if(result.getNameservers().get(0).getIpAddresses() != null){ + assertThat(result.getNameservers().get(0).getIpAddresses().getIpv4().get(0), is("10.0.0.0/32")); + } + else{ + assertThat(result.getNameservers().get(1).getIpAddresses().getIpv4().get(0), is("10.0.0.0/32")); + } final Domain.SecureDNS secureDNS = result.getSecureDNS(); assertThat(secureDNS.isDelegationSigned(), is(true)); From d20b9c5637d3a574e4f572ec816cb9fe6bb6c4d3 Mon Sep 17 00:00:00 2001 From: Wang Date: Sat, 14 Nov 2020 21:07:27 -0600 Subject: [PATCH 2/3] Remove import of CoreMatchers --- .../java/net/ripe/db/whois/api/rdap/RdapObjectMapperTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/whois-api/src/test/java/net/ripe/db/whois/api/rdap/RdapObjectMapperTest.java b/whois-api/src/test/java/net/ripe/db/whois/api/rdap/RdapObjectMapperTest.java index ad427ff4c3..3f4ade4e5f 100644 --- a/whois-api/src/test/java/net/ripe/db/whois/api/rdap/RdapObjectMapperTest.java +++ b/whois-api/src/test/java/net/ripe/db/whois/api/rdap/RdapObjectMapperTest.java @@ -32,7 +32,6 @@ import java.util.Optional; import static net.ripe.db.whois.common.domain.CIString.ciString; -import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.emptyIterable; From a6838436ecae2179a204fbbe04bbaffa9ebcb133 Mon Sep 17 00:00:00 2001 From: Wang Date: Sat, 14 Nov 2020 23:47:54 -0600 Subject: [PATCH 3/3] Modify fix to match Java guidelines --- .../db/whois/api/rdap/RdapObjectMapperTest.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/whois-api/src/test/java/net/ripe/db/whois/api/rdap/RdapObjectMapperTest.java b/whois-api/src/test/java/net/ripe/db/whois/api/rdap/RdapObjectMapperTest.java index 3f4ade4e5f..6c2e849724 100644 --- a/whois-api/src/test/java/net/ripe/db/whois/api/rdap/RdapObjectMapperTest.java +++ b/whois-api/src/test/java/net/ripe/db/whois/api/rdap/RdapObjectMapperTest.java @@ -291,16 +291,12 @@ public void domain() { assertThat(result.getUnicodeName(), is(nullValue())); assertThat(result.getNameservers(), hasSize(2)); - List NameServersList = new ArrayList (); - NameServersList.add(result.getNameservers().get(0).getLdhName()); - NameServersList.add(result.getNameservers().get(1).getLdhName()); - assertThat(NameServersList, containsInAnyOrder("ns.1.net", "ns.foo.net.0.0.193.in-addr.arpa")); - if(result.getNameservers().get(0).getIpAddresses() != null){ - assertThat(result.getNameservers().get(0).getIpAddresses().getIpv4().get(0), is("10.0.0.0/32")); - } - else{ - assertThat(result.getNameservers().get(1).getIpAddresses().getIpv4().get(0), is("10.0.0.0/32")); - } + List nameServersList = new ArrayList<>(); + nameServersList.add(result.getNameservers().get(0).getLdhName()); + nameServersList.add(result.getNameservers().get(1).getLdhName()); + assertThat(nameServersList, containsInAnyOrder("ns.1.net", "ns.foo.net.0.0.193.in-addr.arpa")); + int index = (result.getNameservers().get(0).getIpAddresses() != null) ? 0 : 1; + assertThat(result.getNameservers().get(index).getIpAddresses().getIpv4().get(0), is("10.0.0.0/32")); final Domain.SecureDNS secureDNS = result.getSecureDNS(); assertThat(secureDNS.isDelegationSigned(), is(true));