ALL-UNNAMED module does not export all packages from classpath
Libor Kramolis
libor.kramolis at oracle.com
Mon Mar 20 21:15:29 UTC 2017
Hello.
I have problem to compile following unit test:
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class TestCase {
@Test
public void test() {
Context context = mock(Context.class);
when(context.test(any())) //returns org.mockito.stubbing.OngoingStubbing
.thenReturn("mock");
assertEquals("mock", context.test("any"));
}
interface Context {
String test(String value);
}
}
with following error:
src/test/java/tst/TestCase.java:15: error: OngoingStubbing.thenReturn(T,T...) in package org.mockito.stubbing is not accessible
.thenReturn("mock");
^
(package org.mockito.stubbing is declared in module , which does not export it)
where T is a type-variable:
T extends Object declared in interface OngoingStubbing
1 error
Interface org.mockito.stubbing.OngoingStubbing is returned by when(…) method. And whenever I explicitly import the interface (no other change in code is necessary) compilation works.
Full reproduced sources are available in zip file at http://anise.cz/~paja/liba/reproducer.zip <http://anise.cz/~paja/liba/reproducer.zip>. It contains javac commands. It is also possible to build it by Maven.
What do you think about this behaviour? It seems to me as a bug. The import statement is very artificial in this case.
Thanks in advance for your help.
Best regards,
Libor
More information about the jdk9-dev
mailing list