diff --git a/src/test/java/redis/clients/jedis/modules/search/SearchWithParamsTest.java b/src/test/java/redis/clients/jedis/modules/search/SearchWithParamsTest.java index 3b920f1bbe..a81ceb7821 100644 --- a/src/test/java/redis/clients/jedis/modules/search/SearchWithParamsTest.java +++ b/src/test/java/redis/clients/jedis/modules/search/SearchWithParamsTest.java @@ -1,9 +1,11 @@ package redis.clients.jedis.modules.search; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.*; import static redis.clients.jedis.util.AssertUtil.assertOK; import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import org.hamcrest.Matchers; import org.junit.BeforeClass; @@ -1190,28 +1192,31 @@ public void deepReplySearchProfile() { ? (Map) profile.getValue().get("Iterators profile") : ((List>) profile.getValue().get("Iterators profile")).get(0); - assertEquals("INTERSECT", depth0.get("Type")); - List> depth0_children = (List>) depth0.get("Child iterators"); - assertEquals("TEXT", depth0_children.get(0).get("Type")); - Map depth1 = depth0_children.get(1); - assertEquals("INTERSECT", depth1.get("Type")); - List> depth1_children = (List>) depth1.get("Child iterators"); - assertEquals("TEXT", depth1_children.get(0).get("Type")); - Map depth2 = depth1_children.get(1); - assertEquals("INTERSECT", depth2.get("Type")); - List> depth2_children = (List>) depth2.get("Child iterators"); - assertEquals("TEXT", depth2_children.get(0).get("Type")); - Map depth3 = depth2_children.get(1); - assertEquals("INTERSECT", depth3.get("Type")); - List> depth3_children = (List>) depth3.get("Child iterators"); - assertEquals("TEXT", depth3_children.get(0).get("Type")); - Map depth4 = depth3_children.get(1); - assertEquals("INTERSECT", depth4.get("Type")); - List> depth4_children = (List>) depth4.get("Child iterators"); - assertEquals("TEXT", depth4_children.get(0).get("Type")); - Map depth5 = depth4_children.get(1); - assertEquals("TEXT", depth5.get("Type")); - assertNull(depth5.get("Child iterators")); + AtomicInteger intersectLevelCount = new AtomicInteger(); + AtomicInteger textLevelCount = new AtomicInteger(); + deepReplySearchProfile_assertProfile(depth0, intersectLevelCount, textLevelCount); + assertThat(intersectLevelCount.get(), Matchers.greaterThan(0)); + assertThat(textLevelCount.get(), Matchers.greaterThan(0)); + } + + private void deepReplySearchProfile_assertProfile(Map attr, + AtomicInteger intersectLevelCount, AtomicInteger textLevelCount) { + + String type = (String) attr.get("Type"); + assertThat(type, Matchers.not(Matchers.blankOrNullString())); + + switch (type) { + case "INTERSECT": + assertThat(attr, Matchers.hasKey("Child iterators")); + intersectLevelCount.incrementAndGet(); + deepReplySearchProfile_assertProfile((Map) ((List) attr.get("Child iterators")).get(0), + intersectLevelCount, textLevelCount); + break; + case "TEXT": + assertThat(attr, Matchers.hasKey("Term")); + textLevelCount.incrementAndGet(); + break; + } } @Test