当前位置: 首页>>代码示例>>Java>>正文


Java Mockito.reset方法代码示例

本文整理汇总了Java中org.mockito.Mockito.reset方法的典型用法代码示例。如果您正苦于以下问题:Java Mockito.reset方法的具体用法?Java Mockito.reset怎么用?Java Mockito.reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.mockito.Mockito的用法示例。


在下文中一共展示了Mockito.reset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testManagementOperationErrors

import org.mockito.Mockito; //导入方法依赖的package包/类
private void testManagementOperationErrors() throws Exception {
  HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
  HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
  Mockito.when(request.getQueryString()).thenReturn(
      DelegationTokenAuthenticator.OP_PARAM + "=" +
          DelegationTokenAuthenticator.DelegationTokenOperation.
              GETDELEGATIONTOKEN.toString()
  );
  Mockito.when(request.getMethod()).thenReturn("FOO");
  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.verify(response).sendError(
      Mockito.eq(HttpServletResponse.SC_BAD_REQUEST),
      Mockito.startsWith("Wrong HTTP method"));

  Mockito.reset(response);
  Mockito.when(request.getMethod()).thenReturn(
      DelegationTokenAuthenticator.DelegationTokenOperation.
          GETDELEGATIONTOKEN.getHttpMethod()
  );
  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.verify(response).setStatus(
      Mockito.eq(HttpServletResponse.SC_UNAUTHORIZED));
  Mockito.verify(response).setHeader(
      Mockito.eq(KerberosAuthenticator.WWW_AUTHENTICATE),
      Mockito.eq("mock"));
}
 
开发者ID:naver,项目名称:hadoop,代码行数:27,代码来源:TestDelegationTokenAuthenticationHandlerWithMocks.java

示例2: testWriteFirstChunkFailed

import org.mockito.Mockito; //导入方法依赖的package包/类
@Test
public void testWriteFirstChunkFailed() throws IOException {
    InputSource inputSource = Mockito.mock(InputSource.class);
    doThrow(IOException.class).when(inputSource).open();

    when(gatt.getService(eq(serviceUUID))).thenReturn(gattService);
    when(gattService.getCharacteristic(characteristicUUID)).thenReturn(gattCharacteristic);

    WriteCommand writeCommand = new WriteCommand(
            serviceUUID,
            characteristicUUID,
            BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT,
            inputSource,
            commandObserver);

    writeCommand.execute(device, operationCommandObserver, gatt);
    CommandResult result = CommandResult.createErrorResult(characteristicUUID, BluetoothGatt.GATT_FAILURE);
    verify(commandObserver, times(1)).finished(eq(writeCommand), refEq(result, "timestamp"));
    verify(operationCommandObserver, times(1)).finished(eq(writeCommand), refEq(result, "timestamp"));
    Mockito.reset(commandObserver, operationCommandObserver, inputSource);

    when(inputSource.nextChunk()).thenThrow(IOException.class);
    writeCommand.execute(device, operationCommandObserver, gatt);
    verify(commandObserver, times(1)).finished(eq(writeCommand), refEq(result, "timestamp"));
    verify(operationCommandObserver, times(1)).finished(eq(writeCommand), refEq(result, "timestamp"));
}
 
开发者ID:inovait,项目名称:neatle,代码行数:27,代码来源:WriteCommandTest.java

示例3: setupSpySession

import org.mockito.Mockito; //导入方法依赖的package包/类
private void setupSpySession(final List<String> capturedRequestSessionTokenList, final List<String> capturedResponseSessionTokenList, 
        RxDocumentClientImpl spyClient, final RxDocumentClientImpl origClient) throws DocumentClientException {

    Mockito.reset(spyClient);
    doAnswer(new Answer<Void>() {
        public Void answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            RxDocumentServiceRequest req = (RxDocumentServiceRequest) args[0];
            DocumentServiceResponse resp = (DocumentServiceResponse) args[1];

            capturedRequestSessionTokenList.add(req.getHeaders().get(HttpConstants.HttpHeaders.SESSION_TOKEN));
            capturedResponseSessionTokenList.add(resp.getResponseHeaders().get(HttpConstants.HttpHeaders.SESSION_TOKEN));

            origClient.captureSessionToken(req, resp);

            return null;
        }})
    .when(spyClient).captureSessionToken(Mockito.any(RxDocumentServiceRequest.class), Mockito.any(DocumentServiceResponse.class));
}
 
开发者ID:Azure,项目名称:azure-documentdb-rxjava,代码行数:20,代码来源:SessionTest.java

示例4: capturePrivilegedOperation

