Итак, я пытаюсь создать модульный тест для моей функции отображения Hadoop, используя Mockito.Я правильно создал класс Mapper:
class XmlMapper extends Mapper[LongWritable, Text, Text, LongWritable] {
override def map(key: LongWritable, value: Text, context: Mapper[LongWritable, Text, Text, LongWritable]#Context): Unit = {
//does stuff
}
}
И затем у меня есть следующий тест:
import org.apache.hadoop.io.{LongWritable, Text}
import org.scalatest.FlatSpec
import org.scalatest.mockito.MockitoSugar
import org.mockito.Mockito.verify
import org.mockito.Mockito.times
class XmlMapperTest extends FlatSpec with MockitoSugar {
"XmlMapper" should "output" in {
val mapper = new XmlMapper
val context = mock[mapper.Context]
//so far does nothing yet
}
}
Но я получаю следующую ошибку:
- should output *** FAILED ***
[info] org.mockito.exceptions.base.MockitoException: Mockito cannot mock this class: class org.apache.hadoop.mapreduce.Mapper$Context.
[info]
[info] Mockito can only mock non-private & non-final classes.
[info] If you're not sure why you're getting this error, please report to the mailing list.
Что не имеет смысла, потому что Mapper.Context является публичным абстрактным классом.
Вот общая трассировка стека:
[info] Underlying exception : java.lang.UnsupportedOperationException: Cannot define class using reflection
[info] at org.scalatest.mockito.MockitoSugar.mock(MockitoSugar.scala:73)
[info] at org.scalatest.mockito.MockitoSugar.mock$(MockitoSugar.scala:72)
[info] at XmlMapperTest.mock(XmlMapperTest.scala:7)
[info] at XmlMapperTest.$anonfun$new$1(XmlMapperTest.scala:11)
[info] at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
[info] at org.scalatest.OutcomeOf.outcomeOf(OutcomeOf.scala:85)
[info] at org.scalatest.OutcomeOf.outcomeOf$(OutcomeOf.scala:83)
[info] at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
[info] at org.scalatest.Transformer.apply(Transformer.scala:22)
[info] at org.scalatest.Transformer.apply(Transformer.scala:20)