diff --git a/community/bolt/src/test/java/org/neo4j/bolt/BoltChannelTest.java b/community/bolt/src/test/java/org/neo4j/bolt/BoltChannelTest.java index 435b070b01ddb..322afcb9f97b5 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/BoltChannelTest.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/BoltChannelTest.java @@ -94,7 +94,8 @@ private static Channel channelMock( boolean open ) { Channel channel = mock( Channel.class ); when( channel.isOpen() ).thenReturn( open ); - when( channel.close() ).thenReturn( mock( ChannelFuture.class ) ); + ChannelFuture channelFuture = mock( ChannelFuture.class ); + when( channel.close() ).thenReturn( channelFuture ); return channel; } } diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/MachineRoom.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/MachineRoom.java index e887247d721b2..4a610b44b27d4 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/MachineRoom.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/MachineRoom.java @@ -102,7 +102,8 @@ private static void init( BoltStateMachine machine ) throws AuthenticationExcept private static void init( BoltStateMachine machine, String owner ) throws AuthenticationException, BoltConnectionFatality { - when( machine.spi.authenticate( any() ) ).thenReturn( mock( AuthenticationResult.class ) ); + AuthenticationResult authenticationResult = mock( AuthenticationResult.class ); + when( machine.spi.authenticate( any() ) ).thenReturn( authenticationResult ); machine.init( USER_AGENT, owner == null ? emptyMap() : Collections.singletonMap( AuthToken.PRINCIPAL, owner ), nullResponseHandler() ); } diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/TransactionStateMachineTest.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/TransactionStateMachineTest.java index 2b01b894c8430..b160268cd2807 100644 --- a/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/TransactionStateMachineTest.java +++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/TransactionStateMachineTest.java @@ -574,7 +574,8 @@ private static TransactionStateMachineSPI newFailingTransactionStateMachineSPI( TransactionStateMachine.BoltResultHandle resultHandle = newResultHandle(); TransactionStateMachineSPI stateMachineSPI = mock( TransactionStateMachineSPI.class ); - when( stateMachineSPI.beginTransaction( any() ) ).thenReturn( mock( KernelTransaction.class ) ); + KernelTransaction kernelTransaction = mock( KernelTransaction.class ); + when( stateMachineSPI.beginTransaction( any() ) ).thenReturn( kernelTransaction ); when( stateMachineSPI.executeQuery( any(), any(), anyString(), any() ) ).thenReturn( resultHandle ); when( stateMachineSPI.executeQuery( any(), any(), eq( "FAIL" ), any() ) ).thenThrow( new TransactionTerminatedException( failureStatus ) ); diff --git a/community/cypher/cypher/src/test/java/org/neo4j/cypher/internal/javacompat/SnapshotExecutionEngineTest.java b/community/cypher/cypher/src/test/java/org/neo4j/cypher/internal/javacompat/SnapshotExecutionEngineTest.java index 98176b5267931..c3b05d7b32f26 100644 --- a/community/cypher/cypher/src/test/java/org/neo4j/cypher/internal/javacompat/SnapshotExecutionEngineTest.java +++ b/community/cypher/cypher/src/test/java/org/neo4j/cypher/internal/javacompat/SnapshotExecutionEngineTest.java @@ -74,7 +74,8 @@ public void setUp() throws Exception when( kernelStatement.getVersionContext() ).thenReturn( versionContext ); when( transactionalContext.statement() ).thenReturn( kernelStatement ); Result result = mock( Result.class ); - when( result.getQueryStatistics() ).thenReturn( mock( QueryStatistics.class ) ); + QueryStatistics statistics = mock( QueryStatistics.class ); + when( result.getQueryStatistics() ).thenReturn( statistics ); when( executor.execute( any(), anyMap(), any() ) ).thenReturn( result ); } diff --git a/community/dbms/src/test/java/org/neo4j/commandline/dbms/ImportCommandTest.java b/community/dbms/src/test/java/org/neo4j/commandline/dbms/ImportCommandTest.java index 7d7684bcde924..fd5ad7634d989 100644 --- a/community/dbms/src/test/java/org/neo4j/commandline/dbms/ImportCommandTest.java +++ b/community/dbms/src/test/java/org/neo4j/commandline/dbms/ImportCommandTest.java @@ -62,9 +62,10 @@ public void defaultsToCsvWhenModeNotSpecified() throws Exception { File homeDir = testDir.directory( "home" ); ImporterFactory mockImporterFactory = mock( ImporterFactory.class ); + Importer importer = mock( Importer.class ); when( mockImporterFactory .getImporterForMode( eq( "csv" ), any( Args.class ), any( Config.class ), any( OutsideWorld.class ) ) ) - .thenReturn( mock( Importer.class ) ); + .thenReturn( importer ); try ( RealOutsideWorld outsideWorld = new RealOutsideWorld( System.out, System.err, new ByteArrayInputStream( new byte[0] ) ) ) { @@ -86,9 +87,10 @@ public void acceptsNodeMetadata() throws Exception { File homeDir = testDir.directory( "home" ); ImporterFactory mockImporterFactory = mock( ImporterFactory.class ); + Importer importer = mock( Importer.class ); when( mockImporterFactory .getImporterForMode( eq( "csv" ), any( Args.class ), any( Config.class ), any( OutsideWorld.class ) ) ) - .thenReturn( mock( Importer.class ) ); + .thenReturn( importer ); ImportCommand importCommand = new ImportCommand( homeDir.toPath(), testDir.directory( "conf" ).toPath(), @@ -107,9 +109,10 @@ public void acceptsRelationshipsMetadata() throws Exception { File homeDir = testDir.directory( "home" ); ImporterFactory mockImporterFactory = mock( ImporterFactory.class ); + Importer importer = mock( Importer.class ); when( mockImporterFactory .getImporterForMode( eq( "csv" ), any( Args.class ), any( Config.class ), any( OutsideWorld.class ) ) ) - .thenReturn( mock( Importer.class ) ); + .thenReturn( importer ); ImportCommand importCommand = new ImportCommand( homeDir.toPath(), testDir.directory( "conf" ).toPath(), diff --git a/community/kernel/src/test/java/org/neo4j/kernel/TestPlaceboTransaction.java b/community/kernel/src/test/java/org/neo4j/kernel/TestPlaceboTransaction.java index 7acc03924b6f9..6d78a99220781 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/TestPlaceboTransaction.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/TestPlaceboTransaction.java @@ -54,7 +54,8 @@ public class TestPlaceboTransaction public void before() { ThreadToStatementContextBridge bridge = mock( ThreadToStatementContextBridge.class ); - when( bridge.get() ).thenReturn( mock( Statement.class ) ); + Statement statement = mock( Statement.class ); + when( bridge.get() ).thenReturn( statement ); kernelTransaction = spy( KernelTransaction.class ); locks = mock( Locks.class ); when(kernelTransaction.locks()).thenReturn( locks ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/ExplicitBatchIndexApplierTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/ExplicitBatchIndexApplierTest.java index e99af052d1a62..e0d77f61eee21 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/ExplicitBatchIndexApplierTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/ExplicitBatchIndexApplierTest.java @@ -76,7 +76,8 @@ public void shouldOnlyCreateOneApplierPerProvider() throws Exception when( commitment.hasExplicitIndexChanges() ).thenReturn( true ); IndexConfigStore config = newIndexConfigStore( names, applierName ); ExplicitIndexApplierLookup applierLookup = mock( ExplicitIndexApplierLookup.class ); - when( applierLookup.newApplier( anyString(), anyBoolean() ) ).thenReturn( mock( TransactionApplier.class ) ); + TransactionApplier transactionApplier = mock( TransactionApplier.class ); + when( applierLookup.newApplier( anyString(), anyBoolean() ) ).thenReturn( transactionApplier ); try ( ExplicitBatchIndexApplier applier = new ExplicitBatchIndexApplier( config, applierLookup, BYPASS, INTERNAL ) ) { TransactionToApply tx = new TransactionToApply( null, 2 ); @@ -104,7 +105,8 @@ public void shouldOrderTransactionsMakingExplicitIndexChanges() throws Throwable Map keys = MapUtil.genericMap( "key", 0 ); String applierName = "test-applier"; ExplicitIndexApplierLookup applierLookup = mock( ExplicitIndexApplierLookup.class ); - when( applierLookup.newApplier( anyString(), anyBoolean() ) ).thenReturn( mock( TransactionApplier.class ) ); + TransactionApplier transactionApplier = mock( TransactionApplier.class ); + when( applierLookup.newApplier( anyString(), anyBoolean() ) ).thenReturn( transactionApplier ); IndexConfigStore config = newIndexConfigStore( names, applierName ); // WHEN multiple explicit index transactions are running, they should be done in order diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/KernelTransactionTestBase.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/KernelTransactionTestBase.java index 9c951049b5209..268f00ae4d0b3 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/KernelTransactionTestBase.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/KernelTransactionTestBase.java @@ -111,7 +111,8 @@ public void before() throws Exception collectionsFactory = Mockito.spy( new TestCollectionsFactory() ); when( headerInformation.getAdditionalHeader() ).thenReturn( new byte[0] ); when( headerInformationFactory.create() ).thenReturn( headerInformation ); - when( readLayer.newStatement() ).thenReturn( mock( StoreStatement.class ) ); + StoreStatement statement = mock( StoreStatement.class ); + when( readLayer.newStatement() ).thenReturn( statement ); when( neoStores.getMetaDataStore() ).thenReturn( metaDataStore ); when( storageEngine.storeReadLayer() ).thenReturn( readLayer ); doAnswer( invocation -> ((Collection) invocation.getArgument(0) ).add( new Command diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/KernelTransactionsTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/KernelTransactionsTest.java index 29f407b87d77c..1d9621c556570 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/KernelTransactionsTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/KernelTransactionsTest.java @@ -36,6 +36,7 @@ import org.neo4j.graphdb.DatabaseShutdownException; import org.neo4j.graphdb.security.AuthorizationExpiredException; +import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException; import org.neo4j.internal.kernel.api.security.LoginContext; import org.neo4j.io.pagecache.tracing.cursor.context.EmptyVersionContextSupplier; import org.neo4j.io.pagecache.tracing.cursor.context.VersionContextSupplier; @@ -43,7 +44,6 @@ import org.neo4j.kernel.api.KernelTransaction; import org.neo4j.kernel.api.KernelTransactionHandle; import org.neo4j.kernel.api.exceptions.Status; -import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException; import org.neo4j.kernel.api.explicitindex.AutoIndexing; import org.neo4j.kernel.api.security.AnonymousContext; import org.neo4j.kernel.impl.api.index.IndexingService; @@ -533,7 +533,8 @@ private static KernelTransactions newKernelTransactions( boolean testKernelTrans StorageStatement... otherStorageStatements ) throws Throwable { Locks locks = mock( Locks.class ); - when( locks.newClient() ).thenReturn( mock( Locks.Client.class ) ); + Locks.Client client = mock( Locks.Client.class ); + when( locks.newClient() ).thenReturn( client ); StoreReadLayer readLayer = mock( StoreReadLayer.class ); when( readLayer.newStatement() ).thenReturn( firstStoreStatements, otherStorageStatements ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/constraints/ConstraintIndexCreatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/constraints/ConstraintIndexCreatorTest.java index 96cc687c3d503..1061dc07bb0fe 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/constraints/ConstraintIndexCreatorTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/constraints/ConstraintIndexCreatorTest.java @@ -364,7 +364,8 @@ private KernelTransactionImplementation createTransaction() when( transaction.statementLocks() ).thenReturn( locks ); when( transaction.tokenRead() ).thenReturn( tokenRead ); when( transaction.schemaRead() ).thenReturn( schemaRead ); - when( transaction.txState() ).thenReturn( mock( TransactionState.class ) ); + TransactionState transactionState = mock( TransactionState.class ); + when( transaction.txState() ).thenReturn( transactionState ); return transaction; } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexRecoveryIT.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexRecoveryIT.java index 0a73898a3b3f4..13689f7b2ff14 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexRecoveryIT.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexRecoveryIT.java @@ -207,12 +207,14 @@ public void shouldBeAbleToRecoverAndUpdateOnlineIndex() throws Exception public void shouldKeepFailedIndexesAsFailedAfterRestart() throws Exception { // Given + IndexPopulator indexPopulator = mock( IndexPopulator.class ); when( mockedIndexProvider .getPopulator( anyLong(), any( SchemaIndexDescriptor.class ), any( IndexSamplingConfig.class ) ) ) - .thenReturn( mock( IndexPopulator.class ) ); + .thenReturn( indexPopulator ); + IndexAccessor indexAccessor = mock( IndexAccessor.class ); when( mockedIndexProvider.getOnlineAccessor( anyLong(), any( SchemaIndexDescriptor.class ), any( IndexSamplingConfig.class ) ) - ).thenReturn( mock( IndexAccessor.class ) ); + ).thenReturn( indexAccessor ); startDb(); createIndex( myLabel ); rotateLogsAndCheckPoint(); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexingServiceTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexingServiceTest.java index 441136c7f68ec..a26c9d01b4a01 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexingServiceTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexingServiceTest.java @@ -72,6 +72,7 @@ import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingController; import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode; +import org.neo4j.kernel.impl.scheduler.CentralJobScheduler; import org.neo4j.kernel.impl.store.UnderlyingStorageException; import org.neo4j.kernel.impl.store.record.IndexRule; import org.neo4j.kernel.impl.storemigration.StoreMigrationParticipant; @@ -80,7 +81,6 @@ import org.neo4j.kernel.impl.transaction.state.DefaultIndexProviderMap; import org.neo4j.kernel.impl.transaction.state.DirectIndexUpdates; import org.neo4j.kernel.impl.transaction.state.IndexUpdates; -import org.neo4j.kernel.impl.scheduler.CentralJobScheduler; import org.neo4j.kernel.lifecycle.LifeRule; import org.neo4j.kernel.lifecycle.LifecycleException; import org.neo4j.logging.AssertableLogProvider; @@ -362,8 +362,9 @@ public void shouldLogIndexStateOnInit() throws Exception // given IndexProvider provider = mock( IndexProvider.class ); when( provider.getProviderDescriptor() ).thenReturn( PROVIDER_DESCRIPTOR ); + IndexAccessor indexAccessor = mock( IndexAccessor.class ); when( provider.getOnlineAccessor( anyLong(), any( SchemaIndexDescriptor.class ), any( IndexSamplingConfig.class ) ) ) - .thenReturn( mock( IndexAccessor.class ) ); + .thenReturn( indexAccessor ); IndexProviderMap providerMap = new DefaultIndexProviderMap( provider ); TokenNameLookup mockLookup = mock( TokenNameLookup.class ); @@ -924,8 +925,9 @@ public void shouldLogIndexStateOutliersOnInit() throws Exception // given IndexProvider provider = mock( IndexProvider.class ); when( provider.getProviderDescriptor() ).thenReturn( PROVIDER_DESCRIPTOR ); + IndexAccessor indexAccessor = mock( IndexAccessor.class ); when( provider.getOnlineAccessor( anyLong(), any( SchemaIndexDescriptor.class ), any( IndexSamplingConfig.class ) ) ) - .thenReturn( mock( IndexAccessor.class ) ); + .thenReturn( indexAccessor ); IndexProviderMap providerMap = new DefaultIndexProviderMap( provider ); TokenNameLookup mockLookup = mock( TokenNameLookup.class ); @@ -972,8 +974,9 @@ public void shouldLogIndexStateOutliersOnStart() throws Exception // given IndexProvider provider = mock( IndexProvider.class ); when( provider.getProviderDescriptor() ).thenReturn( PROVIDER_DESCRIPTOR ); + IndexAccessor indexAccessor = mock( IndexAccessor.class ); when( provider.getOnlineAccessor( anyLong(), any( SchemaIndexDescriptor.class ), any( IndexSamplingConfig.class ) ) ) - .thenReturn( mock( IndexAccessor.class ) ); + .thenReturn( indexAccessor ); IndexProviderMap providerMap = new DefaultIndexProviderMap( provider ); TokenNameLookup mockLookup = mock( TokenNameLookup.class ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/newapi/IndexTxStateUpdaterTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/newapi/IndexTxStateUpdaterTest.java index ea1a50cd9c911..b1c6532d9b2a5 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/newapi/IndexTxStateUpdaterTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/newapi/IndexTxStateUpdaterTest.java @@ -115,7 +115,8 @@ public void setup() throws IndexNotFoundKernelException when( readOps.txState() ).thenReturn( txState ); IndexingService indexingService = mock( IndexingService.class ); - when( indexingService.getIndexProxy( any( SchemaDescriptor.class ) ) ).thenReturn( mock( IndexProxy.class ) ); + IndexProxy indexProxy = mock( IndexProxy.class ); + when( indexingService.getIndexProxy( any( SchemaDescriptor.class ) ) ).thenReturn( indexProxy ); indexTxUpdater = new IndexTxStateUpdater( storeReadLayer, readOps, indexingService ); } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/newapi/OperationsLockTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/newapi/OperationsLockTest.java index 5121ef0607583..de9356922ce98 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/newapi/OperationsLockTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/newapi/OperationsLockTest.java @@ -121,8 +121,9 @@ public void setUp() throws InvalidTransactionTypeKernelException when( cursors.allocatePropertyCursor() ).thenReturn( propertyCursor ); when( cursors.allocateRelationshipScanCursor() ).thenReturn( relationshipCursor ); AutoIndexing autoindexing = mock( AutoIndexing.class ); - when( autoindexing.nodes() ).thenReturn( mock( AutoIndexOperations.class ) ); - when( autoindexing.relationships() ).thenReturn( mock( AutoIndexOperations.class ) ); + AutoIndexOperations autoIndexOperations = mock( AutoIndexOperations.class ); + when( autoindexing.nodes() ).thenReturn( autoIndexOperations ); + when( autoindexing.relationships() ).thenReturn( autoIndexOperations ); StorageStatement storageStatement = mock( StorageStatement.class ); StorageEngine engine = mock( StorageEngine.class ); storeReadLayer = mock( StoreReadLayer.class ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/command/NeoTransactionIndexApplierTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/command/NeoTransactionIndexApplierTest.java index d26cba7f7ec04..09c37cce5be18 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/command/NeoTransactionIndexApplierTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/command/NeoTransactionIndexApplierTest.java @@ -81,7 +81,8 @@ public void shouldUpdateLabelStoreScanOnNodeCommands() throws Exception after.setLabelField( 18, emptyDynamicRecords ); final Command.NodeCommand command = new Command.NodeCommand( before, after ); - when( labelScanStore.get() ).thenReturn( mock( LabelScanWriter.class ) ); + LabelScanWriter labelScanWriter = mock( LabelScanWriter.class ); + when( labelScanStore.get() ).thenReturn( labelScanWriter ); // when boolean result; diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/RecordChangeSetTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/RecordChangeSetTest.java index f05e5fec1eff5..cdda58244a2ed 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/RecordChangeSetTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/RecordChangeSetTest.java @@ -56,11 +56,16 @@ public void shouldClearStateOnClose() { // GIVEN NeoStores mockStore = mock( NeoStores.class ); - when( mockStore.getNodeStore() ).thenReturn( mock( NodeStore.class ) ); - when( mockStore.getRelationshipStore() ).thenReturn( mock( RelationshipStore.class ) ); - when( mockStore.getPropertyStore() ).thenReturn( mock( PropertyStore.class ) ); - when( mockStore.getSchemaStore() ).thenReturn( mock( SchemaStore.class ) ); - when( mockStore.getRelationshipGroupStore() ).thenReturn( mock( RelationshipGroupStore.class ) ); + NodeStore store = mock( NodeStore.class ); + when( mockStore.getNodeStore() ).thenReturn( store ); + RelationshipStore relationshipStore = mock( RelationshipStore.class ); + when( mockStore.getRelationshipStore() ).thenReturn( relationshipStore ); + PropertyStore propertyStore = mock( PropertyStore.class ); + when( mockStore.getPropertyStore() ).thenReturn( propertyStore ); + SchemaStore schemaStore = mock( SchemaStore.class ); + when( mockStore.getSchemaStore() ).thenReturn( schemaStore ); + RelationshipGroupStore groupStore = mock( RelationshipGroupStore.class ); + when( mockStore.getRelationshipGroupStore() ).thenReturn( groupStore ); RecordChangeSet changeSet = new RecordChangeSet( new Loaders( mockStore ) ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/WriteTransactionCommandOrderingTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/WriteTransactionCommandOrderingTest.java index 5c5dc8d15e141..f581f74bc9e54 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/WriteTransactionCommandOrderingTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/WriteTransactionCommandOrderingTest.java @@ -190,9 +190,12 @@ private TransactionRecordState injectAllPossibleCommands() Collections.emptyList() ); NeoStores neoStores = mock( NeoStores.class ); - when( neoStores.getNodeStore() ).thenReturn( mock( NodeStore.class ) ); - when( neoStores.getRelationshipGroupStore() ).thenReturn( mock( RelationshipGroupStore.class ) ); - when( neoStores.getRelationshipStore() ).thenReturn( mock( RelationshipStore.class ) ); + NodeStore store = mock( NodeStore.class ); + when( neoStores.getNodeStore() ).thenReturn( store ); + RelationshipGroupStore relationshipGroupStore = mock( RelationshipGroupStore.class ); + when( neoStores.getRelationshipGroupStore() ).thenReturn( relationshipGroupStore ); + RelationshipStore relationshipStore = mock( RelationshipStore.class ); + when( neoStores.getRelationshipStore() ).thenReturn( relationshipStore ); return new TransactionRecordState( neoStores, mock( IntegrityValidator.class ), recordChangeSet, 0, null, null, null, null, null ); diff --git a/community/server/src/test/java/org/neo4j/server/modules/ThirdPartyJAXRSModuleTest.java b/community/server/src/test/java/org/neo4j/server/modules/ThirdPartyJAXRSModuleTest.java index 916cf32271024..d9d447dc52ed4 100644 --- a/community/server/src/test/java/org/neo4j/server/modules/ThirdPartyJAXRSModuleTest.java +++ b/community/server/src/test/java/org/neo4j/server/modules/ThirdPartyJAXRSModuleTest.java @@ -51,7 +51,8 @@ public void shouldReportThirdPartyPackagesAtSpecifiedMount() throws Exception CommunityNeoServer neoServer = mock( CommunityNeoServer.class ); when( neoServer.baseUri() ).thenReturn( new URI( "http://localhost:7575" ) ); when( neoServer.getWebServer() ).thenReturn( webServer ); - when( neoServer.getDatabase() ).thenReturn( mock(Database.class)); + Database database = mock( Database.class ); + when( neoServer.getDatabase() ).thenReturn( database ); Config config = mock( Config.class ); List jaxRsPackages = new ArrayList<>(); diff --git a/community/server/src/test/java/org/neo4j/server/rest/transactional/ConcurrentTransactionAccessTest.java b/community/server/src/test/java/org/neo4j/server/rest/transactional/ConcurrentTransactionAccessTest.java index d8f626841051b..837c9f9df88fe 100644 --- a/community/server/src/test/java/org/neo4j/server/rest/transactional/ConcurrentTransactionAccessTest.java +++ b/community/server/src/test/java/org/neo4j/server/rest/transactional/ConcurrentTransactionAccessTest.java @@ -50,8 +50,8 @@ public void shouldThrowSpecificExceptionOnConcurrentTransactionAccess() throws E new TransactionHandleRegistry( mock( Clock.class), 0, NullLogProvider.getInstance() ); TransitionalPeriodTransactionMessContainer kernel = mock( TransitionalPeriodTransactionMessContainer.class ); GraphDatabaseQueryService queryService = mock( GraphDatabaseQueryService.class ); - when(kernel.newTransaction( any( KernelTransaction.Type.class ), any( LoginContext.class ), anyLong() ) ) - .thenReturn( mock(TransitionalTxManagementKernelTransaction.class) ); + TransitionalTxManagementKernelTransaction kernelTransaction = mock( TransitionalTxManagementKernelTransaction.class ); + when(kernel.newTransaction( any( KernelTransaction.Type.class ), any( LoginContext.class ), anyLong() ) ).thenReturn( kernelTransaction ); TransactionFacade actions = new TransactionFacade( kernel, null, queryService, registry, NullLogProvider.getInstance() ); final TransactionHandle transactionHandle = diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/catchup/tx/TxPullRequestHandlerTest.java b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/catchup/tx/TxPullRequestHandlerTest.java index a65ef7065e4f0..315ea1ae02141 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/catchup/tx/TxPullRequestHandlerTest.java +++ b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/catchup/tx/TxPullRequestHandlerTest.java @@ -71,7 +71,8 @@ public void shouldRespondWithCompleteStreamOfTransactions() throws Exception // given when( transactionIdStore.getLastCommittedTransactionId() ).thenReturn( 15L ); when( logicalTransactionStore.getTransactions( 14L ) ).thenReturn( txCursor( cursor( tx( 14 ), tx( 15 ) ) ) ); - when( context.writeAndFlush( any() ) ).thenReturn( mock( ChannelFuture.class ) ); + ChannelFuture channelFuture = mock( ChannelFuture.class ); + when( context.writeAndFlush( any() ) ).thenReturn( channelFuture ); // when txPullRequestHandler.channelRead0( context, new TxPullRequest( 13, storeId ) ); diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/core/state/machines/locks/LeaderOnlyLockManagerTest.java b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/core/state/machines/locks/LeaderOnlyLockManagerTest.java index 96066f5a7042b..b8c2f69db87b7 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/core/state/machines/locks/LeaderOnlyLockManagerTest.java +++ b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/core/state/machines/locks/LeaderOnlyLockManagerTest.java @@ -52,7 +52,8 @@ public void shouldIssueLocksOnLeader() throws Exception LeaderLocator leaderLocator = mock( LeaderLocator.class ); when( leaderLocator.getLeader() ).thenReturn( me ); Locks locks = mock( Locks.class ); - when( locks.newClient() ).thenReturn( mock( Locks.Client.class ) ); + Locks.Client client = mock( Locks.Client.class ); + when( locks.newClient() ).thenReturn( client ); LeaderOnlyLockManager lockManager = new LeaderOnlyLockManager( me, replicator, leaderLocator, locks, replicatedLockStateMachine ); @@ -77,7 +78,8 @@ public void shouldNotIssueLocksOnNonLeader() throws Exception LeaderLocator leaderLocator = mock( LeaderLocator.class ); when( leaderLocator.getLeader() ).thenReturn( leader ); Locks locks = mock( Locks.class ); - when( locks.newClient() ).thenReturn( mock( Locks.Client.class ) ); + Locks.Client client = mock( Locks.Client.class ); + when( locks.newClient() ).thenReturn( client ); LeaderOnlyLockManager lockManager = new LeaderOnlyLockManager( me, replicator, leaderLocator, locks, replicatedLockStateMachine ); diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/core/state/machines/token/ReplicatedTokenHolderTest.java b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/core/state/machines/token/ReplicatedTokenHolderTest.java index 1f657179b8a45..d8ccb7ccb044c 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/core/state/machines/token/ReplicatedTokenHolderTest.java +++ b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/core/state/machines/token/ReplicatedTokenHolderTest.java @@ -140,7 +140,8 @@ public void visitCreatedLabelToken( String name, int id ) any( StorageStatement.class ), any( ResourceLocker.class ), anyLong() ); StoreReadLayer readLayer = mock( StoreReadLayer.class ); - when( readLayer.newStatement() ).thenReturn( mock( StorageStatement.class ) ); + StorageStatement statement = mock( StorageStatement.class ); + when( readLayer.newStatement() ).thenReturn( statement ); when( storageEngine.storeReadLayer() ).thenReturn( readLayer ); return storageEngine; } diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/discovery/HazelcastClientTest.java b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/discovery/HazelcastClientTest.java index 1dd45d1b4ab73..bbc6042f53cbd 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/discovery/HazelcastClientTest.java +++ b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/discovery/HazelcastClientTest.java @@ -267,7 +267,8 @@ public void shouldReturnEmptyTopologyIfUnableToConnectToHazelcast() HazelcastInstance hazelcastInstance = mock( HazelcastInstance.class ); when( connector.connectToHazelcast() ).thenThrow( new IllegalStateException() ); - when( hazelcastInstance.getAtomicReference( anyString() ) ).thenReturn( mock( IAtomicReference.class ) ); + IAtomicReference iAtomicReference = mock( IAtomicReference.class ); + when( hazelcastInstance.getAtomicReference( anyString() ) ).thenReturn( iAtomicReference ); when( hazelcastInstance.getSet( anyString() ) ).thenReturn( new HazelcastSet() ); OnDemandJobScheduler jobScheduler = new OnDemandJobScheduler(); @@ -310,7 +311,8 @@ public void shouldRegisterReadReplicaInTopology() HazelcastMultiMap hazelcastMultiMap = new HazelcastMultiMap(); HazelcastInstance hazelcastInstance = mock( HazelcastInstance.class ); - when( hazelcastInstance.getAtomicReference( anyString() ) ).thenReturn( mock( IAtomicReference.class ) ); + IAtomicReference iAtomicReference = mock( IAtomicReference.class ); + when( hazelcastInstance.getAtomicReference( anyString() ) ).thenReturn( iAtomicReference ); when( hazelcastInstance.getMap( anyString() ) ).thenReturn( hazelcastMap ); when( hazelcastInstance.getMultiMap( anyString() ) ).thenReturn( hazelcastMultiMap ); when( hazelcastInstance.getLocalEndpoint() ).thenReturn( endpoint ); @@ -354,7 +356,8 @@ public void shouldRemoveReadReplicasOnGracefulShutdown() HazelcastMap hazelcastMap = new HazelcastMap(); HazelcastInstance hazelcastInstance = mock( HazelcastInstance.class ); - when( hazelcastInstance.getAtomicReference( anyString() ) ).thenReturn( mock( IAtomicReference.class ) ); + IAtomicReference iAtomicReference = mock( IAtomicReference.class ); + when( hazelcastInstance.getAtomicReference( anyString() ) ).thenReturn( iAtomicReference ); when( hazelcastInstance.getMap( anyString() ) ).thenReturn( hazelcastMap ); when( hazelcastInstance.getMultiMap( anyString() ) ).thenReturn( new HazelcastMultiMap() ); when( hazelcastInstance.getLocalEndpoint() ).thenReturn( endpoint ); diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/routing/load_balancing/procedure/GetServersProcedureV2Test.java b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/routing/load_balancing/procedure/GetServersProcedureV2Test.java index dde7427b85d48..55a7036c673cd 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/routing/load_balancing/procedure/GetServersProcedureV2Test.java +++ b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/routing/load_balancing/procedure/GetServersProcedureV2Test.java @@ -24,6 +24,7 @@ import java.util.Map; import org.neo4j.causalclustering.routing.load_balancing.LoadBalancingPlugin; +import org.neo4j.causalclustering.routing.load_balancing.LoadBalancingProcessor; import org.neo4j.internal.kernel.api.procs.FieldSignature; import org.neo4j.internal.kernel.api.procs.ProcedureSignature; @@ -63,7 +64,8 @@ public void shouldPassClientContextToPlugin() throws Exception { // given LoadBalancingPlugin plugin = mock( LoadBalancingPlugin.class ); - when( plugin.run( anyMap() ) ).thenReturn( mock( LoadBalancingPlugin.Result.class ) ); + LoadBalancingProcessor.Result result = mock( LoadBalancingPlugin.Result.class ); + when( plugin.run( anyMap() ) ).thenReturn( result ); GetServersProcedureForMultiDC getServers = new GetServersProcedureForMultiDC( plugin ); Map clientContext = stringMap( "key", "value", "key2", "value2" ); diff --git a/enterprise/cluster/src/test/java/org/neo4j/cluster/com/NetworkReceiverTest.java b/enterprise/cluster/src/test/java/org/neo4j/cluster/com/NetworkReceiverTest.java index f1ffe2ba7f434..a2bf0c5ce0586 100644 --- a/enterprise/cluster/src/test/java/org/neo4j/cluster/com/NetworkReceiverTest.java +++ b/enterprise/cluster/src/test/java/org/neo4j/cluster/com/NetworkReceiverTest.java @@ -72,7 +72,8 @@ public void testGetURIWithLocalHost() public void testMessageReceivedOriginFix() throws Exception { LogProvider logProvider = mock( LogProvider.class ); - when( logProvider.getLog( NetworkReceiver.class ) ).thenReturn( mock( Log.class ) ); + Log log = mock( Log.class ); + when( logProvider.getLog( NetworkReceiver.class ) ).thenReturn( log ); NetworkReceiver networkReceiver = new NetworkReceiver( mock( NetworkReceiver.Monitor.class ), mock( NetworkReceiver.Configuration.class ), logProvider ); diff --git a/enterprise/cluster/src/test/java/org/neo4j/cluster/protocol/election/ElectionStateTest.java b/enterprise/cluster/src/test/java/org/neo4j/cluster/protocol/election/ElectionStateTest.java index 2233296dccefa..45c83cab2b74e 100644 --- a/enterprise/cluster/src/test/java/org/neo4j/cluster/protocol/election/ElectionStateTest.java +++ b/enterprise/cluster/src/test/java/org/neo4j/cluster/protocol/election/ElectionStateTest.java @@ -36,7 +36,7 @@ import org.neo4j.cluster.protocol.MessageArgumentMatcher; import org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.AtomicBroadcastMessage; import org.neo4j.cluster.protocol.cluster.ClusterContext; -import org.neo4j.cluster.protocol.cluster.ClusterMessage; +import org.neo4j.cluster.protocol.cluster.ClusterMessage.VersionedConfigurationStateChange; import org.neo4j.logging.NullLog; import static org.junit.Assert.assertEquals; @@ -256,8 +256,9 @@ public void shouldSendAtomicBroadcastOnJoiningAClusterWithAnEstablishedCoordinat when( electionContext.getElectionWinner( COORDINATOR ) ).thenReturn( winner ); when( electionContext.getLog( any( Class.class ) ) ).thenReturn( NullLog.getInstance() ); + VersionedConfigurationStateChange stateChange = mock( VersionedConfigurationStateChange.class ); when( electionContext.newConfigurationStateChange() ) - .thenReturn( mock( ClusterMessage.VersionedConfigurationStateChange.class ) ); + .thenReturn( stateChange ); when( electionContext.getUriForId( winner ) ).thenReturn( URI.create( winnerURI ) ); diff --git a/enterprise/cluster/src/test/java/org/neo4j/cluster/protocol/snapshot/SnapshotStateTest.java b/enterprise/cluster/src/test/java/org/neo4j/cluster/protocol/snapshot/SnapshotStateTest.java index 378729ced38e1..5e18e59d4aa53 100644 --- a/enterprise/cluster/src/test/java/org/neo4j/cluster/protocol/snapshot/SnapshotStateTest.java +++ b/enterprise/cluster/src/test/java/org/neo4j/cluster/protocol/snapshot/SnapshotStateTest.java @@ -75,7 +75,8 @@ private void baseNoSendTest( Map extraMembers ) throws Throwable SnapshotContext context = mock( SnapshotContext.class ); when( context.getClusterContext() ).thenReturn( clusterContext ); - when( context.getSnapshotProvider() ).thenReturn( mock( SnapshotProvider.class ) ); + SnapshotProvider snapshotProvider = mock( SnapshotProvider.class ); + when( context.getSnapshotProvider() ).thenReturn( snapshotProvider ); Message message = Message.to( SnapshotMessage.refreshSnapshot, me ); diff --git a/enterprise/ha/src/test/java/org/neo4j/ha/upgrade/MasterClientTest.java b/enterprise/ha/src/test/java/org/neo4j/ha/upgrade/MasterClientTest.java index d6e79e2fe3720..1b96db85bf10c 100644 --- a/enterprise/ha/src/test/java/org/neo4j/ha/upgrade/MasterClientTest.java +++ b/enterprise/ha/src/test/java/org/neo4j/ha/upgrade/MasterClientTest.java @@ -129,7 +129,8 @@ public void clientShouldReadAndApplyTransactionLogsOnNewLockSessionRequest() thr when( deps.commitProcess() ).thenReturn( commitProcess ); when( deps.logService() ).thenReturn( NullLogService.getInstance() ); when( deps.versionContextSupplier() ).thenReturn( EmptyVersionContextSupplier.EMPTY ); - when( deps.kernelTransactions() ).thenReturn( mock( KernelTransactions.class ) ); + KernelTransactions transactions = mock( KernelTransactions.class ); + when( deps.kernelTransactions() ).thenReturn( transactions ); ResponseUnpacker unpacker = life.add( new TransactionCommittingResponseUnpacker( deps, DEFAULT_BATCH_SIZE, 0 ) ); diff --git a/enterprise/ha/src/test/java/org/neo4j/kernel/ha/cluster/SwitchToSlaveCopyThenBranchTest.java b/enterprise/ha/src/test/java/org/neo4j/kernel/ha/cluster/SwitchToSlaveCopyThenBranchTest.java index c1b9e2fa81c1b..9fd47e6f8babc 100644 --- a/enterprise/ha/src/test/java/org/neo4j/kernel/ha/cluster/SwitchToSlaveCopyThenBranchTest.java +++ b/enterprise/ha/src/test/java/org/neo4j/kernel/ha/cluster/SwitchToSlaveCopyThenBranchTest.java @@ -329,7 +329,7 @@ private SwitchToSlaveCopyThenBranch newSwitchToSlaveSpy() throws Exception StoreCopyClient storeCopyClient = mock( StoreCopyClient.class ); Stream mockStream = mock( Stream.class ); - when( mockStream.filter( any( Predicate.class ) ) ).thenReturn( mock( Stream.class ) ); + when( mockStream.filter( any( Predicate.class ) ) ).thenReturn( mockStream); FileSystemAbstraction fileSystemAbstraction = mock( FileSystemAbstraction.class ); when( fileSystemAbstraction.streamFilesRecursive( any( File.class ) ) ) .thenReturn( mockStream ); diff --git a/enterprise/ha/src/test/java/org/neo4j/kernel/ha/cluster/member/HighAvailabilitySlavesTest.java b/enterprise/ha/src/test/java/org/neo4j/kernel/ha/cluster/member/HighAvailabilitySlavesTest.java index 1e5cc7e1fa932..2c561dacc41ae 100644 --- a/enterprise/ha/src/test/java/org/neo4j/kernel/ha/cluster/member/HighAvailabilitySlavesTest.java +++ b/enterprise/ha/src/test/java/org/neo4j/kernel/ha/cluster/member/HighAvailabilitySlavesTest.java @@ -117,8 +117,9 @@ public void shouldReturnAvailableAndAliveSlaves() new ClusterMember( INSTANCE_ID ).availableAs( SLAVE, HA_URI, StoreId.DEFAULT ) ) ); SlaveFactory slaveFactory = mock( SlaveFactory.class ); + Slave slave = mock( Slave.class ); when( slaveFactory.newSlave( any( LifeSupport.class ), any( ClusterMember.class ), any( String.class ), - any( Integer.class ) ) ).thenReturn( mock( Slave.class ) ); + any( Integer.class ) ) ).thenReturn( slave ); HighAvailabilitySlaves slaves = new HighAvailabilitySlaves( clusterMembers, cluster, slaveFactory, new HostnamePort( null, 0 ) ); @@ -141,8 +142,9 @@ public void shouldClearSlavesWhenNewMasterElected() new ClusterMember( INSTANCE_ID ).availableAs( SLAVE, HA_URI, StoreId.DEFAULT ) ) ); SlaveFactory slaveFactory = mock( SlaveFactory.class ); + Slave slave = mock( Slave.class ); when( slaveFactory.newSlave( any( LifeSupport.class ), any( ClusterMember.class ), any( String.class ), - any( Integer.class ) ) ).thenReturn( mock( Slave.class ), mock( Slave.class ) ); + any( Integer.class ) ) ).thenReturn( slave, slave ); HighAvailabilitySlaves slaves = new HighAvailabilitySlaves( clusterMembers, cluster, slaveFactory, new HostnamePort( "localhost", 0 ) ); diff --git a/enterprise/metrics/src/test/java/org/neo4j/metrics/output/RotatableCsvReporterTest.java b/enterprise/metrics/src/test/java/org/neo4j/metrics/output/RotatableCsvReporterTest.java index 2ec53f78aa0c9..866f38aff73bc 100644 --- a/enterprise/metrics/src/test/java/org/neo4j/metrics/output/RotatableCsvReporterTest.java +++ b/enterprise/metrics/src/test/java/org/neo4j/metrics/output/RotatableCsvReporterTest.java @@ -49,7 +49,8 @@ public class RotatableCsvReporterTest @Test public void stopAllWritersOnStop() throws IOException { - when( fileOutputStreamSupplier.get() ).thenReturn( mock( OutputStream.class ) ); + OutputStream outputStream = mock( OutputStream.class ); + when( fileOutputStreamSupplier.get() ).thenReturn( outputStream ); RotatableCsvReporter reporter = new RotatableCsvReporter( mock( MetricRegistry.class ), Locale.US, TimeUnit.SECONDS, TimeUnit.SECONDS, Clock.defaultClock(), testDirectory.directory(),