Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not able to update mockito version #7618

Closed
imod opened this issue Dec 11, 2016 · 2 comments
Closed

not able to update mockito version #7618

imod opened this issue Dec 11, 2016 · 2 comments
Labels
status: duplicate A duplicate of another issue

Comments

@imod
Copy link

imod commented Dec 11, 2016

This little example works fine with the current default mockito version (1.10.19) used by spring-boot.

@RunWith(SpringRunner.class)
public class DummyTest {

	@MockBean
	private Dummy dummyMock;

	@Test
	public void testDummy() {
		when(dummyMock.getIt()).thenReturn("AA");
		assertNotNull(dummyMock.getIt());
	}

	public static interface Dummy {
		public String getIt();
	}

}

upgrading mockito to any higher version (e.g. 2.2.29) will cause this test to fail with this exception:

java.lang.IllegalAccessError: tried to access method org.mockito.internal.util.MockUtil.<init>()V from class org.springframework.boot.test.mock.mockito.MockReset
	at org.springframework.boot.test.mock.mockito.MockReset.<clinit>(MockReset.java:56)
	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 java.lang.Class.getEnumConstantsShared(Class.java:3320)
	at java.lang.Class.enumConstantDirectory(Class.java:3341)
	at java.lang.Enum.valueOf(Enum.java:232)
	at sun.reflect.annotation.AnnotationParser.parseEnumValue(AnnotationParser.java:483)
	at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:347)
	at java.lang.reflect.Method.getDefaultValue(Method.java:605)
	at sun.reflect.annotation.AnnotationType.<init>(AnnotationType.java:128)
	at sun.reflect.annotation.AnnotationType.getInstance(AnnotationType.java:85)
	at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:266)
	at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120)
	at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72)
	at java.lang.reflect.Field.declaredAnnotations(Field.java:1150)
	at java.lang.reflect.Field.declaredAnnotations(Field.java:1148)
	at java.lang.reflect.Field.getDeclaredAnnotations(Field.java:1139)
	at java.lang.reflect.AccessibleObject.getAnnotations(AccessibleObject.java:207)
	at org.junit.runners.model.FrameworkField.getAnnotations(FrameworkField.java:31)
	at org.junit.runners.model.TestClass.addToAnnotationLists(TestClass.java:84)
	at org.junit.runners.model.TestClass.scanAnnotatedMembers(TestClass.java:71)
	at org.junit.runners.model.TestClass.<init>(TestClass.java:57)
	at org.junit.runners.ParentRunner.createTestClass(ParentRunner.java:88)
	at org.junit.runners.ParentRunner.<init>(ParentRunner.java:83)
	at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:65)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:138)
	at org.springframework.test.context.junit4.SpringRunner.<init>(SpringRunner.java:49)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
	at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
	at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
	at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
	at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
	at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
	at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:84)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:70)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

Specially for Kotlin users it would be great to be able to update, because with Mockito 2 org.mockito.plugins.MockMaker was introduced to simplify mocking of final classes in Java and consequently all classes and member functions in Kotlin.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 11, 2016
@imod
Copy link
Author

imod commented Dec 11, 2016

a link describing the use of org.mockito.plugins.MockMaker http://hadihariri.com/2016/10/04/Mocking-Kotlin-With-Mockito/

@imod
Copy link
Author

imod commented Dec 12, 2016

already fixed with #6520

@imod imod closed this as completed Dec 12, 2016
@snicoll snicoll added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants