Skip to content

Commit c2e1271

Browse files
authored
Fixed flaky test in DisposableSupplierText.java with set comparison
1 parent ff5f5a8 commit c2e1271

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

inject/cdi2-se/src/test/java/org/glassfish/jersey/inject/cdi/se/DisposableSupplierTest.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2022 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2024 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -17,6 +17,8 @@
1717
package org.glassfish.jersey.inject.cdi.se;
1818

1919
import java.lang.reflect.Type;
20+
import java.util.HashSet;
21+
import java.util.Set;
2022
import java.util.concurrent.atomic.AtomicInteger;
2123
import java.util.concurrent.atomic.AtomicReference;
2224
import java.util.function.Supplier;
@@ -368,9 +370,17 @@ public void testDisposeComposedObjectWithPerLookupFields() {
368370

369371
// All instances should be the same because they are request scoped.
370372
ComposedObject instance = injectionManager.getInstance(ComposedObject.class);
371-
assertEquals("1", instance.getFirst());
372-
assertEquals("2", instance.getSecond());
373-
assertEquals("3", instance.getThird());
373+
Set<String> set1 = new HashSet<String>() {{
374+
add("1");
375+
add("2");
376+
add("3");
377+
}};
378+
Set<String> set2 = new HashSet<String>() {{
379+
add(instance.getFirst().toString());
380+
add(instance.getSecond().toString());
381+
add(instance.getThird().toString());
382+
}};
383+
assertEquals(set1, set2);
374384
});
375385

376386
Supplier<String> cleanedSupplier = atomicSupplier.get();

inject/hk2/src/test/java/org/glassfish/jersey/inject/hk2/DisposableSupplierTest.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2022 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2024 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -17,6 +17,8 @@
1717
package org.glassfish.jersey.inject.hk2;
1818

1919
import java.lang.reflect.Type;
20+
import java.util.HashSet;
21+
import java.util.Set;
2022
import java.util.concurrent.atomic.AtomicInteger;
2123
import java.util.concurrent.atomic.AtomicReference;
2224
import java.util.function.Supplier;
@@ -374,9 +376,17 @@ public void testDisposeComposedObjectWithPerLookupFields() {
374376

375377
// All instances should be the same because they are request scoped.
376378
ComposedObject instance = injectionManager.getInstance(ComposedObject.class);
377-
assertEquals("1", instance.first);
378-
assertEquals("2", instance.second);
379-
assertEquals("3", instance.third);
379+
Set<String> set1 = new HashSet<String>() {{
380+
add("1");
381+
add("2");
382+
add("3");
383+
}};
384+
Set<String> set2 = new HashSet<String>() {{
385+
add(instance.first.toString());
386+
add(instance.second.toString());
387+
add(instance.third.toString());
388+
}};
389+
assertEquals(set1, set2);
380390
});
381391

382392
Supplier<String> cleanedSupplier = atomicSupplier.get();

0 commit comments

Comments
 (0)