Skip to content

Commit e1e1bf5

Browse files
committed
[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 3252dc5 commit e1e1bf5

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
@@ -730,41 +730,49 @@ public void testApiNamingConventions() throws Exception {
730730

731731
assertTrue("method [" + apiName + "] is not final",
732732
Modifier.isFinal(method.getClass().getModifiers()) || Modifier.isFinal(method.getModifiers()));
733-
assertTrue(Modifier.isPublic(method.getModifiers()));
733+
assertTrue("method [" + method + "] should be public", Modifier.isPublic(method.getModifiers()));
734734

735735
//we convert all the method names to snake case, hence we need to look for the '_async' suffix rather than 'Async'
736736
if (apiName.endsWith("_async")) {
737737
assertTrue("async method [" + method.getName() + "] doesn't have corresponding sync method",
738738
methods.containsKey(apiName.substring(0, apiName.length() - 6)));
739-
assertThat(method.getReturnType(), equalTo(Void.TYPE));
740-
assertEquals(0, method.getExceptionTypes().length);
739+
assertThat("async method [" + method + "] should return void", method.getReturnType(), equalTo(Void.TYPE));
740+
assertEquals("async method [" + method + "] should not throw any exceptions", 0, method.getExceptionTypes().length);
741741
if (apiName.equals("security.get_ssl_certificates_async")) {
742742
assertEquals(2, method.getParameterTypes().length);
743743
assertThat(method.getParameterTypes()[0], equalTo(RequestOptions.class));
744744
assertThat(method.getParameterTypes()[1], equalTo(ActionListener.class));
745745
} else {
746-
assertEquals(3, method.getParameterTypes().length);
747-
assertThat(method.getParameterTypes()[0].getSimpleName(), endsWith("Request"));
748-
assertThat(method.getParameterTypes()[1], equalTo(RequestOptions.class));
749-
assertThat(method.getParameterTypes()[2], equalTo(ActionListener.class));
746+
assertEquals("async method [" + method + "] has the wrong number of arguments", 3, method.getParameterTypes().length);
747+
assertThat("the first parameter to async method [" + method + "] should be a request type",
748+
method.getParameterTypes()[0].getSimpleName(), endsWith("Request"));
749+
assertThat("the second parameter to async method [" + method + "] is the wrong type",
750+
method.getParameterTypes()[1], equalTo(RequestOptions.class));
751+
assertThat("the third parameter to async method [" + method + "] is the wrong type",
752+
method.getParameterTypes()[2], equalTo(ActionListener.class));
750753
}
751754
} else {
752755
//A few methods return a boolean rather than a response object
753756
if (apiName.equals("ping") || apiName.contains("exist")) {
754-
assertThat(method.getReturnType().getSimpleName(), equalTo("boolean"));
757+
assertThat("the return type for method [" + method + "] is incorrect",
758+
method.getReturnType().getSimpleName(), equalTo("boolean"));
755759
} else {
756-
assertThat(method.getReturnType().getSimpleName(), endsWith("Response"));
760+
assertThat("the return type for method [" + method + "] is incorrect",
761+
method.getReturnType().getSimpleName(), endsWith("Response"));
757762
}
758763

759-
assertEquals(1, method.getExceptionTypes().length);
764+
assertEquals("incorrect number of exceptions for method [" + method + "]", 1, method.getExceptionTypes().length);
760765
//a few methods don't accept a request object as argument
761766
if (apiName.equals("ping") || apiName.equals("info") || apiName.equals("security.get_ssl_certificates")) {
762-
assertEquals(1, method.getParameterTypes().length);
763-
assertThat(method.getParameterTypes()[0], equalTo(RequestOptions.class));
767+
assertEquals("incorrect number of arguments for method [" + method + "]", 1, method.getParameterTypes().length);
768+
assertThat("the parameter to method [" + method + "] is the wrong type",
769+
method.getParameterTypes()[0], equalTo(RequestOptions.class));
764770
} else {
765-
assertEquals(apiName, 2, method.getParameterTypes().length);
766-
assertThat(method.getParameterTypes()[0].getSimpleName(), endsWith("Request"));
767-
assertThat(method.getParameterTypes()[1], equalTo(RequestOptions.class));
771+
assertEquals("incorrect number of arguments for method [" + method + "]", 2, method.getParameterTypes().length);
772+
assertThat("the first parameter to method [" + method + "] is the wrong type",
773+
method.getParameterTypes()[0].getSimpleName(), endsWith("Request"));
774+
assertThat("the second parameter to method [" + method + "] is the wrong type",
775+
method.getParameterTypes()[1], equalTo(RequestOptions.class));
768776
}
769777

770778
boolean remove = apiSpec.remove(apiName);

0 commit comments

Comments
 (0)