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


Java Answer类代码示例

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


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

示例1: createOkResponseWithCookie

import org.mockito.stubbing.Answer; //导入依赖的package包/类
private Answer<HttpResponse> createOkResponseWithCookie() {
    return new Answer<HttpResponse>() {
        @Override
        public HttpResponse answer(InvocationOnMock invocation) throws Throwable {
            HttpContext context = (HttpContext) invocation.getArguments()[1];
            if (context.getAttribute(ClientContext.COOKIE_STORE) != null) {
                BasicCookieStore cookieStore =
                        (BasicCookieStore) context.getAttribute(ClientContext.COOKIE_STORE);
                BasicClientCookie cookie = new BasicClientCookie("cookie", "meLikeCookie");
                cookieStore.addCookie(cookie);
            }

            return OK_200_RESPONSE;
        }
    };
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:17,代码来源:WebDavStoreTest.java

示例2: test

import org.mockito.stubbing.Answer; //导入依赖的package包/类
@Test
public void test() throws Exception {
  assumeNonMaprProfile();
  final IOException ioException = new IOException("test io exception");
  final FSError fsError = newFSError(ioException);
  FileSystem underlyingFS = mock(FileSystem.class, new Answer<Object>() {
    @Override
    public Object answer(InvocationOnMock invocation) throws Throwable {
      if (!invocation.getMethod().getName().equals("getScheme")) {
        throw fsError;
      }
      return "mockfs";
    }
  });
  Configuration conf = new Configuration(false);
  FileSystemWrapper fsw = new FileSystemWrapper(conf, underlyingFS, null);
  Object[] params = FSErrorTestUtils.getDummyArguments(method);
  try {
    method.invoke(fsw, params);
  } catch(InvocationTargetException e) {
    assertThat(e.getTargetException(), is(instanceOf(IOException.class)));
    assertThat((IOException) e.getTargetException(), is(sameInstance(ioException)));
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:25,代码来源:TestFileSystemWrapperFSError.java

示例3: shouldNotifyClientsOnStateChanged_bothClients

import org.mockito.stubbing.Answer; //导入依赖的package包/类
@Test
public void shouldNotifyClientsOnStateChanged_bothClients() {
    // given
    StateChangeEvent event = mockStateChangeEvent(true, false);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            EndHandler handler = (EndHandler) invocation.getArguments()[0];
            handler.onEnd();
            return null;
        }
    }).when(tutor).processUserInteraction(any(EndHandler.class));
    mediator.registerTutor(tutor);
    mediator.registerBonus(bonus);

    // when
    stateChangedHandler.onStateChange(event);

    // then
    InOrder inOrder = Mockito.inOrder(tutor, bonus);
    inOrder.verify(tutor).processUserInteraction(any(EndHandler.class));
    inOrder.verify(bonus).processUserInteraction();
}
 
开发者ID:YoungDigitalPlanet,项目名称:empiria.player,代码行数:25,代码来源:PowerFeedbackMediatorTest.java

示例4: testCheckIfAvailableWithSimulatedHeartBeat

