null ptr during unit testing

I'm running into this problem when running my unit test. The code causing this is just creating a notification:

java.lang.NullPointerException was thrown.
    at com.intellij.notification.Notifications$Bus.notify(
    at com.intellij.notification.Notifications$Bus.notify(
    at org.scalaideaextension.eventlog.EventLog$.info(EventLog.scala:28)
    at org.scalaideaextension.eventlog.EventLog$.info(EventLog.scala:17)
    at org.kostaskougios.idea.scripts.ScriptsManager$$anonfun$2.apply(ScriptsManager.scala:47)

This is the failing code:

      if (ApplicationManager.getApplication().isUnitTestMode()) {

ApplicationManager.getApplication() is null

I setup my env like this:

    val factory = IdeaTestFixtureFactory.getFixtureFactory
    val builder = factory.createFixtureBuilder("ScriptsManagerSuite")
    val insightFixture = factory.createCodeInsightFixture(builder.getFixture)
and then test my code which in turn works ok up to the point where it creates a notification:

        val notification = new Notification("scala-idea-extensions", title, msg, NotificationType.INFORMATION)

Any ideas how to create the application during initialization of my tests?


Comment actions Permalink

it seems the testing API of intellij works only if it runs with some junit runner. To resolve this issue, and since I run my tests using scala test, I had to do the following:

- create this class that extends the base junit class for intellij :

class TestSetup(name: String) extends JavaCodeInsightFixtureTestCase

    override def getName = name

    def init() {

    def done() {

    override def getHomePath = {
        val tmpDir = System.getProperty("")
        val home = new File(tmpDir, "idea-tests-home-path")

- from my scalatest suites I had to init() and done() that class:

    var setup: TestSetup = _

    override protected def beforeAll() {
        setup = new TestSetup(getClass.getSimpleName)

    override protected def afterAll() {

- my scalatest has to run via the junit runner :


Now it works, a workaround but couldn't find a better way.

Comment actions Permalink

Hi Konstantinos,

You don't have to run your tests under JUnit - I do all my testing with the fixtures. Here's my init code - it's in Clojure, but hopefully you can see what's going on well enough:

defn idea-test-fixture [& {:as args}]
  (fn [f]
    (.setLevel (Logger/getRootLogger) Level/WARN)
    (let [factory (IdeaTestFixtureFactory/getFixtureFactory)
          descriptor (proxy [DefaultLightProjectDescriptor] []
                       (getSdk []
                         (-> (JavaSdk/getInstance)
                             (.createJdk "1.7" (TestUtils/getMockJdk) false))))
          builder (.createLightFixtureBuilder factory descriptor)
          fixture (.getFixture builder)
          tmp-dir-fixture (LightTempDirTestFixtureImpl. true)
          java-factory (JavaTestFixtureFactory/getFixtureFactory)
          test-fixture (.createCodeInsightFixture java-factory fixture tmp-dir-fixture)]
      (if-let [inspections (:inspections args)]
        (.enableInspections test-fixture ^"[Ljava.lang.Class;" (into-array Class inspections)))
      (.setUp test-fixture)
        (if-let [libraries (:libraries args)]
          (doseq [library libraries]
            (add-library (.getModule test-fixture) library)))
        (binding [*fixture* test-fixture]
          (if-let [files (:files args)]
            (doseq [[path text] files]
              (add-file path text)))
          (if-let [classes (:classes args)]
            (doseq [text classes]
              (.addClass test-fixture text)))
          (.tearDown test-fixture))))))
Comment actions Permalink

Thanks, my code is similar, maybe without the


But are you running this code using the junit runner?


Please sign in to leave a comment.