 (ns codewars.runner
   (:require [codewars.runner :refer [run]]
+            [codewars.clojure.test]
             [clojure.java.io :as io]
             [codewars.util :refer [write-code!]])
   (:import [codewars.java TempDir]

      0
      (throw (IOException. "Java compilation error")))))

(defn- load-class [dir class-name]
  "Load a java class in a specified directory"
  (let [class-loader
        (URLClassLoader/newInstance
         (into-array [(-> dir .toURI .toURL)]))]
    (Class/forName (name class-name) true class-loader)))

(defn- run-junit-tests [fixture-class]
  (let [runner (JUnitCore.)]
    (.addListener runner (CwRunListener.))
    (.run runner (into-array [fixture-class]))))

(defn- file-names [files]
  (for [{:keys [:file-name]} files
        :when (not (nil? file-name))]
    file-name))

  (let [dir (TempDir/create "java")
        setup (when (not (empty? setup)) (write-code! "java" dir setup))
        solution (write-code! "java" dir solution)
        files (file-names setup solution)]
    (apply compile! files)
    (-> solution
        :class-name
