@SuppressWarnings( "unchecked" ) private static IndexStoreView newStoreView( EntityUpdates... updates ) { IndexStoreView storeView = mock( IndexStoreView.class ); when( storeView.visitNodes( any(), any(), any(), any(), anyBoolean() ) ).thenAnswer( invocation -> { Visitor<EntityUpdates,IndexPopulationFailedKernelException> visitorArg = invocation.getArgument( 2 ); return new IndexEntryUpdateScan( updates, visitorArg ); } ); return storeView; }
@SuppressWarnings( "unchecked" ) void getsProcessedByStoreScanFrom( IndexStoreView mock ) { when( mock.visitNodes( any(int[].class), any( IntPredicate.class ), any( Visitor.class ), isNull(), anyBoolean() ) ).thenAnswer( this ); }
@Test public void shouldCallIndexSeek() throws KernelException { // GIVEN Read read = mock( Read.class ); IndexReference index = mock( IndexReference.class ); when( index.properties() ).thenReturn( new int[]{42} ); // WHEN CompiledIndexUtils.indexSeek( read, mock( CursorFactory.class ), index, "hello" ); // THEN verify( read, times( 1 ) ).nodeIndexSeek( any(), any(), any(), anyBoolean(), any() ); }
@Test public void tryUserAnsii() { when(validation.isUTF8(any(byte[].class), anyBoolean())).thenReturn(new Result(Validation.MAYBE, null)); when(validation.isUTF16(any(byte[].class), anyBoolean())).thenReturn(Result.newValid(StandardCharsets.UTF_16)); when(validation.isValidUTF16(any(byte[].class), anyBoolean())).thenReturn(true); when(validation.tryDecode(any(byte[].class), eq(StandardCharsets.ISO_8859_1))).thenReturn(true); charsets = new ByteCharsetDetector(validation, StandardCharsets.ISO_8859_1); assertThat(charsets.detect(new byte[1])).isEqualTo(StandardCharsets.ISO_8859_1); }
@Before public void setUp() throws Exception { when(dbClient.openSession(anyBoolean())) .thenThrow(new IllegalStateException("ProjectConfigurationLoaderImpl should not open DB session")); when(dbClient.propertiesDao()).thenReturn(propertiesDao); }
@Test public void runsConsistencyCheck() throws Exception { // given DatabaseLayout databaseLayout = testDirectory.databaseLayout(); String[] args = {databaseLayout.databaseDirectory().getAbsolutePath()}; ConsistencyCheckService service = mock( ConsistencyCheckService.class ); // when runConsistencyCheckToolWith( service, args ); // then verify( service ).runFullConsistencyCheck( eq( databaseLayout ), any( Config.class ), any( ProgressMonitorFactory.class ), any( LogProvider.class ), any( FileSystemAbstraction.class ), anyBoolean(), any( ConsistencyFlags.class ) ); }
@Before public void wireMocks() { when(dbClient.openSession(anyBoolean())).thenReturn(dbSession); when(dbSession.getMapper(IsAliveMapper.class)).thenReturn(isAliveMapper); }
@Test public void shouldHandleNullInIndexSeek() throws KernelException { // GIVEN Read read = mock( Read.class ); IndexReference index = mock( IndexReference.class ); when( index.properties() ).thenReturn( new int[]{42} ); // WHEN NodeValueIndexCursor cursor = CompiledIndexUtils.indexSeek( mock( Read.class ), mock( CursorFactory.class ), index, null ); // THEN verify( read, never() ).nodeIndexSeek( any(), any(), any(), anyBoolean() ); assertFalse( cursor.next() ); } }
@Test void shouldMoveToFailedOnRun_fail() throws Throwable { BoltStateMachineV3 machine = getBoltStateMachineInTxReadyState(); // When BoltResponseHandler handler = mock( BoltResponseHandler.class ); doThrow( new RuntimeException( "Error!" ) ).when( handler ).onRecords( any(), anyBoolean() ); machine.process( new RunMessage( "A cypher query" ), handler ); // Then assertThat( machine.state(), instanceOf( FailedState.class ) ); }
@Before public void wireMocksTogether() { when(updateCenterFactory.getUpdateCenter(anyBoolean())).thenReturn(Optional.of(updateCenter)); when(updateCenter.getDate()).thenReturn(DateUtils.parseDateTime("2015-04-24T16:08:36+0200")); } }
@ParameterizedTest @MethodSource( "pullAllDiscardAllMessages" ) void shouldMoveFromStreamingStateToFailedStateOnPullAllOrDiscardAll_fail( RequestMessage message ) throws Throwable { // Given BoltStateMachineV3 machine = getBoltStateMachineInStreamingState(); // When BoltResponseHandler handler = mock( BoltResponseHandler.class ); doThrow( new RuntimeException( "Fail" ) ).when( handler ).onRecords( any(), anyBoolean() ); machine.process( message, handler ); // Then assertThat( machine.state(), instanceOf( FailedState.class ) ); }
@ParameterizedTest @MethodSource( "pullAllDiscardAllMessages" ) void shouldMoveFromTxStreamingStateToFailedStateOnPullAllOrDiscardAll_fail( RequestMessage message ) throws Throwable { // Given BoltStateMachineV3 machine = getBoltStateMachineInTxStreamingState(); // When BoltResponseHandler handler = mock( BoltResponseHandler.class ); doThrow( new RuntimeException( "Fail" ) ).when( handler ).onRecords( any(), anyBoolean() ); machine.process( message, handler ); // Then assertThat( machine.state(), instanceOf( FailedState.class ) ); }
@Before public void setUp() { when(dispatcher.getKey()).thenReturn("NewViolations"); when(emailChannel.getKey()).thenReturn("Email"); when(twitterChannel.getKey()).thenReturn("Twitter"); when(dbClient.openSession(anyBoolean())).thenReturn(dbSession); when(dbClient.propertiesDao()).thenReturn(propertiesDao); when(dbClient.notificationQueueDao()).thenReturn(notificationQueueDao); when(dbClient.authorizationDao()).thenReturn(authorizationDao); underTest = new DefaultNotificationManager(new NotificationChannel[] {emailChannel, twitterChannel}, dbClient); }
@Test public void initShouldCreateThreadPool() throws Throwable { ExecutorFactory mockExecutorFactory = mock( ExecutorFactory.class ); when( mockExecutorFactory.create( anyInt(), anyInt(), any(), anyInt(), anyBoolean(), any() ) ).thenReturn( Executors.newCachedThreadPool() ); ExecutorBoltScheduler scheduler = new ExecutorBoltScheduler( CONNECTOR_KEY, mockExecutorFactory, jobScheduler, logService, 0, 10, Duration.ofMinutes( 1 ), 0, ForkJoinPool.commonPool() ); scheduler.start(); verify( jobScheduler ).threadFactory( Group.BOLT_WORKER ); verify( mockExecutorFactory, times( 1 ) ).create( anyInt(), anyInt(), any( Duration.class ), anyInt(), anyBoolean(), any( ThreadFactory.class ) ); }
@Test void databaseAndBackupAreMutuallyExclusive() throws Exception { ConsistencyCheckService consistencyCheckService = mock( ConsistencyCheckService.class ); Path homeDir = testDir.directory( "home" ).toPath(); CheckConsistencyCommand checkConsistencyCommand = new CheckConsistencyCommand( homeDir, testDir.directory( "conf" ).toPath(), consistencyCheckService ); when( consistencyCheckService.runFullConsistencyCheck( any(), any(), any(), any(), any(), anyBoolean(), any( ConsistencyFlags.class ) ) ) .thenReturn( ConsistencyCheckService.Result.success( null ) ); IncorrectUsage incorrectUsage = assertThrows( IncorrectUsage.class, () -> checkConsistencyCommand.execute( new String[]{"--database=foo", "--backup=bar"} ) ); assertEquals( "Only one of '--database' and '--backup' can be specified.", incorrectUsage.getMessage() ); }
@Test public void shutdownShouldTerminateThreadPool() throws Throwable { ExecutorService cachedThreadPool = Executors.newCachedThreadPool(); ExecutorFactory mockExecutorFactory = mock( ExecutorFactory.class ); when( mockExecutorFactory.create( anyInt(), anyInt(), any(), anyInt(), anyBoolean(), any() ) ).thenReturn( cachedThreadPool ); ExecutorBoltScheduler scheduler = new ExecutorBoltScheduler( CONNECTOR_KEY, mockExecutorFactory, jobScheduler, logService, 0, 10, Duration.ofMinutes( 1 ), 0, ForkJoinPool.commonPool() ); scheduler.start(); scheduler.stop(); assertTrue( cachedThreadPool.isShutdown() ); }
@Test public void testResetNextBatchExpiry() throws Exception { client = spy(new MockClient(time, metadata)); setupWithTransactionState(null); accumulator.append(tp0, 0L, "key".getBytes(), "value".getBytes(), null, null, MAX_BLOCK_TIMEOUT); sender.run(time.milliseconds()); sender.run(time.milliseconds()); time.setCurrentTimeMs(time.milliseconds() + accumulator.getDeliveryTimeoutMs() + 1); sender.run(time.milliseconds()); InOrder inOrder = inOrder(client); inOrder.verify(client, atLeastOnce()).ready(any(), anyLong()); inOrder.verify(client, atLeastOnce()).newClientRequest(anyString(), any(), anyLong(), anyBoolean(), anyInt(), any()); inOrder.verify(client, atLeastOnce()).send(any(), anyLong()); inOrder.verify(client).poll(eq(0L), anyLong()); inOrder.verify(client).poll(eq(accumulator.getDeliveryTimeoutMs()), anyLong()); inOrder.verify(client).poll(geq(1L), anyLong()); }
@Test public void empty_array_is_returned_when_update_center_is_unavailable() throws Exception { when(updateCenterFactory.getUpdateCenter(anyBoolean())).thenReturn(Optional.absent()); underTest.handle(request, response); assertJson(response.outputAsString()).withStrictArrayOrder().isSimilarTo(JSON_EMPTY_UPGRADE_LIST); }
@Test public void testIndexAllNodes() throws FlipFailedKernelException { IndexPopulator indexPopulator1 = createIndexPopulator(); IndexPopulator indexPopulator2 = createIndexPopulator(); addPopulator( indexPopulator1, 1 ); addPopulator( indexPopulator2, 2 ); multipleIndexPopulator.create(); multipleIndexPopulator.indexAllEntities(); verify( indexStoreView ) .visitNodes( any( int[].class ), any( IntPredicate.class ), any( Visitor.class ), isNull(), anyBoolean() ); }
@Test public void download_when_update_center_is_unavailable_with_no_exception_thrown() { when(updateCenterMatrixFactory.getUpdateCenter(anyBoolean())).thenReturn(Optional.absent()); Plugin test = Plugin.factory("test"); Release test10 = new Release(test, "1.0").setDownloadUrl("http://server/test-1.0.jar"); test.addRelease(test10); pluginDownloader.start(); pluginDownloader.download("foo", create("1.0")); }