В мире Java то, что вы просили, обычно делается с помощью делегирования и интерфейсов.
Я бы создал интерфейс (java), который соответствует один к одному с API, который есть в библиотеке js, а затем создал бы простую реализацию этого интерфейса.
Ваш код обёртки затем оборачивает интерфейс. Во время тестирования вы заменяете реализацию этого интерфейса своей собственной, где каждый метод просто подтверждает, вызван он или нет.
1007 * Е.Г. *
custom.lib.js has these exported methods/objects:
var exports = {
method1: function(i) {...},
method2: function() {...},
...etc
}
your custom interface:
public interface CustomLib {
String method1(int i);
void method2();
//...etc etc
}
your simple impl of CustomLib:
public class CustomLibImpl implements CustomLib {
public CustomLibImpl() {
initJS();
}
private native void initJS()/*-{
//...init the custom lib here, e.g.
$wnd.YOUR_NAME_SPACE.customlib = CUSTOMLIB.newObject("blah", 123, "fake");
}-*/;
public native String method1(int i)/*-{
return $wnd.YOUR_NAME_SPACE.customlib.method1(i);
}-*/;
void method2()/*-{
$wnd.YOUR_NAME_SPACE.customlib.method2();
}-*/;
//...etc etc
}
then in your Wrapper class:
public class Wrapper {
private CustomLib customLib;
public Wrapper(CustomLib customLib ) {
this.customLib = customLib;
}
public String yourAPIMethod1(int i) {
return customLib.method1(i);
}
///etc for method2()
}
your test:
public class YourCustomWrapperTest {
Wrapper wrapper;
public void setup() {
wrapper = new Wrapper(new CustomLib() {
//a new impl that just do asserts, no jsni, no logic.
public String method1(int i) {assertCalledWith(i);}
public void method2() {assertNeverCalledTwice();}
//etc with other methods
});
}
public void testSomething() { wrapper.yourAPIMethod1(1);}
}