public void testDynamicObjectsRetrival() throws PrologException {
   Prolog engine = new Prolog();
   JavaLibrary lib = (JavaLibrary) engine.getLibrary("alice.tuprolog.lib.JavaLibrary");
   String theory =
       "demo(C) :- \n"
           + "java_object('alice.tuprolog.TestCounter', [], C), \n"
           + "C <- update, \n"
           + "C <- update. \n";
   engine.setTheory(new Theory(theory));
   SolveInfo info = engine.solve("demo(Obj).");
   Struct id = (Struct) info.getVarValue("Obj");
   TestCounter counter = (TestCounter) lib.getRegisteredDynamicObject(id);
   assertEquals(2, counter.getValue());
 }
 public void testAnonymousObjectRegistration()
     throws InvalidTheoryException, InvalidObjectIdException {
   JavaLibrary lib = (JavaLibrary) engine.getLibrary("alice.tuprolog.lib.JavaLibrary");
   String theory = "demo(X) :- X <- update. \n";
   engine.setTheory(new Theory(theory));
   TestCounter counter = new TestCounter();
   // check registering behaviour
   Struct t = lib.register(counter);
   engine.solve(new Struct("demo", t));
   assertEquals(1, counter.getValue());
   // check unregistering behaviour
   lib.unregister(t);
   SolveInfo goal = engine.solve(new Struct("demo", t));
   assertFalse(goal.isSuccess());
 }
  public void test_unregister_1() throws PrologException, IOException {
    // Test invalid object_id unregistration
    theory = "demo(Obj1) :- unregister(Obj1).";
    engine.setTheory(new Theory(theory));
    info = engine.solve("demo(Res).");
    assertEquals(true, info.isHalted());

    setPath(true);
    theory =
        "demo(Obj) :- \n"
            + "java_object('Counter', [], Obj,["
            + paths
            + "]), \n"
            + "Obj <- inc, \n"
            + "Obj <- inc, \n"
            + "register(Obj), unregister(Obj).";
    engine.setTheory(new Theory(theory));
    info = engine.solve("demo(Res).");
    assertEquals(true, info.isSuccess());
    JavaLibrary lib = (JavaLibrary) engine.getLibrary("alice.tuprolog.lib.JavaLibrary");
    Struct id = (Struct) info.getTerm("Res");
    Object obj = lib.getRegisteredObject(id);
    assertNull(obj);
  }