From 35d08f96e77ab5f2e449addf55c82b829f9f41ae Mon Sep 17 00:00:00 2001 From: John Coben Date: Mon, 16 Oct 2023 11:29:58 -0400 Subject: [PATCH] SWE637 Fix flaky test RefactorTest This test was passing when run on its own but flaky when run with other tests. Discovered with the nondex tool: https://github.com/TestingResearchIllinois/NonDex Ran test on its own with command: mvn test -Dtest=com.insightfullogic.java8.examples.chapter3.RefactorTest#allStringJoins Ran tests in groups with command: mvn edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=com.insightfullogic.java8.examples.chapter3.RefactorTest#allStringJoins Fixed test by adding some code to sort the HashSet before comparing it to a hard-coded string. --- .../java8/examples/chapter3/RefactorTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/insightfullogic/java8/examples/chapter3/RefactorTest.java b/src/test/java/com/insightfullogic/java8/examples/chapter3/RefactorTest.java index a10f9363..ecf44cc9 100644 --- a/src/test/java/com/insightfullogic/java8/examples/chapter3/RefactorTest.java +++ b/src/test/java/com/insightfullogic/java8/examples/chapter3/RefactorTest.java @@ -4,7 +4,9 @@ import com.insightfullogic.java8.examples.chapter1.SampleData; import org.junit.Test; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Set; import java.util.function.Supplier; @@ -35,7 +37,10 @@ public void allStringJoins() { Refactor.LongTrackFinder longTrackFinder = finder.get(); Set longTracks = longTrackFinder.findLongTracks(albums); - assertEquals("[Acknowledgement, Resolution]", longTracks.toString()); + List result = new ArrayList(longTracks); + Collections.sort(result); + + assertEquals("[Acknowledgement, Resolution]", result.toString()); longTracks = longTrackFinder.findLongTracks(noTracks);