static Resources mockResources(final String resValueString) { Resources resources = mock(Resources.class); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); ((TypedValue) args[1]).string = resValueString; return null; } }).when(resources).getValue(anyInt(), any(TypedValue.class), anyBoolean()); return resources; }
@Test public void testTargetIsCalledWithAnimationFromFactory() { SingleRequest<List> request = builder.build(); Transition<List> transition = mockTransition(); when(builder.transitionFactory.build(any(DataSource.class), anyBoolean())) .thenReturn(transition); request.onResourceReady(builder.resource, DataSource.DATA_DISK_CACHE); verify(builder.target).onResourceReady(eq(builder.result), eq(transition)); }
private LockableDatabase createLockableDatabase() throws MessagingException { LockableDatabase lockableDatabase = mock(LockableDatabase.class); when(lockableDatabase.execute(anyBoolean(), any(LockableDatabase.DbCallback.class))).thenReturn(false); return lockableDatabase; }
@Test public void testDoesNotNotifyListenerIfConnectedAndBecomesConnected() { harness.connect(); monitor.onStart(); harness.broadcast(); verify(listener, never()).onConnectivityChanged(anyBoolean()); }
@Test public void testDeleteWorkflow() { workflowService.deleteWorkflow("w123", true); verify(mockExecutionService, times(1)).removeWorkflow(anyString(), anyBoolean()); }
@Test public void bucketWrapperShouldDelegateRemoveBucketToEnclosedOperator() { wrapper.removeBucket(targetMember, bucketId, colocatedRegionBytes); // verify the delegate is invoked verify(delegate, times(1)).removeBucket(targetMember, bucketId, colocatedRegionBytes); // verify we recorded necessary stats verify(stats, times(1)).startBucketRemove(anyInt()); verify(stats, times(1)).endBucketRemove(anyInt(), anyBoolean(), anyLong(), anyLong()); }
@Test public void testListTrans() throws Exception { final String DUMMY_TRANS_2 = "test-trans-name-2"; when( mockRepository.getTransformationNames( anyObject(), anyBoolean() ) ).thenReturn( new String[]{ DUMMY_TRANS_1, DUMMY_TRANS_2 } ); when( mockRepository.loadRepositoryDirectoryTree() ).thenReturn( mockRepositoryDirectory );
@Test @SuppressWarnings("deprecation") public void testDelegateFsMethods() throws IOException { final FileSystem fs = mock(FileSystem.class); when(fs.open(any(Path.class))).thenReturn(mock(FSDataInputStream.class)); when(fs.open(any(Path.class), anyInt())).thenReturn(mock(FSDataInputStream.class)); when(fs.create(any(Path.class), anyBoolean())).thenReturn(mock(FSDataOutputStream.class)); when(fs.create(any(Path.class), any(WriteMode.class))).thenReturn(mock(FSDataOutputStream.class)); when(fs.create(any(Path.class), anyBoolean(), anyInt(), anyShort(), anyLong())).thenReturn(mock(FSDataOutputStream.class)); verify(fs).isDistributedFS(); verify(fs).isDistributedFS(); verify(fs).getHomeDirectory();
@Test(expected = IOException.class) public void shouldThrowExceptionOnDistcpFailure() throws Exception { Path destination = mock(Path.class); Path source = mock(Path.class); FileSystem fs = mock(FileSystem.class); List<Path> srcPaths = Arrays.asList(source, source); HiveConf conf = mock(HiveConf.class); CopyUtils copyUtils = Mockito.spy(new CopyUtils(null, conf)); mockStatic(FileUtils.class); mockStatic(Utils.class); when(destination.getFileSystem(same(conf))).thenReturn(fs); when(source.getFileSystem(same(conf))).thenReturn(fs); when(FileUtils.distCp(same(fs), anyListOf(Path.class), same(destination), anyBoolean(), eq(null), same(conf), same(ShimLoader.getHadoopShims()))) .thenReturn(false); when(Utils.getUGI()).thenReturn(mock(UserGroupInformation.class)); doReturn(false).when(copyUtils).regularCopy(same(fs), same(fs), anyListOf(ReplChangeManager.FileInfo.class)); copyUtils.doCopy(destination, srcPaths); } }
@Test public void testGetTaskFormVariablesThrowsAuthorizationException() { String message = "expected exception"; doThrow(new AuthorizationException(message)).when(formServiceMock).getTaskFormVariables(anyString(), Matchers.<Collection<String>>any(), anyBoolean()); given() .pathParam("id", MockProvider.EXAMPLE_TASK_ID) .then().expect() .statusCode(Status.FORBIDDEN.getStatusCode()) .body("type", equalTo(AuthorizationException.class.getSimpleName())) .body("message", equalTo(message)) .when() .get(FORM_VARIABLES_URL); }
private void addToDeviceNotifications(Notification notificationToReturn) { when(deviceNotifications.buildSummaryNotification( eq(account), eq(newMailNotifications.notificationData), anyBoolean()) ).thenReturn(notificationToReturn); }
@Before public void setup() throws Exception { PowerMockito.mockStatic( SSHData.class ); PowerMockito.mockStatic( KettleVFS.class ); when( SSHData.createConnection( server, port ) ).thenReturn( connection ); when( SSHData.OpenConnection( any(), anyInt(), any(), any(), anyBoolean(), any(), any(), anyInt(), anyObject(), any(), anyInt(), any(), any() ) ).thenCallRealMethod(); when( KettleVFS.getFileObject( keyFilePath ) ).thenReturn( fileObject ); }
@Test public void testDoesNotStartALoadIfOnSizeReadyIsCalledAfterClear() { SingleRequest<List> request = builder.build(); request.clear(); request.onSizeReady(100, 100); verify(builder.engine, never()) .load( eq(builder.glideContext), eq(builder.model), eq(builder.signature), anyInt(), anyInt(), eq(Object.class), eq(List.class), any(Priority.class), any(DiskCacheStrategy.class), eq(builder.transformations), anyBoolean(), anyBoolean(), any(Options.class), anyBoolean(), anyBoolean(), /*useAnimationPool=*/ anyBoolean(), anyBoolean(), any(ResourceCallback.class), anyExecutor()); }
@Test public void onReceive_withMissingPermission_previouslyConnected_doesNotNotifyListeners() { harness.connect(); monitor.onStart(); harness.shadowConnectivityManager.isNetworkPermissionGranted = false; harness.broadcast(); verify(listener, never()).onConnectivityChanged(anyBoolean()); }
@Test public void restart() { workflowResource.restart("w123", false); verify(mockWorkflowService, times(1)).restartWorkflow(anyString(), anyBoolean()); }
@Test public void bucketWrapperShouldDoNotRecordBucketRemovesIfMoveBucketFails() { doReturn(false).when(delegate).removeBucket(targetMember, bucketId, colocatedRegionBytes); wrapper.removeBucket(targetMember, bucketId, colocatedRegionBytes); // verify the details is not updated with bytes transfered for (PartitionRebalanceDetailsImpl details : rebalanceDetails) { verify(details, times(0)).incTransfers(anyLong(), anyLong()); } // verify we recorded necessary stats verify(stats, times(1)).startBucketRemove(anyInt()); verify(stats, times(1)).endBucketRemove(anyInt(), anyBoolean(), anyLong(), anyLong()); }
@Test public void testListJobs() throws Exception { final String DUMMY_JOB_2 = "test-job-name-2"; when( mockRepository.getJobNames( anyObject(), anyBoolean() ) ).thenReturn( new String[]{ DUMMY_JOB_1, DUMMY_JOB_2 } ); when( mockRepository.loadRepositoryDirectoryTree() ).thenReturn( mockRepositoryDirectory );
Engine.LoadStatus doLoad() { when( engineJobFactory.build( eq(cacheKey), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean())) .thenReturn((EngineJob<Object>) job); when(job.onlyRetrieveFromCache()).thenReturn(onlyRetrieveFromCache); return getEngine() .load( glideContext, model, signature, width, height, Object.class /*resourceClass*/, Object.class /*transcodeClass*/, Priority.HIGH, DiskCacheStrategy.ALL, transformations, false /*isTransformationRequired*/, isScaleOnlyOrNoTransform, options, isMemoryCacheable, useUnlimitedSourceGeneratorPool, /*useAnimationPool=*/ false, onlyRetrieveFromCache, cb, Executors.directExecutor()); }
public static HStoreFile createDummyStoreFile(long maxSequenceId) throws Exception { // "Files" are totally unused, it's Scanner class below that gives compactor fake KVs. // But compaction depends on everything under the sun, so stub everything with dummies. HStoreFile sf = mock(HStoreFile.class); StoreFileReader r = mock(StoreFileReader.class); when(r.length()).thenReturn(1L); when(r.getBloomFilterType()).thenReturn(BloomType.NONE); when(r.getHFileReader()).thenReturn(mock(HFile.Reader.class)); when(r.getStoreFileScanner(anyBoolean(), anyBoolean(), anyBoolean(), anyLong(), anyLong(), anyBoolean())).thenReturn(mock(StoreFileScanner.class)); when(sf.getReader()).thenReturn(r); when(sf.getMaxSequenceId()).thenReturn(maxSequenceId); return sf; }
@Test public void testIgnoresOnSizeReadyIfNotWaitingForSize() { SingleRequest<List> request = builder.build(); request.begin(); request.onSizeReady(100, 100); request.onSizeReady(100, 100); verify(builder.engine, times(1)) .load( eq(builder.glideContext), eq(builder.model), eq(builder.signature), eq(100), eq(100), eq(Object.class), eq(List.class), any(Priority.class), any(DiskCacheStrategy.class), eq(builder.transformations), anyBoolean(), anyBoolean(), any(Options.class), anyBoolean(), anyBoolean(), /*useAnimationPool=*/ anyBoolean(), anyBoolean(), any(ResourceCallback.class), anyExecutor()); }