eclipse-emfcloud / emfcloud-modelserver

Modelserver component
Other
41 stars 21 forks source link

Mocking WsContext.pathParam sometimes results in WrongTypeOfReturnValue exception #63

Closed martin-fleck-at closed 3 years ago

martin-fleck-at commented 3 years ago

Since updating to the latest version of Kotlin in https://github.com/eclipse-emfcloud/emfcloud-modelserver/pull/56 the JUnit tests seem to fail sometimes with the following error:

org.mockito.exceptions.misusing.WrongTypeOfReturnValue: 
String cannot be returned by pathParam()
pathParam() should return Validator
***
If you're unsure why you're getting above error read on.
Due to the nature of the syntax above problem might occur because:
1. This exception *might* occur in wrongly written multi-threaded tests.
   Please refer to Mockito FAQ on limitations of concurrency testing.
2. A spy is stubbed using when(spy.foo()).then() syntax. It is safer to stub spies - 
   - with doReturn|Throw() family of methods. More in javadocs for Mockito.spy() method.

    at org.eclipse.emfcloud.modelserver.emf.common.SessionControllerTest.initializeWsMessageContext(SessionControllerTest.java:190)
    at org.eclipse.emfcloud.modelserver.emf.common.SessionControllerTest.testSubscribeAndSendKeepAlive(SessionControllerTest.java:159)

After investigating that for a bit, it seems that there was a change that marked the method pathParam with @JvmSynthetic to might have fixed that but did not in our case: https://github.com/tipsy/javalin/commit/be8910b3e867e1662663fbedb4e914c4262aff64.

There are already some open issues related to this:

The problem should be investigated and fixed, either by re-writing the mocking code, downgrading to a Javalin version that works (previously we used 3.1.0) of finding another way to get the test cases to run properly.

martin-fleck-at commented 3 years ago

For the moment, we downgraded to Javalin version 3.1.0 again in this commit to avoid the mocking problems that prevent the tests from running successful. In the long term, however, we should upgrade to a newer Javalin version. I therefore close this issue and created a follow-up issue to monitor the situation to upgrade eventually.