title: Mocking SparkSession for unit testing
body: <p>I have a method in my spark application that loads the data from a MySQL database. the method looks something like this.</p>
  
  <pre><code>trait DataManager {
  
  val session: SparkSession
  
  def loadFromDatabase(input: Input): DataFrame = {
              session.read.jdbc(input.jdbcUrl, s"(${input.selectQuery}) T0",
                input.columnName, 0L, input.maxId, input.parallelism, input.connectionProperties)
      }
  }
  </code></pre>
  
  <p>The method does nothing else other than executing <code>jdbc</code> method and loads data from the database. How can I test this method? The standard approach is to create a mock of the object <code>session</code> which is an instance of <code>SparkSession</code>. But since <code>SparkSession</code> has a private constructor I was not able to mock it using ScalaMock. </p>
  
  <p>The main ask here is that my function is a pure side-effecting function (the side-effect being pull data from relational database) and how can i unit test this function given that I have issues mocking <code>SparkSession</code>.</p>
  
  <p>So is there any way I can mock <code>SparkSession</code> or any other better way than mocking to test this method? </p>