imply-cheddar commented on code in PR #15454:
URL: https://github.com/apache/druid/pull/15454#discussion_r1427305594
##########
processing/src/test/java/org/apache/druid/java/util/common/IntervalsTest.java:
##########
@@ -78,4 +79,16 @@ public void testFindOverlappingInterval()
);
}
+ @Test(expected = DruidException.class)
+ public void testInvalidInterval()
+ {
+ try {
+ Intervals.of("invalid string");
+ }
+ catch (DruidException e) {
+ Assert.assertTrue(e.getMessage().contains("Bad Interval[invalid
string]"));
+
+ throw e;
+ }
+ }
Review Comment:
There is a `DruidExceptionMatcher` that can be used to validate
`DruidException` classes. We try to use it with `Assert.assertThat()`.
You can do an `Assert.assertThrows()` first which will return the Throwable,
and then `Assert.assertThat` on the returned throwable to validate with the
matcher. This pattern is preferred to expecting an exception be thrown out of
the test class as it's a bit more explicit and keeps any instance of an
exception exiting the test method as a bad thing always.
##########
server/src/test/java/org/apache/druid/test/utils/TestUtils.java:
##########
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.test.utils;
+
+import org.apache.druid.error.DruidException;
+import org.junit.Assert;
+
+import java.util.function.Function;
+
+public class TestUtils
+{
+ /**
+ * This only validates that IF the expression throws a DruidException, that
the assertFunction passes.
+ *
+ * @param expression - any expression that throws a DruidException
+ * @param assertFunction
+ */
+ public static void validateExpressionThrowsDruidException(
+ Runnable expression,
+ Function<DruidException, Void> assertFunction
+ )
+ {
Review Comment:
Can we either
1) make the call sites use the `Assert.assertThrows` ->
`Assert.assertMatches` pattern discussed above.
2) Adjust this to take a `DruidExceptionMatcher` instead of the `Function`
and then use the `Assert.assertThrows` -> `Assert.assertMatches` pattern in
here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]