version 1.7.0RC2 IllegalAccessError #753

Closed
AhmedHORMAL opened this Issue Feb 15, 2017 · 11 comments

Comments

Projects
None yet
4 participants
@AhmedHORMAL

AhmedHORMAL commented Feb 15, 2017

I use powermockito for mocking private method.

My test class has following annotations :

@RunWith( PowerMockRunner.class ) @PrepareForTest( DocumentsService.class )

My Test method has following code:

@Test
public void shouldGenerateOnePDF() throws Exception {

	final ZipToSend zipToSend = buildZipToSend("Content", "00P26000002", MediaType.PDF);
	final DocumentsService spy = PowerMockito.spy(new DocumentsService());

	PowerMockito.doNothing().when(spy, MemberMatcher.method(DocumentsService.class, "generateIndexXMLDocumentFromAgregat", String.class, Agregat.class)).withArguments(Mockito.anyString(), Mockito.any(Agregat.class));

	spy.generateZipFromZipToSend(zipToSend, TEST_DIR_PATH, TEST_DIR_NAME);
	Assert.assertTrue(new File(TEST_DIR_PATH + "/" + TEST_DIR_NAME).exists());

}`

My test pass with 1.6.6 but not with 1.7.0RC2
Here is the stack trace of the error:

java.lang.IllegalAccessError: tried to access method org.mockito.internal.stubbing.answers.DoesNothing.<init>()V from class org.powermock.api.mockito.PowerMockito at org.powermock.api.mockito.PowerMockito.doNothing(PowerMockito.java:743) at fr.myPackage.shouldGenerateOnePDF(DocumentsServiceTest.java:219) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:68) at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:310) at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:89) at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:97) at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:294) at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTestInSuper(PowerMockJUnit47RunnerDelegateImpl.java:131) at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.access$100(PowerMockJUnit47RunnerDelegateImpl.java:59) at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner$TestExecutorStatement.evaluate(PowerMockJUnit47RunnerDelegateImpl.java:147) at org.assertj.core.api.JUnitSoftAssertions$1.evaluate(JUnitSoftAssertions.java:44) at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.evaluateStatement(PowerMockJUnit47RunnerDelegateImpl.java:107) at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTest(PowerMockJUnit47RunnerDelegateImpl.java:82) at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:282) at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:87) at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:50) at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:202) at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:144) at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.run(PowerMockJUnit44RunnerDelegateImpl.java:118) at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34) at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44) at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:120) at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:121) at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53) at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

@thekingnothing

This comment has been minimized.

Show comment
Hide comment
@thekingnothing

thekingnothing Feb 15, 2017

Member

Which version of mockito do you use?

Member

thekingnothing commented Feb 15, 2017

Which version of mockito do you use?

@AhmedHORMAL

This comment has been minimized.

Show comment
Hide comment
@AhmedHORMAL

AhmedHORMAL Feb 15, 2017

I'm using version 2.7.5 of mockito !

AhmedHORMAL commented Feb 15, 2017

I'm using version 2.7.5 of mockito !

@thekingnothing

This comment has been minimized.

Show comment
Hide comment
@thekingnothing

thekingnothing Feb 17, 2017

Member

Thank you for reporting the issue. I'll look into. @gstamac, maybe you will have a time to check the issue.

Member

thekingnothing commented Feb 17, 2017

Thank you for reporting the issue. I'll look into. @gstamac, maybe you will have a time to check the issue.

@emmaLP

This comment has been minimized.

Show comment
Hide comment
@emmaLP

emmaLP Mar 1, 2017

Contributor

The problem occurs because you cannot directly instantiate DoesNothing class. The constructor is set to private. This would need to change to call the static method to get an instance.

The following method currently looks like this:

public static PowerMockitoStubber doNothing() {
    return POWERMOCKITO_CORE.doAnswer(new DoesNothing());
}

but it should be changed to:

public static PowerMockitoStubber doNothing() {
    return POWERMOCKITO_CORE.doAnswer(DoesNothing.doesNothing());
}
Contributor

emmaLP commented Mar 1, 2017

The problem occurs because you cannot directly instantiate DoesNothing class. The constructor is set to private. This would need to change to call the static method to get an instance.

The following method currently looks like this:

public static PowerMockitoStubber doNothing() {
    return POWERMOCKITO_CORE.doAnswer(new DoesNothing());
}

but it should be changed to:

public static PowerMockitoStubber doNothing() {
    return POWERMOCKITO_CORE.doAnswer(DoesNothing.doesNothing());
}
@thekingnothing

This comment has been minimized.

Show comment
Hide comment
@thekingnothing

thekingnothing Mar 1, 2017

Member

@emmaLP, thank you for investigating the issue.

It will be amazing if you have a time to provide a pull request with changes.

Member

thekingnothing commented Mar 1, 2017

@emmaLP, thank you for investigating the issue.

It will be amazing if you have a time to provide a pull request with changes.

emmaLP added a commit to emmaLP/powermock that referenced this issue Mar 1, 2017

#753 issue fix to upgrade code to be compatible with later versions …
…of Mockito

- Updated the Mockito version to a more later version
- Fixed issues with imports
-Updated version to 1.7.0RC4
@emmaLP

This comment has been minimized.

Show comment
Hide comment
@emmaLP

emmaLP Mar 1, 2017

Contributor

Pull request: #759

Contributor

emmaLP commented Mar 1, 2017

Pull request: #759

thekingnothing added a commit that referenced this issue Mar 1, 2017

#753 issue fix to upgrade code to be compatible with later versions …
…of Mockito

- Updated the Mockito version to a more later version
- Fixed issues with imports
-Updated version to 1.7.0RC4
@thekingnothing

This comment has been minimized.

Show comment
Hide comment
@thekingnothing

thekingnothing Mar 1, 2017

Member

@emmaLP, thank you a lot for help! I've merged your pull request.

Member

thekingnothing commented Mar 1, 2017

@emmaLP, thank you a lot for help! I've merged your pull request.

@emmaLP

This comment has been minimized.

Show comment
Hide comment
@emmaLP

emmaLP Mar 2, 2017

Contributor

Do you have an ETA of when this will be released?

Contributor

emmaLP commented Mar 2, 2017

Do you have an ETA of when this will be released?

@thekingnothing

This comment has been minimized.

Show comment
Hide comment
@thekingnothing

thekingnothing Mar 2, 2017

Member
Member

thekingnothing commented Mar 2, 2017

emmaLP added a commit to emmaLP/powermock that referenced this issue Mar 2, 2017

Merge pull request #1 from emmaLP/bugs/753
#753 issue fix to upgrade code to be compatible with later versions o…
@thekingnothing

This comment has been minimized.

Show comment
Hide comment
@thekingnothing

thekingnothing Mar 5, 2017

Member

@emmaLP, I've just dropped PowerMock 1.7.0.RC4 release.

Member

thekingnothing commented Mar 5, 2017

@emmaLP, I've just dropped PowerMock 1.7.0.RC4 release.

@hazems

This comment has been minimized.

Show comment
Hide comment
@hazems

hazems Apr 8, 2017

@thekingnothing You are a life saver.

hazems commented Apr 8, 2017

@thekingnothing You are a life saver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment