org.spockframework.mock.CannotCreateMockException: Cannot create mock for class java.time.Instant because Java mocks cannot mock final classes. If the code under test is written in Groovy, use a Groovy mock.

Searched on Google with the first line of a JAVA stack trace?

We can recommend more relevant solutions and speed up debugging when you paste your entire stack trace with the exception message. Try a sample exception.

Recommended solutions based on your search

Samebug tips

Do you know how to solve this issue? Write a tip to help other users and build your expert profile.

Solutions on the web

via GitHub by kurron
, 1 year ago
Cannot create mock for class java.time.Instant because Java mocks cannot mock final classes. If the code under test is written in Groovy, use a Groovy mock.
via GitHub by Derbeth
, 10 months ago
Cannot create mock for class java.util.Optional because Java mocks cannot mock final classes. If the code under test is written in Groovy, use a Groovy mock.
org.spockframework.mock.CannotCreateMockException: Cannot create mock for class java.time.Instant because Java mocks cannot mock final classes. If the code under test is written in Groovy, use a Groovy mock.
at org.spockframework.mock.runtime.JavaMockFactory.create(JavaMockFactory.java:41)
at org.spockframework.mock.runtime.CompositeMockFactory.create(CompositeMockFactory.java:44)
at org.spockframework.lang.SpecInternals.createMock(SpecInternals.java:45)
at org.spockframework.mock.EmptyOrDummyResponse.createDummy(EmptyOrDummyResponse.java:123)
at org.spockframework.mock.EmptyOrDummyResponse.respond(EmptyOrDummyResponse.java:92)
at org.spockframework.mock.runtime.MockController.handle(MockController.java:49)
at org.spockframework.mock.runtime.JavaMockInterceptor.intercept(JavaMockInterceptor.java:72)
at com.transparent.molde.example.core.TemporalAcquisitionService.currentTime(TemporalAcquisitionService.groovy:35)

Users with the same issue

2 times, 8 months ago
Samebug visitor profile picture
Unknown user
Once, 2 years ago

Write tip

Know the solutions? Share your knowledge to help other developers to debug faster.