This is an automated email from the ASF dual-hosted git repository.
bowenliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kyuubi.git
The following commit(s) were added to refs/heads/master by this push:
new 1efad474f [KYUUBI #5214] Correct file path for scala tests in
util-scala module
1efad474f is described below
commit 1efad474fd1979323e9bdcccab4f38e9a1952e56
Author: liangbowen <[email protected]>
AuthorDate: Wed Aug 30 10:56:13 2023 +0800
[KYUUBI #5214] Correct file path for scala tests in util-scala module
### _Why are the changes needed?_
- Move Scala tests in `kyuubi-util-scala` module from `src/test/java`back
to the correct path `src/test/scala`
- Apply Scala style fixes
- Add handy assertion methods for intercepting exception
### _How was this patch tested?_
- [ ] Add some test cases that check the changes thoroughly including
negative and positive cases if possible
- [ ] Add screenshots for manual tests if appropriate
- [x] [Run
test](https://kyuubi.readthedocs.io/en/master/contributing/code/testing.html#running-tests)
locally before make a pull request
### _Was this patch authored or co-authored using generative AI tooling?_
No.
Closes #5214 from bowenliang123/scalautil-test.
Closes #5214
55bc38cde [liangbowen] correct file path for scala tests in util-scala
module
Authored-by: liangbowen <[email protected]>
Signed-off-by: Bowen Liang <[email protected]>
---
.../org/apache/kyuubi/util/AssertionUtils.scala | 26 +++++++++++++++++++++-
.../apache/kyuubi/util/SemanticVersionSuite.scala | 11 +++++++--
.../kyuubi/util/reflect/ReflectUtilsSuite.scala | 20 +++++++++--------
3 files changed, 45 insertions(+), 12 deletions(-)
diff --git
a/kyuubi-util-scala/src/test/java/org/apache/kyuubi/util/AssertionUtils.scala
b/kyuubi-util-scala/src/test/scala/org/apache/kyuubi/util/AssertionUtils.scala
similarity index 71%
rename from
kyuubi-util-scala/src/test/java/org/apache/kyuubi/util/AssertionUtils.scala
rename to
kyuubi-util-scala/src/test/scala/org/apache/kyuubi/util/AssertionUtils.scala
index 7b465cb7f..a6cd9b862 100644
---
a/kyuubi-util-scala/src/test/java/org/apache/kyuubi/util/AssertionUtils.scala
+++
b/kyuubi-util-scala/src/test/scala/org/apache/kyuubi/util/AssertionUtils.scala
@@ -18,8 +18,10 @@ package org.apache.kyuubi.util
import java.util.Locale
+import scala.reflect.ClassTag
+
import org.scalactic.source
-import org.scalatest.Assertions.fail
+import org.scalatest.Assertions._
object AssertionUtils {
@@ -51,4 +53,26 @@ object AssertionUtils {
fail(s"Expected containing '$expected' ignoring case, but got
[$actual]")(pos)
}
}
+
+ /**
+ * Asserts that the given function throws an exception of the given type
+ * and with the exception message equals to expected string
+ */
+ def interceptEquals[T <: Exception](f: => Any)(expected: String)(implicit
+ classTag: ClassTag[T],
+ pos: source.Position): Unit = {
+ val exception = intercept[T](f)(classTag, pos)
+ assertResult(expected)(exception.getMessage)
+ }
+
+ /**
+ * Asserts that the given function throws an exception of the given type
+ * and with the exception message equals to expected string
+ */
+ def interceptContains[T <: Exception](f: => Any)(contained: String)(implicit
+ classTag: ClassTag[T],
+ pos: source.Position): Unit = {
+ val exception = intercept[T](f)(classTag, pos)
+ assert(exception.getMessage.contains(contained))
+ }
}
diff --git
a/kyuubi-util-scala/src/test/java/org/apache/kyuubi/util/SemanticVersionSuite.scala
b/kyuubi-util-scala/src/test/scala/org/apache/kyuubi/util/SemanticVersionSuite.scala
similarity index 89%
rename from
kyuubi-util-scala/src/test/java/org/apache/kyuubi/util/SemanticVersionSuite.scala
rename to
kyuubi-util-scala/src/test/scala/org/apache/kyuubi/util/SemanticVersionSuite.scala
index ca208d89c..6cad67993 100644
---
a/kyuubi-util-scala/src/test/java/org/apache/kyuubi/util/SemanticVersionSuite.scala
+++
b/kyuubi-util-scala/src/test/scala/org/apache/kyuubi/util/SemanticVersionSuite.scala
@@ -17,7 +17,10 @@
package org.apache.kyuubi.util
// scalastyle:off
+
import org.scalatest.funsuite.AnyFunSuite
+
+import org.apache.kyuubi.util.AssertionUtils._
// scalastyle:on
// scalastyle:off
@@ -42,8 +45,12 @@ class SemanticVersionSuite extends AnyFunSuite {
}
test("reject parsing illegal formatted version") {
- assertThrows[IllegalArgumentException](SemanticVersion("v1.0"))
- assertThrows[IllegalArgumentException](SemanticVersion(".1.0"))
+ interceptContains[IllegalArgumentException](SemanticVersion("v1.0"))(
+ "Tried to parse 'v1.0' as a project version string, " +
+ "but it could not find the major and minor version numbers")
+ interceptContains[IllegalArgumentException](SemanticVersion(".1.0"))(
+ "Tried to parse '.1.0' as a project version string, " +
+ "but it could not find the major and minor version numbers")
}
test("companion class compare version at most") {
diff --git
a/kyuubi-util-scala/src/test/java/org/apache/kyuubi/util/reflect/ReflectUtilsSuite.scala
b/kyuubi-util-scala/src/test/scala/org/apache/kyuubi/util/reflect/ReflectUtilsSuite.scala
similarity index 87%
rename from
kyuubi-util-scala/src/test/java/org/apache/kyuubi/util/reflect/ReflectUtilsSuite.scala
rename to
kyuubi-util-scala/src/test/scala/org/apache/kyuubi/util/reflect/ReflectUtilsSuite.scala
index d81d1d9f9..626aeebe2 100644
---
a/kyuubi-util-scala/src/test/java/org/apache/kyuubi/util/reflect/ReflectUtilsSuite.scala
+++
b/kyuubi-util-scala/src/test/scala/org/apache/kyuubi/util/reflect/ReflectUtilsSuite.scala
@@ -16,9 +16,10 @@
*/
package org.apache.kyuubi.util.reflect
+// scalastyle:off
import org.scalatest.funsuite.AnyFunSuite
-// scalastyle:off
+import org.apache.kyuubi.util.AssertionUtils._
import org.apache.kyuubi.util.reflect.ReflectUtils._
class ReflectUtilsSuite extends AnyFunSuite {
// scalastyle:on
@@ -68,15 +69,16 @@ class ReflectUtilsSuite extends AnyFunSuite {
}
test("test invokeAs method not found exception") {
- val exception = intercept[RuntimeException]{
- invokeAs[String](ObjectA, "methodNotExists", (classOf[String], "arg1"),
+ interceptEquals[RuntimeException] {
+ invokeAs[String](
+ ObjectA,
+ "methodNotExists",
+ (classOf[String], "arg1"),
(classOf[String], "arg2"))
- }
- assert(exception.getMessage ===
- "Method methodNotExists(java.lang.String, java.lang.String) not found " +
- "in class org.apache.kyuubi.util.reflect.ObjectA$ " +
- "[equals(java.lang.Object), field5(), field6(), getClass(),
hashCode(), method5(), " +
- "method6(), notify(), notifyAll(), toString(), wait(), wait(long),
wait(long, int)]")
+ }("Method methodNotExists(java.lang.String, java.lang.String) not found " +
+ "in class org.apache.kyuubi.util.reflect.ObjectA$ " +
+ "[equals(java.lang.Object), field5(), field6(), getClass(), hashCode(),
method5(), " +
+ "method6(), notify(), notifyAll(), toString(), wait(), wait(long),
wait(long, int)]")
}
}