Skip to content

Commit dd3e9f3

Browse files
author
Michel Davit
authored
Fix typeValidation in TransformOverride (#4967)
1 parent 94087d4 commit dd3e9f3

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

scio-test/src/main/scala/com/spotify/scio/testing/TransformOverride.scala

+13-8
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,16 @@ object TransformOverride {
7676
java.lang.Double.TYPE -> classOf[java.lang.Double]
7777
)
7878

79-
private def typeValidation[A, B](failMsg: String, aIn: Class[A], bIn: Class[B]): Unit = {
79+
private def typeValidation[A, B](
80+
expectedIn: Class[B],
81+
actualIn: Class[A],
82+
failMsg: String
83+
): Unit = {
8084
// get normal java types instead of primitives
81-
val (a, b) = (primitiveMapping.getOrElse(aIn, aIn), primitiveMapping.getOrElse(bIn, bIn))
82-
if (!a.isAssignableFrom(b))
83-
throw new IllegalArgumentException(s"$failMsg Expected: ${aIn} Found: ${bIn}")
85+
val expected = primitiveMapping.getOrElse(expectedIn, expectedIn)
86+
val actual = primitiveMapping.getOrElse(actualIn, actualIn)
87+
if (!expected.isAssignableFrom(actual))
88+
throw new IllegalArgumentException(s"$failMsg Expected: $expected Found: $actual")
8489
}
8590

8691
/**
@@ -105,9 +110,9 @@ object TransformOverride {
105110
def of[T: ClassTag, U](name: String, fn: T => U): PTransformOverride = {
106111
val wrappedFn: T => U = fn.compose { t: T =>
107112
typeValidation(
108-
s"Input for override transform $name does not match pipeline transform.",
113+
implicitly[ClassTag[T]].runtimeClass,
109114
t.getClass,
110-
implicitly[ClassTag[T]].runtimeClass
115+
s"Input for override transform $name does not match pipeline transform."
111116
)
112117
t
113118
}
@@ -132,9 +137,9 @@ object TransformOverride {
132137
val wrappedFn: T => JIterable[U] = fn
133138
.compose { t: T =>
134139
typeValidation(
135-
s"Input for override transform $name does not match pipeline transform.",
140+
implicitly[ClassTag[T]].runtimeClass,
136141
t.getClass,
137-
implicitly[ClassTag[T]].runtimeClass
142+
s"Input for override transform $name does not match pipeline transform."
138143
)
139144
t
140145
}

0 commit comments

Comments
 (0)