import org.mockito.stubbing.Answer; //导入依赖的package包/类
@Test
public void testCheckIfAvailableWithSimulatedHeartBeat() {
  NetView v = installAView();

  InternalDistributedMember memberToCheck = mockMembers.get(1);
  HeartbeatMessage fakeHeartbeat = new HeartbeatMessage();
  fakeHeartbeat.setSender(memberToCheck);
  when(messenger.send(any(HeartbeatRequestMessage.class))).then(new Answer() {
    @Override
    public Object answer(InvocationOnMock invocation) throws Throwable {
      gmsHealthMonitor.processMessage(fakeHeartbeat);
      return null;
    }
  });

  boolean retVal = gmsHealthMonitor.checkIfAvailable(memberToCheck, "Not responding", true);
  assertTrue("CheckIfAvailable should have return true", retVal);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:19,代码来源:GMSHealthMonitorJUnitTest.java

示例5: add_requestFinishedListenerCanceled

import org.mockito.stubbing.Answer; //导入依赖的package包/类
/**
 * Verify RequestFinishedListeners are informed when requests are canceled
 *
 * Needs to be an integration test because relies on Request -> dispatcher -> RequestQueue interaction
 */
@Test public void add_requestFinishedListenerCanceled() throws Exception {
    RequestFinishedListener listener = mock(RequestFinishedListener.class);
    Request request = new MockRequest();
    Answer<NetworkResponse> delayAnswer = new Answer<NetworkResponse>() {
        @Override
        public NetworkResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
            Thread.sleep(200);
            return mock(NetworkResponse.class);
        }
    };
    RequestQueue queue = new RequestQueue(new NoCache(), mMockNetwork, 1, mDelivery);

    when(mMockNetwork.performRequest(request)).thenAnswer(delayAnswer);

    queue.addRequestFinishedListener(listener);
    queue.start();
    queue.add(request);

    request.cancel();
    verify(listener, timeout(100)).onRequestFinished(request);
    queue.stop();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:28,代码来源:RequestQueueIntegrationTest.java

示例6: shouldCallPlayOrStopEntryOnPlayButtonClick

import org.mockito.stubbing.Answer; //导入依赖的package包/类
@Test
public void shouldCallPlayOrStopEntryOnPlayButtonClick() {
    // given
    String file = "test.mp3";
    Entry entry = mock(Entry.class);
    when(entry.getEntrySound()).thenReturn(file);

    doAnswer(new Answer<Void>() {
        @Override
        public Void answer(InvocationOnMock invocation) {
            clickHandler = (ClickHandler) invocation.getArguments()[0];
            return null;
        }
    }).when(explanationView).addEntryPlayButtonHandler(any(ClickHandler.class));

    // when
    testObj.init();
    testObj.processEntry(entry);
    clickHandler.onClick(null);

    // then
    verify(entryDescriptionSoundController).playOrStopEntrySound(entry.getEntrySound());
}
 
开发者ID:YoungDigitalPlanet,项目名称:empiria.player,代码行数:24,代码来源:ExplanationControllerTest.java

示例7: testReturnsOriginalResourceIfTransformationDoesNotTransform

import org.mockito.stubbing.Answer; //导入依赖的package包/类
@Test
public void testReturnsOriginalResourceIfTransformationDoesNotTransform() {
  int outWidth = 123;
  int outHeight = 456;
  when(wrapped.transform(
      anyContext(), Util.<Bitmap>anyResource(), eq(outWidth), eq(outHeight)))
      .thenAnswer(new Answer<Resource<Bitmap>>() {
        @SuppressWarnings("unchecked")
        @Override
        public Resource<Bitmap> answer(InvocationOnMock invocation) throws Throwable {
          return (Resource<Bitmap>) invocation.getArguments()[1];
        }
      });

  Resource<BitmapDrawable> transformed =
      transformation.transform(context, drawableResourceToTransform, outWidth, outHeight);

  assertThat(transformed).isEqualTo(drawableResourceToTransform);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:BitmapDrawableTransformationTest.java

示例8: createFileSystemForServiceName

import org.mockito.stubbing.Answer; //导入依赖的package包/类
public static MockFileSystem createFileSystemForServiceName(
    final Text service, final FileSystem... children) throws IOException {
  final MockFileSystem fs = new MockFileSystem();
  final MockFileSystem mockFs = fs.getRawFileSystem();
  if (service != null) {
    when(mockFs.getCanonicalServiceName()).thenReturn(service.toString());
    when(mockFs.getDelegationToken(any(String.class))).thenAnswer(
      new Answer<Token<?>>() {
        @Override
        public Token<?> answer(InvocationOnMock invocation) throws Throwable {
          Token<?> token = new Token<TokenIdentifier>();
          token.setService(service);
          return token;
        }
      });
  }
  when(mockFs.getChildFileSystems()).thenReturn(children);
  return fs;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:20,代码来源:TestFileSystemTokens.java

示例9: testHandlesNonEngineResourcesFromCacheIfPresent

import org.mockito.stubbing.Answer; //导入依赖的package包/类
@Test
public void testHandlesNonEngineResourcesFromCacheIfPresent() {
  final Object expected = new Object();
  @SuppressWarnings("rawtypes") Resource fromCache = mockResource();
  when(fromCache.get()).thenReturn(expected);
  when(harness.cache.remove(eq(harness.cacheKey))).thenReturn(fromCache);

  doAnswer(new Answer<Void>() {
    @Override
    public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
      Resource<?> resource = (Resource<?>) invocationOnMock.getArguments()[0];
      assertEquals(expected, resource.get());
      return null;
    }
  }).when(harness.cb).onResourceReady(anyResource(), isADataSource());

  harness.doLoad();

  verify(harness.cb).onResourceReady(anyResource(), isADataSource());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:EngineTest.java

示例10: testNotifiesNewCallbackOfResourceIfCallbackIsAddedDuringOnResourceReady

import org.mockito.stubbing.Answer; //导入依赖的package包/类
@Test
public void testNotifiesNewCallbackOfResourceIfCallbackIsAddedDuringOnResourceReady() {
  final EngineJob<Object> job = harness.getJob();
  final ResourceCallback existingCallback = mock(ResourceCallback.class);
  final ResourceCallback newCallback = mock(ResourceCallback.class);

  doAnswer(new Answer<Void>() {
    @Override
    public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
      job.addCallback(newCallback);
      return null;
    }
  }).when(existingCallback).onResourceReady(anyResource(), isADataSource());

  job.addCallback(existingCallback);
  job.start(harness.decodeJob);
  job.onResourceReady(harness.resource, harness.dataSource);

  verify(newCallback).onResourceReady(eq(harness.engineResource), eq(harness.dataSource));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:EngineJobTest.java

示例11: mockApplicationContext

import org.mockito.stubbing.Answer; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Before
public void mockApplicationContext() {
	final ApplicationContext applicationContext = Mockito.mock(ApplicationContext.class);
	SpringUtils.setSharedApplicationContext(applicationContext);
	mockLdapResource = Mockito.mock(GroupResource.class);
	final GroupFullLdapTask mockTask = new GroupFullLdapTask();
	mockTask.resource = mockLdapResource;
	mockTask.securityHelper = securityHelper;
	mockTask.containerScopeResource = Mockito.mock(ContainerScopeResource.class);
	Mockito.when(applicationContext.getBean(SessionSettings.class)).thenReturn(new SessionSettings());
	Mockito.when(applicationContext.getBean((Class<?>) ArgumentMatchers.any(Class.class))).thenAnswer((Answer<Object>) invocation -> {
		final Class<?> requiredType = (Class<Object>) invocation.getArguments()[0];
		if (requiredType == GroupFullLdapTask.class) {
			return mockTask;
		}
		return GroupBatchLdapResourceTest.super.applicationContext.getBean(requiredType);
	});

	final ContainerScope container = new ContainerScope();
	container.setId(1);
	container.setName("Fonction");
	container.setType(ContainerType.GROUP);
	Mockito.when(mockTask.containerScopeResource.findByName("Fonction")).thenReturn(container);
}
 
开发者ID:ligoj,项目名称:plugin-id,代码行数:26,代码来源:GroupBatchLdapResourceTest.java

示例12: testRemovingCallbackDuringOnExceptionIsIgnoredIfCallbackHasAlreadyBeenCalled

import org.mockito.stubbing.Answer; //导入依赖的package包/类
@Test
public void testRemovingCallbackDuringOnExceptionIsIgnoredIfCallbackHasAlreadyBeenCalled() {
  harness = new EngineJobHarness();
  final EngineJob<Object> job = harness.getJob();
  final ResourceCallback cb = mock(ResourceCallback.class);

  doAnswer(new Answer<Void>() {
    @Override
    public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
      job.removeCallback(cb);
      return null;
    }
  }).when(cb).onLoadFailed(any(GlideException.class));

  GlideException exception = new GlideException("test");
  job.addCallback(cb);
  job.start(harness.decodeJob);
  job.onLoadFailed(exception);

  verify(cb, times(1)).onLoadFailed(eq(exception));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:EngineJobTest.java

示例13: setupUploadMock

import org.mockito.stubbing.Answer; //导入依赖的package包/类
private static void setupUploadMock(UploadService mockUploadService) {
  String jsonString = "{"
      + "'url' : 'https://s3.amazonaws.com/path',"
      + "'headers' : {"
      + "'Authorization' : 'auth_value',"
      + "'Content-MD5' : 'md5_value',"
      + "'x-amz-content-sha256' : 'sha256_value',"
      + "'x-amz-date' : 'date_value',"
      + "'x-amz-acl' : 'acl_value'"
      + "},"
      + "'location_url' : 'url'"
      + "}";

  Gson gson = new Gson();
  final UploadResponse response = gson.fromJson(jsonString, UploadResponse.class);
  Mockito
      .doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
          return Calls.response(response);
        }
      })
      .when(mockUploadService)
      .upload(Mockito.<String, RequestBody>anyMap());
}
 
