You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We develop in OSGi environment and we are using latest version of mockito available on maven central 2.23.4
We got an issue when we mock classes given to guice (sisu) for injection. Sisu/Guice analyse all declared fields and methods for the input type and its super classes to built a sort of index of known types. In OSGi it fails with ClassNotFoundException on mocked classes. The reason is that the mocked class built with SubclassBytecodeGenerator has a classloader not able to load types reachable only by supertypes. In OSGi this does not happen because each class has associated the classloader from which is loaded. This guarantee that the class is able to reach/load each type it declares (by its methods, fields or annotations).
Example:
Bundle A foo.Class1 has a protected method that returns foo.impl.OtherClass foo.impl.OtherClass
Bundle B (imports only foo package from bundle A) acme.Class2 extends Class1
Mockito.mock(foo.Class1).getDeclaredMethods() will fails. To fix this issue SubclassBytecodeGenerator should compose a classloader (MultipleParentClassLoader) with also the classloader of superclass the mocked type (features.mockedType).
The text was updated successfully, but these errors were encountered:
We develop in OSGi environment and we are using latest version of mockito available on maven central 2.23.4
We got an issue when we mock classes given to guice (sisu) for injection. Sisu/Guice analyse all declared fields and methods for the input type and its super classes to built a sort of index of known types. In OSGi it fails with ClassNotFoundException on mocked classes. The reason is that the mocked class built with
SubclassBytecodeGenerator
has a classloader not able to load types reachable only by supertypes. In OSGi this does not happen because each class has associated the classloader from which is loaded. This guarantee that the class is able to reach/load each type it declares (by its methods, fields or annotations).Example:
Bundle A
foo.Class1
has a protected method that returns foo.impl.OtherClassfoo.impl.OtherClass
Bundle B (imports only
foo
package from bundle A)acme.Class2 extends Class1
Mockito.mock(foo.Class1).getDeclaredMethods()
will fails. To fix this issueSubclassBytecodeGenerator
should compose a classloader (MultipleParentClassLoader
) with also the classloader of superclass the mocked type (features.mockedType
).The text was updated successfully, but these errors were encountered: