I run Diffblue on a big service class. It goes through the stages of Prepare, Index, and Writing tests. But for each test it tries to write I’m getting a Notification in IDEA “Failure to combine test code…into existing test class. This can occur when the existing test file has been manually edited [etc…]”. But this is a brand-new Test class, starting from scratch. When the process finishes, there’s an empty FooServiceClass.java file.
Unable to combine written test code for SensorManagementService.addSensorEvent(SensorEvent) into existing test class SensorManagementServiceTest. This can occur when the existing test file has been manually edited causing an incompatibility. See the documentation for details.
Here’s what seems like the relevant section of the plugin log:
11:35:40.132 [WARN][pool-7-thread-16][c.d.i.plugin.g.a] Failure to combine test code - Unable to combine written test code for <a href="diffblue-method-reference:us.tacticaledge.itv.gateway.modules.sensors.service.SensorManagementService.updateSensorTimestamp:(Ljava/lang/String;Ljava/util/Date;)V">SensorManagementService.updateSensorTimestamp(String, Date)</a> into existing test class <a href="diffblue-class-reference:us.tacticaledge.itv.gateway.modules.sensors.service.SensorManagementServiceTest">SensorManagementServiceTest</a>. This can occur when the existing test file has been manually edited causing an incompatibility. See the <a href="https://docs.diffblue.com/getting-started/cover-intellij-plugin/">documentation</a> for details.
com.diffblue.cover.exception.environment.InsertTestException: Failed to insert a test into the created test Java file 'C:\Users\ibcol\Documents\Projects\telemetry-services\telemetry\telemetry-services\telemetry-webapp\src\test\java\us\tacticaledge\itv\gateway\modules\sensors\service\SensorManagementServiceTest.java'
at com.diffblue.intellij.plugin.b.f.b(SourceFile:121)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1023)
at com.diffblue.intellij.plugin.a.a.c(SourceFile:66)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:219)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:174)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:164)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:150)
at com.diffblue.intellij.plugin.a.a.b(SourceFile:67)
at com.intellij.openapi.application.TransactionGuardImpl.runWithWritingAllowed(TransactionGuardImpl.java:209)
at com.intellij.openapi.application.TransactionGuardImpl.access$100(TransactionGuardImpl.java:21)
at com.intellij.openapi.application.TransactionGuardImpl$1.run(TransactionGuardImpl.java:191)
at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:881)
at com.intellij.openapi.application.impl.ApplicationImpl$3.run(ApplicationImpl.java:513)
at com.intellij.openapi.application.impl.LaterInvocator$1.run(LaterInvocator.java:95)
at com.intellij.openapi.application.impl.FlushQueue.doRun(FlushQueue.java:75)
at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:118)
at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:42)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:779)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:730)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:724)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:749)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:898)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:746)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$6(IdeEventQueue.java:439)
at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:791)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$7(IdeEventQueue.java:438)
at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:105)
at com.intellij.ide.IdeEventQueue.performActivity(IdeEventQueue.java:604)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:436)
at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:881)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:484)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)
Caused by: com.diffblue.combiner.a.b: java.lang.IllegalArgumentException: Invalid identifier : >boolean<
at com.diffblue.combiner.a.a$a.a(SourceFile:151)
at com.diffblue.intellij.plugin.b.f.b(SourceFile:98)
... 39 common frames omitted
Caused by: java.lang.IllegalArgumentException: Invalid identifier : >boolean<
at com.diffblue.shaded.org.eclipse.jdt.core.dom.SimpleName.setIdentifier(SimpleName.java:243)
at com.diffblue.shaded.org.eclipse.jdt.core.dom.AST.newSimpleName(AST.java:2742)
at com.diffblue.a.u.a(SourceFile:51)
at com.diffblue.a.u.a(SourceFile:60)
at com.diffblue.a.a.f.a(SourceFile:85)
at com.diffblue.a.a.e.b(SourceFile:53)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:310)
at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:734)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
at com.diffblue.a.a.e.a(SourceFile:59)
at com.diffblue.a.w.<init>(SourceFile:430)
at com.diffblue.a.v.a(SourceFile:209)
at com.diffblue.cover.d.b.a(SourceFile:54)
at com.diffblue.combiner.a.c.a(SourceFile:500)
at com.diffblue.combiner.a.a.a(SourceFile:1061)
at com.diffblue.combiner.a.a$a.a(SourceFile:146)
... 40 common frames omitted
11:35:40.133 [INFO][pool-7-thread-16][c.d.cover.api.o] Failed to create tests for method group us.tacticaledge.itv.gateway.modules.sensors.service.SensorManagementService.updateSensorTimestamp:(Ljava/lang/String;Ljava/util/Date;)V: R026: Failed to create Spring context
Attempt to initialize test context failed with
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:132)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:124)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:543)
org.mockito.exceptions.base.MockitoException:
Cannot mock/spy class java.lang.Boolean
Mockito cannot mock/spy because :
- final class
at org.springframework.boot.test.mock.mockito.MockDefinition.createMock(MockDefinition.java:154)
at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.registerMock(MockitoPostProcessor.java:185)
at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.register(MockitoPostProcessor.java:167)
at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:141)
at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:129)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:325)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:191)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:746)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:564)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:127)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:276)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:244)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:124)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:543)
when running class:
package us.tacticaledge.itv.gateway.modules.sensors.service;
@org.springframework.test.context.ContextConfiguration(classes = {us.tacticaledge.itv.gateway.modules.sensors.service.SensorManagementService.class})
@org.junit.runner.RunWith(value = org.springframework.test.context.junit4.SpringRunner.class) // if JUnit 4
@org.junit.jupiter.api.extension.ExtendWith(value = org.springframework.test.context.junit.jupiter.SpringExtension.class) // if JUnit 5
public class DiffblueFakeClass1153 {
@org.springframework.boot.test.mock.mockito.MockBean java.lang.Boolean aBoolean;
@org.springframework.boot.test.mock.mockito.MockBean us.tacticaledge.itv.gateway.modules.movements.service.ItemMovementManagementService itemMovementManagementService;
@org.springframework.boot.test.mock.mockito.MockBean us.tacticaledge.itv.gateway.modules.locations.service.LocationManagementService locationManagementService;
@org.springframework.boot.test.mock.mockito.MockBean us.tacticaledge.itv.gateway.modules.sensors.model.SensorEventMapper sensorEventMapper;
@org.springframework.boot.test.mock.mockito.MockBean us.tacticaledge.itv.gateway.modules.sensors.data.SensorEventRepository sensorEventRepository;
@org.springframework.boot.test.mock.mockito.MockBean us.tacticaledge.itv.gateway.modules.sensors.service.SensorHealthService sensorHealthService;
@org.springframework.beans.factory.annotation.Autowired us.tacticaledge.itv.gateway.modules.sensors.service.SensorManagementService sensorManagementService;
@org.springframework.boot.test.mock.mockito.MockBean us.tacticaledge.itv.gateway.modules.sensors.model.SensorMapper sensorMapper;
@org.springframework.boot.test.mock.mockito.MockBean us.tacticaledge.itv.gateway.modules.sensors.service.SensorNotificationService sensorNotificationService;
@org.springframework.boot.test.mock.mockito.MockBean us.tacticaledge.itv.gateway.modules.sensors.service.SensorRelationshipService sensorRelationshipService;
@org.springframework.boot.test.mock.mockito.MockBean us.tacticaledge.itv.gateway.modules.sensors.data.SensorRepository sensorRepository;
@org.springframework.boot.test.mock.mockito.MockBean us.tacticaledge.itv.gateway.data.timeseries.service.TimeSeriesService timeSeriesService;
@org.junit.Test // if JUnit 4
@org.junit.jupiter.api.Test // if JUnit 5
public void testSpringContextLoads() {}
}
See https://diff.blue/R026 to resolve this issue.