Skip to content

Commit

Permalink
put all values directly in RandomFrom in the unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Tianli Feng <[email protected]>
  • Loading branch information
Tianli Feng committed Mar 17, 2022
1 parent ec61416 commit dfd260d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions server/src/test/java/org/opensearch/rest/RestRequestTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

Expand Down Expand Up @@ -289,17 +289,18 @@ public void testRequiredContent() {
*/
public void testValidateParamValuesAreEqualWhenTheyAreEqual() {
FakeRestRequest request = new FakeRestRequest();
List<String> valueList = new ArrayList<>(Arrays.asList(null, "", "value1"));
String valueForKey1 = randomFrom(valueList);
String valueForKey1 = randomFrom("value1", "", null);
String valueForKey2 = "value1";
request.params().put("key1", valueForKey1);
request.params().put("key2", valueForKey2);
request.validateParamValuesAreEqual("key1", "key2");
assertTrue(
"Values of the 2 keys should be equal, or having 1 null value or empty String. Value of key1: "
+ valueForKey1
+ ". Value of key2: "
+ valueForKey2,
String.format(
Locale.ROOT,
"The 2 values should be equal, or having 1 null/empty value. Value of key1: %s. Value of key2: %s",
valueForKey1,
valueForKey2
),
Strings.isNullOrEmpty(valueForKey1) || valueForKey1.equals(valueForKey2)
);
}
Expand Down

0 comments on commit dfd260d

Please sign in to comment.