class Test{
override def execute(sqlContext: SQLContext) {
val df: DataFrame = sqlContext.read.parquet(path)
}
How to mock sqlContext.read.parquet ? Need to read from a json and return that dummy dataframe when this is called
class XTest extends FunSuite with MockitoSugar {
test("Test") {
val sparkSession = SparkSession
.builder()
.master("local[*]")
.appName("View_Persistence_Spark_Job")
.getOrCreate()
sparkSession.sparkContext.setLogLevel("ERROR")
val test = new Test()
val df_from_json = sparkSession.read.option("multiline", "true").json("src/test/resources/test.json")
val mockContext = mock[SQLContext]
when(mockContext.read.parquet("src/test/resources/test.json")).thenReturn(df_from_json)
test.execute(sparkSession.sqlContext)