Skip to content

Commit

Permalink
Fix unit test by moving assert into try
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 15, 2022
1 parent d5ce228 commit 2d36c8f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions server/src/test/java/org/opensearch/rest/RestRequestTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,13 @@ public void testValidateParamValuesAreEqual() {
request.params().put("key2", valueForKey2);
try {
request.validateParamValuesAreEqual("key1", "key2");
assertTrue(
"Values of the 2 keys should be equal, or having a least 1 null value or empty String. Value of key1: "
+ valueForKey1
+ ". Value of key2: "
+ valueForKey2,
Strings.isNullOrEmpty(valueForKey1) || Strings.isNullOrEmpty(valueForKey2) || valueForKey1.equals(valueForKey2)
);
} catch (OpenSearchParseException e) {
assertEquals(
"The values of the request parameters: [key1, key2] are required to be equal, otherwise please only assign value to one of the request parameters.",
Expand All @@ -304,10 +311,6 @@ public void testValidateParamValuesAreEqual() {
assertFalse(Strings.isNullOrEmpty(valueForKey1));
assertFalse(Strings.isNullOrEmpty(valueForKey2));
}
assertTrue(
"Values of the 2 keys should be equal, or having a least 1 null value or empty String.",
Strings.isNullOrEmpty(valueForKey1) || Strings.isNullOrEmpty(valueForKey2) || valueForKey1.equals(valueForKey2)
);
}

private static RestRequest contentRestRequest(String content, Map<String, String> params) {
Expand Down

0 comments on commit 2d36c8f

Please sign in to comment.