Working with code R026

R026 - Failed to create Spring context

If your received the output code R026, this means that Diffblue Cover was unable to create a Spring context. This code is for general problems in creating the Spring context (specific related codes are R027 and R028).

The first step to resolving an R026 is to ensure you have an active Spring profile, e.g. "test" or "dev", if available. The second step to is to check if there are any missing environment variables or system properties. These two steps are the most common resolutions for failures by Diffblue Cover in creating Spring contexts.

Debugging with Partial Tests

Diffblue Cover has the ability to create and keep partial tests that can be used to debug problems with test creation.

In Cover Plugin for IntelliJ, partial tests are available by default, all you have to do is click on the button to write tests.

In the CLI, pass in the --keep-partial-tests option.

Rerunning Diffblue Cover with the appropriate option to keep partial tests will keep tests including the R026 code that can then be used to identify where Diffblue Cover is failing. An example of this output is shown below.

  /**
  * Method under test: {@link ResourceServerConfig#clientCredentialsResourceDetails()}
  */
  @Test
  public void testClientCredentialsResourceDetails() {
    //   Diffblue Cover was unable to write a Spring test,
    //   so wrote a non-Spring test instead.
    //   Reason: R026 Failed to create Spring context.
    //   Attempt to initialize test context failed with
    //   org.mockito.exceptions.base.MockitoException:
    //   Mockito cannot mock this class: interface org.springframework.security.config.annotation.ObjectPostProcessor.
    //   Mockito can only mock non-private & non-final classes.
    //   If you're not sure why you're getting this error, please report to the mailing list.
    //   Java               : 11
    //   JVM vendor name    : Private Build
    //   JVM vendor version : 11.0.15+10-Ubuntu-0ubuntu0.18.04.1
    //   JVM name           : OpenJDK 64-Bit Server VM
    //   JVM version        : 11.0.15+10-Ubuntu-0ubuntu0.18.04.1
    //   JVM info           : mixed mode, sharing
    //   OS name            : Linux
    //   OS version         : 5.4.0-109-generic
    //   Underlying exception : java.lang.UnsupportedOperationException: Cannot define class using reflection
    //       at org.springframework.boot.test.mock.mockito.MockDefinition.createMock(MockDefinition.java:157)
    //       at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.createMock(MockitoPostProcessor.java:222)
    //       at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.registerMock(MockitoPostProcessor.java:192)
    //       at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.register(MockitoPostProcessor.java:174)
    //       at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:144)
    //       at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:131)
    //       at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284)
    //       at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:172)
    //       at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694)
    //       at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)
    //       at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128)
    //       at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
    //       at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107)
    //       at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243)
    //       at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
    //       at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117)
    //       at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108)
    //   java.lang.UnsupportedOperationException: Cannot define class using reflection
    //       at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$Unavailable.defineClass(ClassInjector.java:821)
    //       at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection.inject(ClassInjector.java:185)
    //       at net.bytebuddy.dynamic.loading.ClassLoadingStrategy$Default$InjectionDispatcher.load(ClassLoadingStrategy.java:187)
    //       at net.bytebuddy.dynamic.TypeResolutionStrategy$Passive.initialize(TypeResolutionStrategy.java:79)
    //       at net.bytebuddy.dynamic.DynamicType$Default$Unloaded.load(DynamicType.java:4457)
    //       at org.mockito.internal.creation.bytebuddy.SubclassBytecodeGenerator.mockClass(SubclassBytecodeGenerator.java:121)
    //       at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:37)
    //       at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:34)
    //       at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:138)
    //       at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:346)
    //       at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:161)
    //       at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:355)
    //       at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator.mockClass(TypeCachingBytecodeGenerator.java:32)
    //       at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMockType(SubclassByteBuddyMockMaker.java:71)
    //       at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMock(SubclassByteBuddyMockMaker.java:42)
    //       at org.mockito.internal.creation.bytebuddy.ByteBuddyMockMaker.createMock(ByteBuddyMockMaker.java:25)
    //       at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:35)
    //       at org.mockito.internal.MockitoCore.mock(MockitoCore.java:65)
    //       at org.mockito.Mockito.mock(Mockito.java:1855)
    //       at org.springframework.boot.test.mock.mockito.MockDefinition.createMock(MockDefinition.java:157)
    //       at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.createMock(MockitoPostProcessor.java:222)
    //       at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.registerMock(MockitoPostProcessor.java:192)
    //       at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.register(MockitoPostProcessor.java:174)
    //       at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:144)
    //       at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:131)
    //       at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284)
    //       at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:172)
    //       at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694)
    //       at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)
    //       at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128)
    //       at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
    //       at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107)
    //       at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243)
    //       at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
    //       at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117)
    //       at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108)
    //   java.lang.IllegalStateException: Could not find sun.misc.Unsafe
    //       at net.bytebuddy.dynamic.loading.ClassInjector$UsingUnsafe$Dispatcher$Disabled.initialize(ClassInjector.java:1366)
    //       at net.bytebuddy.dynamic.loading.ClassInjector$UsingUnsafe.inject(ClassInjector.java:1202)
    //       at net.bytebuddy.dynamic.loading.ClassLoadingStrategy$ForUnsafeInjection.load(ClassLoadingStrategy.java:458)
    //       at net.bytebuddy.dynamic.TypeResolutionStrategy$Passive.initialize(TypeResolutionStrategy.java:79)
    //       at net.bytebuddy.dynamic.DynamicType$Default$Unloaded.load(DynamicType.java:4457)
    //       at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$Indirect.make(ClassInjector.java:684)
    //       at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$CreationAction.run(ClassInjector.java:302)
    //       at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$CreationAction.run(ClassInjector.java:290)
    //       at java.security.AccessController.doPrivileged(Native Method)
    //       at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection.<clinit>(ClassInjector.java:70)
    //       at net.bytebuddy.dynamic.loading.ClassLoadingStrategy$Default$InjectionDispatcher.load(ClassLoadingStrategy.java:184)
    //       at net.bytebuddy.dynamic.TypeResolutionStrategy$Passive.initialize(TypeResolutionStrategy.java:79)
    //       at net.bytebuddy.dynamic.DynamicType$Default$Unloaded.load(DynamicType.java:4457)
    //       at org.mockito.internal.creation.bytebuddy.SubclassBytecodeGenerator.mockClass(SubclassBytecodeGenerator.java:121)
    //       at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:37)
    //       at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:34)
    //       at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:138)
    //       at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:346)
    //       at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:161)
    //       at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:355)
    //       at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator.mockClass(TypeCachingBytecodeGenerator.java:32)
    //       at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMockType(SubclassByteBuddyMockMaker.java:71)
    //       at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMock(SubclassByteBuddyMockMaker.java:42)
    //       at org.mockito.internal.creation.bytebuddy.ByteBuddyMockMaker.createMock(ByteBuddyMockMaker.java:25)
    //       at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:35)
    //       at org.mockito.internal.MockitoCore.mock(MockitoCore.java:65)
    //       at org.mockito.Mockito.mock(Mockito.java:1855)
    //       at org.springframework.boot.test.mock.mockito.MockDefinition.createMock(MockDefinition.java:157)
    //       at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.createMock(MockitoPostProcessor.java:222)
    //       at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.registerMock(MockitoPostProcessor.java:192)
    //       at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.register(MockitoPostProcessor.java:174)
    //       at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:144)
    //       at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:131)
    //       at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284)
    //       at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:172)
    //       at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694)
    //       at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)
    //       at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128)
    //       at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
    //       at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107)
    //       at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243)
    //       at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
    //       at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117)
    //       at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108)
    //       at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
    //       at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1655)
    //       at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
    //       at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
    //       at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
    //       at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    //       at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
    //   java.lang.NoSuchMethodException: sun.misc.Unsafe.defineClass(java.lang.String, [B, int, int, java.lang.ClassLoader, java.security.ProtectionDomain)
    //       at java.lang.Class.getMethod(Class.java:2108)
    //       at net.bytebuddy.dynamic.loading.ClassInjector$UsingUnsafe$Dispatcher$CreationAction.run(ClassInjector.java:1269)
    //       at net.bytebuddy.dynamic.loading.ClassInjector$UsingUnsafe$Dispatcher$CreationAction.run(ClassInjector.java:1257)
    //       at java.security.AccessController.doPrivileged(Native Method)
    //       at net.bytebuddy.dynamic.loading.ClassInjector$UsingUnsafe.<clinit>(ClassInjector.java:1136)
    //       at net.bytebuddy.dynamic.loading.ClassLoadingStrategy$ForUnsafeInjection.load(ClassLoadingStrategy.java:458)
    //       at net.bytebuddy.dynamic.TypeResolutionStrategy$Passive.initialize(TypeResolutionStrategy.java:79)
    //       at net.bytebuddy.dynamic.DynamicType$Default$Unloaded.load(DynamicType.java:4457)
    //       at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$Indirect.make(ClassInjector.java:684)
    //       at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$CreationAction.run(ClassInjector.java:302)
    //       at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$CreationAction.run(ClassInjector.java:290)
    //       at java.security.AccessController.doPrivileged(Native Method)
    //       at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection.<clinit>(ClassInjector.java:70)
    //       at net.bytebuddy.dynamic.loading.ClassLoadingStrategy$Default$InjectionDispatcher.load(ClassLoadingStrategy.java:184)
    //       at net.bytebuddy.dynamic.TypeResolutionStrategy$Passive.initialize(TypeResolutionStrategy.java:79)
    //       at net.bytebuddy.dynamic.DynamicType$Default$Unloaded.load(DynamicType.java:4457)
    //       at org.mockito.internal.creation.bytebuddy.SubclassBytecodeGenerator.mockClass(SubclassBytecodeGenerator.java:121)
    //       at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:37)
    //       at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:34)
    //       at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:138)
    //       at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:346)
    //       at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:161)
    //       at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:355)
    //       at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator.mockClass(TypeCachingBytecodeGenerator.java:32)
    //       at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMockType(SubclassByteBuddyMockMaker.java:71)
    //       at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMock(SubclassByteBuddyMockMaker.java:42)
    //       at org.mockito.internal.creation.bytebuddy.ByteBuddyMockMaker.createMock(ByteBuddyMockMaker.java:25)
    //       at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:35)
    //       at org.mockito.internal.MockitoCore.mock(MockitoCore.java:65)
    //       at org.mockito.Mockito.mock(Mockito.java:1855)
    //       at org.springframework.boot.test.mock.mockito.MockDefinition.createMock(MockDefinition.java:157)
    //       at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.createMock(MockitoPostProcessor.java:222)
    //       at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.registerMock(MockitoPostProcessor.java:192)
    //       at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.register(MockitoPostProcessor.java:174)
    //       at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:144)
    //       at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:131)
    //       at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284)
    //       at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:172)
    //       at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694)
    //       at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)
    //       at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128)
    //       at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
    //       at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107)
    //       at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243)
    //       at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
    //       at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117)
    //       at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108)
    //       at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
    //       at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1655)
    //       at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
    //       at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
    //       at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
    //       at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    //       at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
    //   See https://diff.blue/R026 to resolve this issue.

    // Arrange and Act
    ClientCredentialsResourceDetails actualClientCredentialsResourceDetailsResult = (new ResourceServerConfig(
        new ResourceServerProperties())).clientCredentialsResourceDetails();

    // Assert
    assertEquals("access_token", actualClientCredentialsResourceDetailsResult.getTokenName());
    assertEquals("client_credentials", actualClientCredentialsResourceDetailsResult.getGrantType());
    assertEquals(AuthenticationScheme.header,
        actualClientCredentialsResourceDetailsResult.getClientAuthenticationScheme());
    assertEquals(AuthenticationScheme.header, actualClientCredentialsResourceDetailsResult.getAuthenticationScheme());
  }

