From f329963e41db4b19a3a99d66686296af9cfbdd2d Mon Sep 17 00:00:00 2001 From: Pritham Sriram Govindaraj <75803408+ThugJudy@users.noreply.github.com> Date: Sat, 25 Nov 2023 03:09:32 -0600 Subject: [PATCH] Fixed flaky tests in ListFacetTests (#6180) --- .../browsing/facets/ListFacetTests.java | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/main/tests/server/src/com/google/refine/browsing/facets/ListFacetTests.java b/main/tests/server/src/com/google/refine/browsing/facets/ListFacetTests.java index c18348913f84..825b2de5b3cb 100644 --- a/main/tests/server/src/com/google/refine/browsing/facets/ListFacetTests.java +++ b/main/tests/server/src/com/google/refine/browsing/facets/ListFacetTests.java @@ -28,9 +28,14 @@ package com.google.refine.browsing.facets; import java.io.IOException; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ObjectNode; import org.testng.annotations.Test; import com.google.refine.RefineTest; @@ -69,8 +74,8 @@ public class ListFacetTests extends RefineTest { + "\"columnName\":\"Column A\"," + "\"invert\":false," + "\"choices\":[" - + " {\"v\":{\"v\":\"foobar\",\"l\":\"foobar\"},\"c\":1,\"s\":true}," - + " {\"v\":{\"v\":\"barbar\",\"l\":\"barbar\"},\"c\":1,\"s\":false}" + + " {\"v\":{\"v\":\"barbar\",\"l\":\"barbar\"},\"c\":1,\"s\":false}," + + " {\"v\":{\"v\":\"foobar\",\"l\":\"foobar\"},\"c\":1,\"s\":true}" + "]}"; private static String selectedEmptyChoiceFacet = "{" @@ -79,9 +84,9 @@ public class ListFacetTests extends RefineTest { + "\"columnName\":\"Column A\"," + "\"invert\":false," + "\"choices\":[" - + " {\"v\":{\"v\":\"ebar\",\"l\":\"ebar\"},\"c\":1,\"s\":false}," - + " {\"v\":{\"v\":\"cbar\",\"l\":\"cbar\"},\"c\":1,\"s\":false}," + " {\"v\":{\"v\":\"abar\",\"l\":\"abar\"},\"c\":1,\"s\":false}," + + " {\"v\":{\"v\":\"cbar\",\"l\":\"cbar\"},\"c\":1,\"s\":false}," + + " {\"v\":{\"v\":\"ebar\",\"l\":\"ebar\"},\"c\":1,\"s\":false}," + " {\"v\":{\"v\":\"foobar\",\"l\":\"true\"},\"c\":0,\"s\":true}" + "]}"; @@ -103,7 +108,14 @@ public void serializeListFacet() throws JsonParseException, JsonMappingException Facet facet = facetConfig.apply(project); facet.computeChoices(project, engine.getAllFilteredRows()); - TestUtils.isSerializedTo(facet, jsonFacet); + ObjectNode actual = ParsingUtilities.mapper.valueToTree(facet); + List choicesList = new ArrayList<>(); + + actual.findValues("choices").get(0).forEach(choicesList::add); + choicesList.sort(Comparator.comparing(JsonNode::toString)); + actual.replace("choices", ParsingUtilities.mapper.createArrayNode().addAll(choicesList)); + + TestUtils.assertEqualsAsJson(actual.toString(), jsonFacet); } @Test @@ -128,6 +140,14 @@ public void testSelectedEmptyChoice() throws IOException { ListFacetConfig facetConfig = ParsingUtilities.mapper.readValue(jsonConfig, ListFacetConfig.class); Facet facet = facetConfig.apply(project); facet.computeChoices(project, engine.getAllFilteredRows()); - TestUtils.isSerializedTo(facet, selectedEmptyChoiceFacet); + + ObjectNode actual = ParsingUtilities.mapper.valueToTree(facet); + List choicesList = new ArrayList<>(); + + actual.findValues("choices").get(0).forEach(choicesList::add); + choicesList.sort(Comparator.comparing(n -> n.get("v").toString())); + actual.replace("choices", ParsingUtilities.mapper.createArrayNode().addAll(choicesList)); + + TestUtils.assertEqualsAsJson(actual.toString(), selectedEmptyChoiceFacet); } }