Skip to content

Commit

Permalink
fix flaky tests in ParametersTest (#2820)
Browse files Browse the repository at this point in the history
  • Loading branch information
qz0610 authored and Cole-Greer committed Oct 17, 2024
1 parent 5542869 commit 2d6814a
Showing 1 changed file with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -57,7 +58,15 @@ public void shouldAllowNullValues() {

final Object[] params = parameters.getKeyValues(mock(Traverser.Admin.class));
assertEquals(6, params.length);
assertThat(Arrays.equals(new Object[] {"a", null, "b", "bat", "c", "cat"}, params), is(true));
Map<Object, Object> paramsMap = new HashMap<>();
for (int i = 0; i < params.length; i += 2) {
paramsMap.put(params[i], params[i + 1]);
}
Map<Object, Object> expectedMap = new HashMap<>();
expectedMap.put("a", null);
expectedMap.put("b", "bat");
expectedMap.put("c", "cat");
assertThat(paramsMap.equals(expectedMap), is(true));
}

@Test
Expand All @@ -67,7 +76,15 @@ public void shouldGetKeyValues() {

final Object[] params = parameters.getKeyValues(mock(Traverser.Admin.class));
assertEquals(6, params.length);
assertThat(Arrays.equals(new Object[] {"a", "axe", "b", "bat", "c", "cat"}, params), is(true));
Map<Object, Object> paramsMap = new HashMap<>();
for (int i = 0; i < params.length; i += 2) {
paramsMap.put(params[i], params[i + 1]);
}
Map<Object, Object> expectedMap = new HashMap<>();
expectedMap.put("a", "axe");
expectedMap.put("b", "bat");
expectedMap.put("c", "cat");
assertThat(paramsMap.equals(expectedMap), is(true));
}

@Test
Expand All @@ -77,7 +94,14 @@ public void shouldGetKeyValuesIgnoringSomeKeys() {

final Object[] params = parameters.getKeyValues(mock(Traverser.Admin.class), "b");
assertEquals(4, params.length);
assertThat(Arrays.equals(new Object[] {"a", "axe", "c", "cat"}, params), is(true));
Map<Object, Object> paramsMap = new HashMap<>();
for (int i = 0; i < params.length; i += 2) {
paramsMap.put(params[i], params[i + 1]);
}
Map<Object, Object> expectedMap = new HashMap<>();
expectedMap.put("a", "axe");
expectedMap.put("c", "cat");
assertThat(paramsMap.equals(expectedMap), is(true));
}

@Test
Expand Down

0 comments on commit 2d6814a

Please sign in to comment.