The information in the comment can be used to identify where Diffblue Cover is unable to proceed. In this example the overview of information indicates that Java 11 is being used despite this project requring Java 8. Further information can be seen in the stack trace below, should initial environmental or configuration information not be sufficient. Resolving this problem will resolve the R026 code and allow Diffblue Cover to successfully write tests.

An alternative solution is to complete the test manually and confirm that the test passes, this will ensure that the test class is correctly configured. For example here, by resolving the Java version.

Note that the information in the comment of a partial test can also be used by Diffblue Support should you need further assistance.

Further Troubleshooting

In addition to creating tests as descibed above or manually, further information can also be found in the log files from Diffblue Cover that can indicate the problem.

A (trimmed) example of the output from a log file (found in your project under .diffblue/log) can be seen below.

15:16:33.979 [INFO][analyzer-service:grpc-default-executor-0][c.d.fuzztest.d.o] Reason to be partial:
com.diffblue.cover.exception.limitation.FailedToCreateSpringContextException: Failed to create Spring context using package com.piggymetrics.account.config;
@org.springframework.test.context.ContextConfiguration(classes = {com.piggymetrics.account.config.ResourceServerConfig.class,org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties.class})
@org.junit.runner.RunWith(value = org.springframework.test.context.junit4.SpringRunner.class)
public class DiffblueFakeClass3 {
  @org.springframework.boot.test.mock.mockito.MockBean org.springframework.security.config.annotation.ObjectPostProcessor objectPostProcessor;
  @org.springframework.beans.factory.annotation.Autowired com.piggymetrics.account.config.ResourceServerConfig resourceServerConfig;
  @org.springframework.beans.factory.annotation.Autowired org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties resourceServerProperties;
  @org.junit.Test
  public void testSpringContextLoads() {}
}

	at com.diffblue.cover.d.a.j.b(SourceFile:2113)
	at com.diffblue.cover.d.a.j.a(SourceFile:52)
	at com.diffblue.cover.d.a.p$a.a(SourceFile:158)
	at com.diffblue.fuzztest.a.g.a(SourceFile:1024)
	at com.diffblue.fuzztest.a.d.a(SourceFile:735)
	at com.diffblue.fuzztest.a.d.a(SourceFile:416)
	at com.diffblue.fuzztest.a.d.a(SourceFile:212)
	at com.diffblue.fuzztest.d.n.a(SourceFile:1254)
	at com.diffblue.fuzztest.d.t.a(SourceFile:190)
	at com.diffblue.fuzztest.d.q.a(SourceFile:45)
	at com.diffblue.fuzztest.d.b.i(SourceFile:315)
	at com.diffblue.cover.sandbox.execution.WorkerThread.lambda$callWorkerThread$3(SourceFile:134)
	at com.diffblue.cover.sandbox.execution.WorkerThread.run(SourceFile:207)