开发者ID:filestack,项目名称:filestack-java,代码行数:26,代码来源:TestClient.java

示例14: testRemovingCallbackDuringOnExceptionPreventsCallbackFromBeingCalledIfNotYetCalled

import org.mockito.stubbing.Answer; //导入依赖的package包/类
@Test
public void testRemovingCallbackDuringOnExceptionPreventsCallbackFromBeingCalledIfNotYetCalled() {
  harness = new EngineJobHarness();
  final EngineJob<Object> job = harness.getJob();
  final ResourceCallback called = mock(ResourceCallback.class);
  final ResourceCallback notYetCalled = mock(ResourceCallback.class);

  doAnswer(new Answer<Void>() {
    @Override
    public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
      job.removeCallback(notYetCalled);
      return null;
    }
  }).when(called).onLoadFailed(any(GlideException.class));

  job.addCallback(called);
  job.addCallback(notYetCalled);
  job.start(harness.decodeJob);
  job.onLoadFailed(new GlideException("test"));

  verify(notYetCalled, never()).onResourceReady(anyResource(), isADataSource());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:EngineJobTest.java

示例15: shouldCallPlayOrStopDescriptionOnPlayButtonClick

import org.mockito.stubbing.Answer; //导入依赖的package包/类
@Test
public void shouldCallPlayOrStopDescriptionOnPlayButtonClick() {
    // given
    String file = "test.mp3";
    Entry entry = mock(Entry.class);
    when(entry.getEntryExampleSound()).thenReturn(file);

    doAnswer(new Answer<Void>() {
        @Override
        public Void answer(InvocationOnMock invocation) {
            clickHandler = (ClickHandler) invocation.getArguments()[0];
            return null;
        }
    }).when(explanationView).addPlayButtonHandler(any(ClickHandler.class));

    // when
    testObj.init();
    testObj.processEntry(entry);
    clickHandler.onClick(null);

    // then
    verify(explanationDescriptionSoundController).playOrStopExplanationSound(entry.getEntryExampleSound());
}
 
开发者ID:YoungDigitalPlanet,项目名称:empiria.player,代码行数:24,代码来源:ExplanationControllerTest.java


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