In our SmartGWT web application, we pass our domain objects from the server to the client and back (via GWT serialization). To show/edit the data at client side in a DynamicForm or a GridList, we have to convert it into a Record (or ListGridRecord) and after editing back into our domain objects.
I would like to write a unit test for this conversion method, but a straightforward attempt in JUnit fails, since the record's getAttribute
and setAttribute
methods are implemented by JSOHelper.getAttribute
/JSOHelper.setAttribute
, which are static methods declared as native
and implemented by JSNI in JavaScript, thus only usable on the client side, when compiled to JavaScript.
We get an UnsatisfiedLinkError when using these methods from JUnit, as the native methods are not implemented there.
Any ideas how I could test these classes?
These critical methods could be easily implemented by a simple HashMap (or maybe a LinkedHashMap, if the attribute order is important) - actually a JavaScript object is about that, if only looking at the data part, not the methods. Thus I just think about providing an alternative implementation of some selected SmartGWT classes (mainly JSOHelper) with Java implementations instead of the JavaScript ones.
But am I really the first one who has this problem? Am I simply too stupid to find the existing solution?
If you have used a MVP or MVC pattern in your code, just mock the view code with something like mockito and test all the rest of the application. To test the view code you will need to use something like Selinium I don't think gwtTestCase would work with smartGWT since it is just a gwt wrapper around js code.