This is an automated email from the ASF dual-hosted git repository.

spmallette pushed a commit to branch 3.7-dev
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git


The following commit(s) were added to refs/heads/3.7-dev by this push:
     new a5bf4a3ce4 Allowed providers to handle error message assertion for 
gherkin.
a5bf4a3ce4 is described below

commit a5bf4a3ce4e65cfaec58b8911b09c3afb1c752cf
Author: Stephen Mallette <[email protected]>
AuthorDate: Wed Oct 16 16:39:44 2024 -0400

    Allowed providers to handle error message assertion for gherkin.
    
    Took an earlier a change a step further and made it so that providers get 
more complete control over the assertions. CTR
---
 .../tinkerpop/gremlin/features/StepDefinition.java | 32 ++++++++++++----------
 .../apache/tinkerpop/gremlin/features/World.java   | 13 ++++++---
 2 files changed, 26 insertions(+), 19 deletions(-)

diff --git 
a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/features/StepDefinition.java
 
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/features/StepDefinition.java
index d26a5dd804..b34fdaed81 100644
--- 
a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/features/StepDefinition.java
+++ 
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/features/StepDefinition.java
@@ -405,21 +405,23 @@ public final class StepDefinition {
     public void theTraversalWillRaiseAnErrorWithMessage(final String 
comparison, final String expectedMessage) {
         assertNotNull(error);
 
-        final String msg = world.mapErrorMessage(expectedMessage);
-
-        switch (comparison) {
-            case "containing":
-                assertThat(error.getMessage(), 
containsStringIgnoringCase(msg));
-                break;
-            case "starting":
-                assertThat(error.getMessage(), startsWithIgnoringCase(msg));
-                break;
-            case "ending":
-                assertThat(error.getMessage(), endsWithIgnoringCase(msg));
-                break;
-            default:
-                throw new IllegalStateException(String.format(
-                        "Unknown comparison of %s - must be one of: 
containing, starting or ending", comparison));
+        // delegate error message assertion completely to the provider. if 
they choose to handle on their own then
+        // skip the default assertions
+        if (!world.handleErrorMessageAssertion(comparison, expectedMessage, 
error)) {
+            switch (comparison) {
+                case "containing":
+                    assertThat(error.getMessage(), 
containsStringIgnoringCase(expectedMessage));
+                    break;
+                case "starting":
+                    assertThat(error.getMessage(), 
startsWithIgnoringCase(expectedMessage));
+                    break;
+                case "ending":
+                    assertThat(error.getMessage(), 
endsWithIgnoringCase(expectedMessage));
+                    break;
+                default:
+                    throw new IllegalStateException(String.format(
+                            "Unknown comparison of %s - must be one of: 
containing, starting or ending", comparison));
+            }
         }
 
         // consume the error now that it has been asserted
diff --git 
a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/features/World.java 
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/features/World.java
index 41a0d070d6..52a977e614 100644
--- 
a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/features/World.java
+++ 
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/features/World.java
@@ -83,10 +83,15 @@ public interface World {
     }
 
     /**
-     * Allows for some flexibility in error message assertion, where the 
provider can supply their
-     * own error message that they find more suitable for a given test.
+     * Allows for some flexibility in error message assertion, where the 
provider can handle assertions themselves.
+     * Providers should use standard assertion logic as they would with tests. 
Note that if this method is called, then
+     * the exception has happened and that the only point of concern for 
assertion is the message. Providers can not use
+     * this method as a way to avoid throwing an exception in the first place. 
TinkerPop tries to not be too
+     * prescriptive with error messages and while we recommend providers 
conform to our messages it is not required.
+     * @return {@code true} if the assertion was handled and {@code false} if 
default handling should be engaged
      */
-    public default String mapErrorMessage(final String expectedErrorMessage) {
-        return expectedErrorMessage;
+    public default boolean handleErrorMessageAssertion(final String 
comparison, final String expectedMessage,
+                                                       final Throwable 
actualException) {
+        return false;
     }
 }

Reply via email to