   {:boot/export-tasks true}
   (:require [boot.core :as core])
   (:import org.junit.runner.JUnitCore
+           org.junit.runner.notification.RunListener
            (org.junit.internal JUnitSystem
                                RealSystem)
            (org.reflections Reflections

           (org.reflections.util ClasspathHelper
                                 ConfigurationBuilder
                                 FilterBuilder)))

(defn invoke-private-method [obj fn-name-string & args]
  (let [m (first (filter (fn [x] (.. x getName (equals fn-name-string)))
                         (.. obj getClass getDeclaredMethods)))]
    (. m (setAccessible true))
    (. m (invoke obj (into-array Object args)))))

(defn failure->map [failure]
  {:description (.. failure (getDescription) (toString))

         set
         vec)))

(def run-listener
  (proxy [RunListener]
      []
    (testRunStarted [description]
      (println "Test started!"))
    (testRunFinished [result]
      (println "\nTest run finished!"))
    (testStarted [description]
      (print "."))
    (testFinished [description]
      (print "F"))))

(core/deftask junit
  "Run the jUnit test runner."
  [p packages PACKAGE #{sym} "The set of Java packages to run tests in."]
  (core/with-pre-wrap fileset
    (if (seq packages)
      (let [^JUnitCore core (doto (JUnitCore.)
                              (.addListener run-listener))
            result (.run core
                         (into-array Class
                                     (find-all-tests packages)))]
        (when (> (.getFailureCount result) 0)
          (println (result->map result))))
      (println "No packages were tested."))
    fileset))