import org.mockito.Mockito; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private PrivilegedOperation capturePrivilegedOperation()
    throws PrivilegedOperationException {
  ArgumentCaptor<PrivilegedOperation> opCaptor = ArgumentCaptor.forClass(
      PrivilegedOperation.class);

  //single invocation expected
  //due to type erasure + mocking, this verification requires a suppress
  // warning annotation on the entire method
  verify(mockExecutor, times(1))
      .executePrivilegedOperation(anyList(), opCaptor.capture(), any(
          File.class), any(Map.class), eq(false));

  //verification completed. we need to isolate specific invications.
  // hence, reset mock here
  Mockito.reset(mockExecutor);

  return opCaptor.getValue();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:20,代码来源:TestDockerContainerRuntime.java

示例5: testValidateAlreadyCached

import org.mockito.Mockito; //导入方法依赖的package包/类
@Test
public void testValidateAlreadyCached() throws IOException{
	byte[] bytes = "{ 'key': 'value' }".getBytes(StandardCharsets.UTF_8);
	HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
	Mockito.doReturn(new CachingServletInputStream(new ByteArrayInputStream(bytes))).when(request).getInputStream();
	Mockito.doReturn(toParamMap(params)).when(request).getParameterMap();
	CachingHttpServletRequest cachingRequest = CachingHttpServletRequest.getOrCreate(request);
	Assert.assertNotNull(cachingRequest.getContent());
	Mockito.reset(request);

	SecurityValidationResult result = validator.validate(cachingRequest);
	Mockito.verify(request, Mockito.never()).getInputStream();
	Assert.assertSame(result.getWrappedRequest(), cachingRequest);
}
 
开发者ID:hotpads,项目名称:datarouter,代码行数:15,代码来源:DefaultSignatureValidatorTests.java

示例6: doesntSetIfEmptyProperties

import org.mockito.Mockito; //导入方法依赖的package包/类
@Test
public void doesntSetIfEmptyProperties() {
    Mockito.reset(request);
    mavenGoal.setProperties(new Properties());
    mavenGoal.execution(null, null);
    verify(request, times(0)).setProperties((Properties)any());
}
 
开发者ID:paypal,项目名称:butterfly,代码行数:8,代码来源:MavenGoalTest.java

示例7: addMultipleEventHandlerTest

import org.mockito.Mockito; //导入方法依赖的package包/类
@Test
public void addMultipleEventHandlerTest() {
    AbstractPlayerEventHandlerImpl abstractEventHandlers = getPlayerEventHandler();
    PlayerEventHandler handler = mock(PlayerEventHandler.class);

    abstractEventHandlers.addHandler(handler, PlayerEvent.getType(PlayerEventTypes.LOAD_PAGE_VIEW));

    // test
    PlayerEvent event = new PlayerEvent(PlayerEventTypes.LOAD_PAGE_VIEW);
    abstractEventHandlers.fireEvent(event);
    verify(handler).onPlayerEvent(event);
    Mockito.reset(handler);
}
 
开发者ID:YoungDigitalPlanet,项目名称:empiria.player,代码行数:14,代码来源:AbstractEventHandlersTest.java

示例8: testConnect

import org.mockito.Mockito; //导入方法依赖的package包/类
@Test
public void testConnect() throws Exception {
  // The test connects the plugin to the ledger by default, so disconnect first.
  this.mockLedgerPlugin.disconnect();
  Mockito.reset(ledgerPluginEventHandlerMock);

  this.mockLedgerPlugin.connect();
  assertThat(mockLedgerPlugin.isConnected(), is(true));

  verify(ledgerPluginEventHandlerMock).onConnect(any());
  verifyNoMoreInteractions(ledgerPluginEventHandlerMock);
  assertThat(mockLedgerPlugin.getSimulatedLedger().getConnections().size(), is(1));
}
 
开发者ID:interledger,项目名称:java-ilp-plugin,代码行数:14,代码来源:AbstractMockLedgerPluginTest.java

示例9: checkFatalsAndReset

import org.mockito.Mockito; //导入方法依赖的package包/类
private void checkFatalsAndReset() throws Exception {
  for (int i = 0; i < NUM_ELECTORS; i++) {
    Mockito.verify(cbs[i], Mockito.never()).notifyFatalError(
        Mockito.anyString());
    Mockito.reset(cbs[i]);
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:8,代码来源:TestActiveStandbyElectorRealZK.java

示例10: testInvokeRequest

import org.mockito.Mockito; //导入方法依赖的package包/类
@Test
public void testInvokeRequest() {
    instance.setFlowRequestsInvoker(requestInvoker);
    doReturn(null).when(instance)
            .getCurrentGroupIdentifier();

    instance.isSelected = true;
    instance.invokeRequest();
    verify(requestInvoker).invokeRequest(Matchers.any(FlowRequest.Continue.class));

    Mockito.reset(requestInvoker);
    instance.isSelected = false;
    instance.invokeRequest();
    verify(requestInvoker).invokeRequest(Matchers.any(FlowRequest.ShowAnswers.class));
}
 
开发者ID:YoungDigitalPlanet,项目名称:empiria.player,代码行数:16,代码来源:ShowAnswersButtonModuleTest.java

示例11: testDoesNotCheckDirectories

import org.mockito.Mockito; //导入方法依赖的package包/类
/**
 * Test to make sure that we don't attempt to ask the delegate whether or not we should preserve a
 * directory.
 * @throws Exception on failure
 */
@Test
public void testDoesNotCheckDirectories() throws Exception {
  Stoppable stop = new StoppableImplementation();
  Configuration conf = UTIL.getConfiguration();
  Path testDir = UTIL.getDataTestDir();
  FileSystem fs = UTIL.getTestFileSystem();
  String confKey = "hbase.test.cleaner.delegates";
  conf.set(confKey, AlwaysDelete.class.getName());

  AllValidPaths chore = new AllValidPaths("test-file-cleaner", stop, conf, fs, testDir, confKey);
  // spy on the delegate to ensure that we don't check for directories
  AlwaysDelete delegate = (AlwaysDelete) chore.cleanersChain.get(0);
  AlwaysDelete spy = Mockito.spy(delegate);
  chore.cleanersChain.set(0, spy);

  // create the directory layout in the directory to clean
  Path parent = new Path(testDir, "parent");
  Path file = new Path(parent, "someFile");
  fs.mkdirs(parent);
  assertTrue("Test parent didn't get created.", fs.exists(parent));
  // touch a new file
  fs.create(file).close();
  assertTrue("Test file didn't get created.", fs.exists(file));
  
  FileStatus fStat = fs.getFileStatus(parent);
  chore.chore();
  // make sure we never checked the directory
  Mockito.verify(spy, Mockito.never()).isFileDeletable(fStat);
  Mockito.reset(spy);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:36,代码来源:TestCleanerChore.java

示例12: before

import org.mockito.Mockito; //导入方法依赖的package包/类
@Before
public void before() {
    Mockito.reset(candidateMatchPair);
}
 
开发者ID:mattvickery,项目名称:dsMatch,代码行数:5,代码来源:BooleanMatchingStrategyBuilderTest.java

示例13: setup

import org.mockito.Mockito; //导入方法依赖的package包/类
@Before
public void setup() {
    Mockito.reset(amazonDynamoDB);
    scanResult = new ScanResult();
}
 
开发者ID:simplymequeeny,项目名称:dynamodb-client-web-gui,代码行数:6,代码来源:TableControllerTest.java

示例14: doTestFailedSaveNamespace

import org.mockito.Mockito; //导入方法依赖的package包/类
/**
 * Injects a failure on all storage directories while saving namespace.
 *
 * @param restoreStorageAfterFailure if true, will try to save again after
 *   clearing the failure injection
 */
public void doTestFailedSaveNamespace(boolean restoreStorageAfterFailure)
throws Exception {
  Configuration conf = getConf();
  NameNode.initMetrics(conf, NamenodeRole.NAMENODE);
  DFSTestUtil.formatNameNode(conf);
  FSNamesystem fsn = FSNamesystem.loadFromDisk(conf);

  // Replace the FSImage with a spy
  final FSImage originalImage = fsn.getFSImage();
  NNStorage storage = originalImage.getStorage();
  storage.close(); // unlock any directories that FSNamesystem's initialization may have locked

  NNStorage spyStorage = spy(storage);
  originalImage.storage = spyStorage;
  FSImage spyImage = spy(originalImage);
  Whitebox.setInternalState(fsn, "fsImage", spyImage);

  spyImage.storage.setStorageDirectories(
      FSNamesystem.getNamespaceDirs(conf), 
      FSNamesystem.getNamespaceEditsDirs(conf));

  doThrow(new IOException("Injected fault: saveFSImage")).
      when(spyImage).saveFSImage(
          (SaveNamespaceContext)anyObject(),
          (StorageDirectory)anyObject(), (NameNodeFile) anyObject());

  try {
    doAnEdit(fsn, 1);

    // Save namespace
    fsn.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
    try {
      fsn.saveNamespace();
      fail("saveNamespace did not fail even when all directories failed!");
    } catch (IOException ioe) {
      LOG.info("Got expected exception", ioe);
    }
    
    // Ensure that, if storage dirs come back online, things work again.
    if (restoreStorageAfterFailure) {
      Mockito.reset(spyImage);
      spyStorage.setRestoreFailedStorage(true);
      fsn.saveNamespace();
      checkEditExists(fsn, 1);
    }

    // Now shut down and restart the NN
    originalImage.close();
    fsn.close();
    fsn = null;

    // Start a new namesystem, which should be able to recover
    // the namespace from the previous incarnation.
    fsn = FSNamesystem.loadFromDisk(conf);

    // Make sure the image loaded including our edits.
    checkEditExists(fsn, 1);
  } finally {
    if (fsn != null) {
      fsn.close();
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:70,代码来源:TestSaveNamespace.java

示例15: beforeMethod

import org.mockito.Mockito; //导入方法依赖的package包/类
@BeforeMethod
public void beforeMethod() {
    Mockito.reset(this.spyGateway);
}
 
开发者ID:Azure,项目名称:azure-documentdb-rxjava,代码行数:5,代码来源:RetryCreateDocumentTest.java


注:本文中的org.mockito.Mockito.reset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。