org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cityService' defined in file [/Users/pwebb/projects/spring-boot/samples/spring-boot-issue-6871/target/classes/com/example/CityService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cityRepository': Post-processing of FactoryBean's singleton object failed; nested exception is org.mockito.exceptions.base.MockitoException: Cannot mock/spy class com.example.$Proxy81 Mockito cannot mock/spy following: - final classes - anonymous classes - primitive types

GitHub | philwebb | 2 months ago
  1. 0

    GitHub comment 7033#252793702

    GitHub | 2 months ago | philwebb
    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cityService' defined in file [/Users/pwebb/projects/spring-boot/samples/spring-boot-issue-6871/target/classes/com/example/CityService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cityRepository': Post-processing of FactoryBean's singleton object failed; nested exception is org.mockito.exceptions.base.MockitoException: Cannot mock/spy class com.example.$Proxy81 Mockito cannot mock/spy following: - final classes - anonymous classes - primitive types
  2. 0

    Answered Question: How to easily test java classes? (5 answers)

    askto.net | 8 months ago
    org.mockito.exceptions.base.MockitoException: Cannot mock/spy class java.lang.String Mockito cannot mock/spy following: - final classes - anonymous classes - primitive types
  3. 0

    Unable to mock final and private classes when using @PowerMockRunnerDelegate(PowerMockRunner.class)

    GitHub | 1 year ago | johanhaleby
    org.mockito.exceptions.base.MockitoException: Cannot mock/spy class com.eibus.soap.SOAPTransaction Mockito cannot mock/spy following: - final classes - anonymous classes - primitive types
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    How to mock an Object in Scala

    Stack Overflow | 1 year ago | Bogdan Drachinskiy
    org.mockito.exceptions.base.MockitoException: Cannot mock/spy class Mockito cannot mock/spy following: - final classes - anonymous classes - primitive types
  6. 0

    How to Mock YearMonth in java 8

    Stack Overflow | 3 days ago | sjc_w
    org.mockito.exceptions.base.MockitoException: Cannot mock/spy class java.time.YearMonth Mockito cannot mock/spy following: - final classes - anonymous classes - primitive types

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. org.mockito.exceptions.base.MockitoException

      Cannot mock/spy class com.example.$Proxy81 Mockito cannot mock/spy following: - final classes - anonymous classes - primitive types

      at org.springframework.boot.test.mock.mockito.SpyDefinition.createSpy()
    2. org.springframework.boot
      MockitoPostProcessor$SpyPostProcessor.postProcessAfterInitialization
      1. org.springframework.boot.test.mock.mockito.SpyDefinition.createSpy(SpyDefinition.java:99)[classes/:na]
      2. org.springframework.boot.test.mock.mockito.MockitoPostProcessor.createSpyIfNecessary(MockitoPostProcessor.java:332)[classes/:na]
      3. org.springframework.boot.test.mock.mockito.MockitoPostProcessor$SpyPostProcessor.createSpyIfNecessary(MockitoPostProcessor.java:490)[classes/:na]
      4. org.springframework.boot.test.mock.mockito.MockitoPostProcessor$SpyPostProcessor.postProcessAfterInitialization(MockitoPostProcessor.java:486)[classes/:na]
      4 frames
    3. Spring Beans
      DefaultListableBeanFactory.preInstantiateSingletons
      1. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:422)[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      2. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.postProcessObjectFromFactoryBean(AbstractAutowireCapableBeanFactory.java:1728)[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      3. org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:113)[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      4. org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1600)[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      5. org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:317)[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      6. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      7. org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:207)[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      8. org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1128)[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      9. org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1056)[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      10. org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835)[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      11. org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      12. org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:189)[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      13. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1148)[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      14. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1051)[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      15. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      16. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      17. org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      18. org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      19. org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      20. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      21. org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:751)[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      21 frames
    4. Spring Context
      AbstractApplicationContext.refresh
      1. org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      2. org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      2 frames
    5. Spring Boot
      SpringApplication.run
      1. org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761)[classes/:na]
      2. org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371)[classes/:na]
      3. org.springframework.boot.SpringApplication.run(SpringApplication.java:315)[classes/:na]
      3 frames
    6. org.springframework.boot
      SpringBootContextLoader.loadContext
      1. org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:111)[classes/:na]
      1 frame
    7. org.springframework.test
      DefaultCacheAwareContextLoaderDelegate.loadContext
      1. org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)[spring-test-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      2. org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)[spring-test-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      2 frames
    8. Spring TestContext
      SpringJUnit4ClassRunner$1.runReflectiveCall
      1. org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)[spring-test-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      2. org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:189)[spring-test-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      3. org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:131)[spring-test-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      4. org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)[spring-test-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      5. org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:228)[spring-test-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      6. org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287)[spring-test-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      6 frames
    9. JUnit
      ReflectiveCallable.run
      1. org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)[junit-4.12.jar:4.12]
      1 frame
    10. Spring TestContext
      SpringJUnit4ClassRunner.runChild
      1. org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289)[spring-test-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      2. org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247)[spring-test-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      3. org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)[spring-test-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      3 frames
    11. JUnit
      ParentRunner$2.evaluate
      1. org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)[junit-4.12.jar:4.12]
      2. org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)[junit-4.12.jar:4.12]
      3. org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)[junit-4.12.jar:4.12]
      4. org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)[junit-4.12.jar:4.12]
      5. org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)[junit-4.12.jar:4.12]
      5 frames
    12. Spring TestContext
      RunAfterTestClassCallbacks.evaluate
      1. org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)[spring-test-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      2. org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)[spring-test-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      2 frames
    13. JUnit
      ParentRunner.run
      1. org.junit.runners.ParentRunner.run(ParentRunner.java:363)[junit-4.12.jar:4.12]
      1 frame
    14. Spring TestContext
      SpringJUnit4ClassRunner.run
      1. org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)[spring-test-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      1 frame
    15. JUnit4 Runner
      JUnit4TestReference.run
      1. org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)[.cp/:na]
      1 frame
    16. JUnit3 Runner
      RemoteTestRunner.main
      1. org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)[.cp/:na]
      2. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)[.cp/:na]
      3. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)[.cp/:na]
      4. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)[.cp/:na]
      5. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)[.cp/:na]
      5 frames