Search code examples
gwtnative-methodsgwttestcase

Test JsonUtils in GWTTestCase


I want to create some testcase to see if my JSON parsing classes work correct. Therefore I want to instantiate them with a JavaScript object which I create form a JSON String throw the JsonUtils.

My problem now is that, JsonUtils is a native method, so there is now source code available for it, during testing.

Is there a possibility to built GwtTestCases which include native methods?


Solution

  • Ok, after writting the question I got some new ideas to google and found this article: UnsatisfiedLinkError in GWTTestCase. Options.

    So apperently you just cant use native methods in the GWTTestCase constructur, but you can use them inside the test function.

    Example illeagal:

    JSWidgetBasic jswb;
    public JSWidgetBasicTest() {
        String s_jswb = "{\"zzzz\":\"type\"}";
        jswb = JsonUtils.safeEval(s_jswb).cast();
    }
    
    public void testWidgetType() {
        assert (jswb.getZZZZ().compareTo("type") == 0);
    }
    

    but this is allowed

    public JSWidgetBasicTest() {
    }
    
    public void testWidgetType() {
        String s_jswb = "{\"zzzz\":\"type\"}";
        JSWidgetBasic jswb = JsonUtils.safeEval(s_jswb).cast();
    
        assert (jswb.getZZZZ().compareTo("type") == 0);
    }
    

    Hope this helps someboedy, cause I wasted a few hours finding it....