Caused by: org.mockito.exceptions.base.MockitoException:
Mockito cannot mock this class: interface org.springframework.security.config.annotation.ObjectPostProcessor.

Mockito can only mock non-private & non-final classes.
If you're not sure why you're getting this error, please report to the mailing list.

Java               : 11
JVM vendor name    : Private Build
JVM vendor version : 11.0.15+10-Ubuntu-0ubuntu0.18.04.1
JVM name           : OpenJDK 64-Bit Server VM
JVM version        : 11.0.15+10-Ubuntu-0ubuntu0.18.04.1
JVM info           : mixed mode, sharing
OS name            : Linux
OS version         : 5.4.0-109-generic

Underlying exception : java.lang.UnsupportedOperationException: Cannot define class using reflection
	at org.springframework.boot.test.mock.mockito.MockDefinition.createMock(MockDefinition.java:157)
	at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.createMock(MockitoPostProcessor.java:222)
	at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.registerMock(MockitoPostProcessor.java:192)
	at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.register(MockitoPostProcessor.java:174)
	at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:144)
	at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:131)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:172)
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)
	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128)
	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107)
	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117)
	at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108)
	at com.diffblue.spring.isolation.SpringFactoriesImpl.makeTestContext(SpringFactoriesImpl.java:250)
	at com.diffblue.cover.d.a.o.a(SourceFile:42)
	at com.diffblue.cover.d.a.b.a(SourceFile:60)
	at com.diffblue.cover.d.a.j.b(SourceFile:69)
	... 12 common frames omitted

Otherwise, please contact Diffblue Support with details of:

  • The log file (to be found in the module's .diffblue directory for the CLI, or the log file name displayed in Cover Plugin for IntelliJ).

  • The source code of the class under test, and the failing (partial) test. Note that if detailed information can't be shared with Diffblue you can provide the following as part of the support case:

    • Extract an example from your source code that is sufficient to reproduce the problem, but doesn't contain anything confidential.

    • Mask parts of the log file that you consider confidential. Partial test creation or troubleshooting can be highly valuable in diagnosing the problem.

Last updated