Mokito cannot mock Unmarshaller-dependent class

This class is Foo:

public class Foo {
  private Unmarshaller unmarshaller;
  public Foo(Unmarshaller unmarshaller) {}
}

The following tests failed:

@Test
public void test() {
  Foo packagingJobSource2 = mock(Foo.class);
}

... with an error:

org.mockito.exceptions.base.MockitoException: 
Mockito cannot mock this class: class com.bell.cts.fonse.vod.streaming.services.adapter.cron.avcm.packagingjob.loading.xmlstorage.Foo.

Mockito can only mock non-private & non-final classes.
If you're not sure why you're getting this error, please report to the mailing list.


Java               : 9
JVM vendor name    : Oracle Corporation
JVM vendor version : 9.0.1+11
JVM name           : Java HotSpot(TM) 64-Bit Server VM
JVM version        : 9.0.1+11
JVM info           : mixed mode
OS name            : Mac OS X
OS version         : 10.13.2

I tried using JDK 8 instead of 9 and it works fine. I don’t know why this will fail, and not how I can do this work.

The problem arises when it Unmarshalleris addiction. If you change it to another type, for example String, it works ...

+4
source share
1 answer

The likely reason for the same is that it is module java.xml.bindnot allowed by default. when you compile or run code in CLASSPATH .

Java Platform Module System (JPMS), (1), , VM arg :

--add-modules java.xml.bind
+4

Source: https://habr.com/ru/post/1691064/


All Articles