Skip to content

Commit 3b2154a

Browse files
tvernumkcm
authored andcommitted
[TEST] HLRC: Expand failure messages in API checks (#34838)
For the assertions in the "testApiNamingConventions" test that check the API contract, this change adds details of the method that was being checked, and the intent of the assertion (the API contract)
1 parent 2f21422 commit 3b2154a

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -712,41 +712,49 @@ public void testApiNamingConventions() throws Exception {
712712

713713
assertTrue("method [" + apiName + "] is not final",
714714
Modifier.isFinal(method.getClass().getModifiers()) || Modifier.isFinal(method.getModifiers()));
715-
assertTrue(Modifier.isPublic(method.getModifiers()));
715+
assertTrue("method [" + method + "] should be public", Modifier.isPublic(method.getModifiers()));
716716

717717
//we convert all the method names to snake case, hence we need to look for the '_async' suffix rather than 'Async'
718718
if (apiName.endsWith("_async")) {
719719
assertTrue("async method [" + method.getName() + "] doesn't have corresponding sync method",
720720
methods.containsKey(apiName.substring(0, apiName.length() - 6)));
721-
assertThat(method.getReturnType(), equalTo(Void.TYPE));
722-
assertEquals(0, method.getExceptionTypes().length);
721+
assertThat("async method [" + method + "] should return void", method.getReturnType(), equalTo(Void.TYPE));
722+
assertEquals("async method [" + method + "] should not throw any exceptions", 0, method.getExceptionTypes().length);
723723
if (apiName.equals("security.get_ssl_certificates_async")) {
724724
assertEquals(2, method.getParameterTypes().length);
725725
assertThat(method.getParameterTypes()[0], equalTo(RequestOptions.class));
726726
assertThat(method.getParameterTypes()[1], equalTo(ActionListener.class));
727727
} else {
728-
assertEquals(3, method.getParameterTypes().length);
729-
assertThat(method.getParameterTypes()[0].getSimpleName(), endsWith("Request"));
730-
assertThat(method.getParameterTypes()[1], equalTo(RequestOptions.class));
731-
assertThat(method.getParameterTypes()[2], equalTo(ActionListener.class));
728+
assertEquals("async method [" + method + "] has the wrong number of arguments", 3, method.getParameterTypes().length);
729+
assertThat("the first parameter to async method [" + method + "] should be a request type",
730+
method.getParameterTypes()[0].getSimpleName(), endsWith("Request"));
731+
assertThat("the second parameter to async method [" + method + "] is the wrong type",
732+
method.getParameterTypes()[1], equalTo(RequestOptions.class));
733+
assertThat("the third parameter to async method [" + method + "] is the wrong type",
734+
method.getParameterTypes()[2], equalTo(ActionListener.class));
732735
}
733736
} else {
734737
//A few methods return a boolean rather than a response object
735738
if (apiName.equals("ping") || apiName.contains("exist")) {
736-
assertThat(method.getReturnType().getSimpleName(), equalTo("boolean"));
739+
assertThat("the return type for method [" + method + "] is incorrect",
740+
method.getReturnType().getSimpleName(), equalTo("boolean"));
737741
} else {
738-
assertThat(method.getReturnType().getSimpleName(), endsWith("Response"));
742+
assertThat("the return type for method [" + method + "] is incorrect",
743+
method.getReturnType().getSimpleName(), endsWith("Response"));
739744
}
740745

741-
assertEquals(1, method.getExceptionTypes().length);
746+
assertEquals("incorrect number of exceptions for method [" + method + "]", 1, method.getExceptionTypes().length);
742747
//a few methods don't accept a request object as argument
743748
if (apiName.equals("ping") || apiName.equals("info") || apiName.equals("security.get_ssl_certificates")) {
744-
assertEquals(1, method.getParameterTypes().length);
745-
assertThat(method.getParameterTypes()[0], equalTo(RequestOptions.class));
749+
assertEquals("incorrect number of arguments for method [" + method + "]", 1, method.getParameterTypes().length);
750+
assertThat("the parameter to method [" + method + "] is the wrong type",
751+
method.getParameterTypes()[0], equalTo(RequestOptions.class));
746752
} else {
747-
assertEquals(apiName, 2, method.getParameterTypes().length);
748-
assertThat(method.getParameterTypes()[0].getSimpleName(), endsWith("Request"));
749-
assertThat(method.getParameterTypes()[1], equalTo(RequestOptions.class));
753+
assertEquals("incorrect number of arguments for method [" + method + "]", 2, method.getParameterTypes().length);
754+
assertThat("the first parameter to method [" + method + "] is the wrong type",
755+
method.getParameterTypes()[0].getSimpleName(), endsWith("Request"));
756+
assertThat("the second parameter to method [" + method + "] is the wrong type",
757+
method.getParameterTypes()[1], equalTo(RequestOptions.class));
750758
}
751759

752760
boolean remove = apiSpec.remove(apiName);

0 commit comments

Comments
 (0)