Getting Buffered$SourceException in unit test but not in production code

I have a view with the following field

ObjectProperty<Double> balance = new ObjectProperty<Double>(0.0); connected to a TextField.

When actually running the code everything works, and when creating the AdminView from unit tests in
UkelonnUITest
the AdminView constructor can be run without causing an exception.

But when I tried to create a unit test for the AdminView, class the AdminView constructor failed with a Buffered$SourceException in the view constructor:

Caused by: com.vaadin.data.util.converter.Converter$ConversionException: Unable to convert value of type java.lang.Double to presentation type class java.lang. String. No converter is set and the types are not compatible. The test failed here (setting the property datasource on the text field):
https://github.com/steinarb/ukelonn/blob/work/use-liquibase/ukelonn.bundle/src/main/java/no/priv/bang/ukelonn/impl/AdminView.java#L151

Is some global initialization missing from my unit test?
The
UkelonnUITest
does
a lot of initialization
, but I don’t know what might be significiant for AdminView.

Thanks!

  • Steinar

When I run all tests in
https://github.com/steinarb/ukelonn/tree/work/use-liquibase/ukelonn.bundle/src/test/java/no/priv/bang/ukelonn
and subdirectories, the tests run green, including my previously failing AdminViewTest.

So something in my test setup is sufficient to set up the stuff that is missing when I run the AdminViewTest on its own. I have tried to copy in stuff from the working tests, but I haven’t found anything that works yet.

What was needed, was to create a Session object and call Session.setCurrent() with the session, before creating the AdminView.

I only needed to create the Session once before the tests were run, so I could put it in the static @BeforeClass method:

@BeforeClass public static void beforeAllTests() throws ServletException, ServiceException { setupFakeOsgiServices(); session = createSession(); } @Test public void testUpdateFormsAfterAccountIsSelected() throws ServiceException, ServletException { VaadinSession.setCurrent(session); VaadinRequest request = createMockVaadinRequest("http://localhost:8181/ukelonn/"); AdminView view = new AdminView(request); The code is
here