From c2e1271b3709427a2130fb2c70a853dc66241cfc Mon Sep 17 00:00:00 2001 From: Benjamin Guan <47118893+mumbler6@users.noreply.github.com> Date: Tue, 22 Oct 2024 13:07:53 -0500 Subject: [PATCH] Fixed flaky test in DisposableSupplierText.java with set comparison --- .../inject/cdi/se/DisposableSupplierTest.java | 18 ++++++++++++++---- .../inject/hk2/DisposableSupplierTest.java | 18 ++++++++++++++---- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/inject/cdi2-se/src/test/java/org/glassfish/jersey/inject/cdi/se/DisposableSupplierTest.java b/inject/cdi2-se/src/test/java/org/glassfish/jersey/inject/cdi/se/DisposableSupplierTest.java index 69d68eb247..5dc78bc373 100644 --- a/inject/cdi2-se/src/test/java/org/glassfish/jersey/inject/cdi/se/DisposableSupplierTest.java +++ b/inject/cdi2-se/src/test/java/org/glassfish/jersey/inject/cdi/se/DisposableSupplierTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -17,6 +17,8 @@ package org.glassfish.jersey.inject.cdi.se; import java.lang.reflect.Type; +import java.util.HashSet; +import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Supplier; @@ -368,9 +370,17 @@ public void testDisposeComposedObjectWithPerLookupFields() { // All instances should be the same because they are request scoped. ComposedObject instance = injectionManager.getInstance(ComposedObject.class); - assertEquals("1", instance.getFirst()); - assertEquals("2", instance.getSecond()); - assertEquals("3", instance.getThird()); + Set set1 = new HashSet() {{ + add("1"); + add("2"); + add("3"); + }}; + Set set2 = new HashSet() {{ + add(instance.getFirst().toString()); + add(instance.getSecond().toString()); + add(instance.getThird().toString()); + }}; + assertEquals(set1, set2); }); Supplier cleanedSupplier = atomicSupplier.get(); diff --git a/inject/hk2/src/test/java/org/glassfish/jersey/inject/hk2/DisposableSupplierTest.java b/inject/hk2/src/test/java/org/glassfish/jersey/inject/hk2/DisposableSupplierTest.java index 9eefe4889a..5a2d86968b 100644 --- a/inject/hk2/src/test/java/org/glassfish/jersey/inject/hk2/DisposableSupplierTest.java +++ b/inject/hk2/src/test/java/org/glassfish/jersey/inject/hk2/DisposableSupplierTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -17,6 +17,8 @@ package org.glassfish.jersey.inject.hk2; import java.lang.reflect.Type; +import java.util.HashSet; +import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Supplier; @@ -374,9 +376,17 @@ public void testDisposeComposedObjectWithPerLookupFields() { // All instances should be the same because they are request scoped. ComposedObject instance = injectionManager.getInstance(ComposedObject.class); - assertEquals("1", instance.first); - assertEquals("2", instance.second); - assertEquals("3", instance.third); + Set set1 = new HashSet() {{ + add("1"); + add("2"); + add("3"); + }}; + Set set2 = new HashSet() {{ + add(instance.first.toString()); + add(instance.second.toString()); + add(instance.third.toString()); + }}; + assertEquals(set1, set2); }); Supplier cleanedSupplier = atomicSupplier.get();