package coa.droid_test.internal;

import clojure.lang.IFn;
import clojure.lang.Symbol;
import clojure.java.api.Clojure;
import java.util.ArrayList;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import java.util.List;

@RunWith(TestRunner.class)
public class ReplWrapper {

    @Test
    public void nreplStarter() {
        try {
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
            IFn require = Clojure.var("clojure.core", "require");

            require.invoke(Clojure.read("clojure.tools.nrepl.server"));
            IFn startServer = Clojure.var("clojure.tools.nrepl.server",
                                          "start-server");
            startServer.invoke();
            // IFn getImports = Clojure.var("coa.droid-test.internal.util",
            //                              "extract-imports");

            // require.invoke(Clojure.read("clojure.test"));

            // ArrayList<Symbol> namespaces = new ArrayList<Symbol>();
            // for (String ns : TestRunner.getTestNamespaces()) {
            //     Symbol nsSym = Symbol.intern(null, ns);
            //     List<String> imports = (List<String>)getImports.invoke(loader, ns);
            //     for (String classname : imports) {
            //         Class.forName(classname, true, loader);
            //     }
            //     require.invoke(nsSym);
            //     namespaces.add(nsSym);
            // }

            // IFn runTests = Clojure.var("clojure.test", "run-tests");
            // IFn apply = Clojure.var("clojure.core", "apply");
            // apply.invoke(runTests, namespaces);
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }

}

@@ -71,80 +71,24 @@
 ure.
-lang.Symbol;%0Aimport clojure.java.api.Clojure;%0Aimport java.util.ArrayList
+java.api.Clojure
 ;%0Aim
@@ -187,31 +187,8 @@
 ent;
-%0Aimport java.util.List;
 %0A%0A@R
@@ -313,76 +313,67 @@
     
-ClassLoader loader = Thread.currentThread().getContextClassLoader();
+Util.importNsDeclarations(TestRunner.getTestNamespaces());%0A
 %0A   
@@ -431,25 +431,24 @@
 %22require%22);%0A
-%0A
             
@@ -673,922 +673,107 @@
 oke(
-);%0A            // IFn getImports = Clojure.var(%22coa.droid-test.internal.util%22,%0A            //                              %22extract-imports%22);%0A%0A            // require.invoke(Clojure.read(%22clojure.test%22));%0A%0A            // ArrayList%3CSymbol%3E namespaces = new ArrayList%3CSymbol%3E();%0A            // for (String ns : TestRunner.getTestNamespaces()) %7B%0A            //     Symbol nsSym = Symbol.intern(null, ns);%0A            //     List%3CString%3E imports = (List%3CString%3E)getImports.invoke(loader, ns);%0A            //     for (String classname : imports) %7B%0A            //         Class.forName(classname, true, loader);%0A            //     %7D%0A            //     require.invoke(nsSym);%0A            //     namespaces.add(nsSym);%0A            // %7D%0A%0A            // IFn runTests = Clojure.var(%22clojure.test%22, %22run-tests%22);%0A            // IFn apply = Clojure.var(%22clojure.core%22, %22apply%22);%0A            // apply.invoke(runTests, namespaces
+Clojure.read(%22:port%22), 8888);%0A            System.out.println(%22Started nREPL server on port %22 + 8888
 );%0A 

Make ReplWrapper work