本文整理汇总了Java中org.mockito.internal.stubbing.answers.ThrowsException类的典型用法代码示例。如果您正苦于以下问题:Java ThrowsException类的具体用法?Java ThrowsException怎么用?Java ThrowsException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ThrowsException类属于org.mockito.internal.stubbing.answers包,在下文中一共展示了ThrowsException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFindElementsWhenThereAreDetachedFrames2
import org.mockito.internal.stubbing.answers.ThrowsException; //导入依赖的package包/类
@Test(enabled = false)
public void testFindElementsWhenThereAreDetachedFrames2() {
final List<WebElement> firstLevelFrames = new ArrayList<WebElement>();
final List<WebElement> secondLevelFrames = new ArrayList<WebElement>();
final List<WebElement> thirdLevelFrames = new ArrayList<WebElement>();
final List<WebElement> lastLevelFrames = emptyList();
firstLevelFrames.add(mock(WebElement.class));
final WebElement unstableFrame = mock(WebElement.class);
when(unstableFrame.getTagName())
.thenReturn("iframe")
.thenAnswer(new ThrowsException(new StaleElementReferenceException("stolen")));
secondLevelFrames.add(unstableFrame);
thirdLevelFrames.add(mock(WebElement.class));
when(wrappedDriver.findElements(By.tagName("iframe")))
.thenReturn(firstLevelFrames)
.thenReturn(secondLevelFrames)
.thenReturn(thirdLevelFrames)
.thenReturn(lastLevelFrames);
assertThat(driver.findElements(By.cssSelector("selector")), hasSize(0));
}
示例2: onExceptionOnTheFirstTime
import org.mockito.internal.stubbing.answers.ThrowsException; //导入依赖的package包/类
@Test
public void onExceptionOnTheFirstTime() throws Exception {
DiskRawQueue queue = mock(DiskRawQueue.class);
Lenient.Op op = mock(Lenient.Op.class);
Lenient lenient = new Lenient(queue);
InOrder orderly = inOrder(queue, op);
when(op.call())
.thenAnswer(new ThrowsException(new Error("abc")))
.thenAnswer(new Returns(42L));
assertThat(lenient.perform(op)).isEqualTo(42);
orderly.verify(op).call();
orderly.verify(queue).reopen();
}
示例3: shouldGetResultsForMethods
import org.mockito.internal.stubbing.answers.ThrowsException; //导入依赖的package包/类
@Test
public void shouldGetResultsForMethods() throws Throwable {
invocationContainerImpl.setInvocationForPotentialStubbing(new InvocationMatcher(simpleMethod));
invocationContainerImpl.addAnswer(new Returns("simpleMethod"));
Invocation differentMethod = new InvocationBuilder().differentMethod().toInvocation();
invocationContainerImpl.setInvocationForPotentialStubbing(new InvocationMatcher(differentMethod));
invocationContainerImpl.addAnswer(new ThrowsException(new MyException()));
assertEquals("simpleMethod", invocationContainerImpl.answerTo(simpleMethod));
try {
invocationContainerImpl.answerTo(differentMethod);
fail();
} catch (MyException e) {}
}
示例4: should_get_results_for_methods
import org.mockito.internal.stubbing.answers.ThrowsException; //导入依赖的package包/类
@Test
public void should_get_results_for_methods() throws Throwable {
invocationContainerImpl.setInvocationForPotentialStubbing(new InvocationMatcher(simpleMethod));
invocationContainerImpl.addAnswer(new Returns("simpleMethod"));
Invocation differentMethod = new InvocationBuilder().differentMethod().toInvocation();
invocationContainerImpl.setInvocationForPotentialStubbing(new InvocationMatcher(differentMethod));
invocationContainerImpl.addAnswer(new ThrowsException(new MyException()));
assertEquals("simpleMethod", invocationContainerImpl.answerTo(simpleMethod));
try {
invocationContainerImpl.answerTo(differentMethod);
fail();
} catch (MyException e) {}
}
示例5: should_get_results_for_methods_stub_only
import org.mockito.internal.stubbing.answers.ThrowsException; //导入依赖的package包/类
@Test
public void should_get_results_for_methods_stub_only() throws Throwable {
invocationContainerImplStubOnly.setInvocationForPotentialStubbing(new InvocationMatcher(simpleMethod));
invocationContainerImplStubOnly.addAnswer(new Returns("simpleMethod"));
Invocation differentMethod = new InvocationBuilder().differentMethod().toInvocation();
invocationContainerImplStubOnly.setInvocationForPotentialStubbing(new InvocationMatcher(differentMethod));
invocationContainerImplStubOnly.addAnswer(new ThrowsException(new MyException()));
assertEquals("simpleMethod", invocationContainerImplStubOnly.answerTo(simpleMethod));
try {
invocationContainerImplStubOnly.answerTo(differentMethod);
fail();
} catch (MyException e) {}
}
示例6: testFindElementsWhenThereAreDetachedFrames
import org.mockito.internal.stubbing.answers.ThrowsException; //导入依赖的package包/类
@Test(enabled = false)
public void testFindElementsWhenThereAreDetachedFrames() {
frames.add(mock(WebElement.class));
frames.add(mock(WebElement.class, new ThrowsException(new StaleElementReferenceException("stolen"))));
assertThat(driver.findElements(By.cssSelector("selector")), hasSize(0));
}
示例7: testFailoverFromNonExistantServiceWithFencer
import org.mockito.internal.stubbing.answers.ThrowsException; //导入依赖的package包/类
@Test
public void testFailoverFromNonExistantServiceWithFencer() throws Exception {
DummyHAService svc1 = spy(new DummyHAService(null, svc1Addr));
// Getting a proxy to a dead server will throw IOException on call,
// not on creation of the proxy.
HAServiceProtocol errorThrowingProxy = Mockito.mock(HAServiceProtocol.class,
Mockito.withSettings()
.defaultAnswer(new ThrowsException(
new IOException("Could not connect to host")))
.extraInterfaces(Closeable.class));
Mockito.doNothing().when((Closeable)errorThrowingProxy).close();
Mockito.doReturn(errorThrowingProxy).when(svc1).getProxy(
Mockito.<Configuration>any(),
Mockito.anyInt());
DummyHAService svc2 = new DummyHAService(HAServiceState.STANDBY, svc2Addr);
svc1.fencer = svc2.fencer = setupFencer(AlwaysSucceedFencer.class.getName());
try {
doFailover(svc1, svc2, false, false);
} catch (FailoverFailedException ffe) {
fail("Non-existant active prevented failover");
}
// Verify that the proxy created to try to make it go to standby
// gracefully used the right rpc timeout
Mockito.verify(svc1).getProxy(
Mockito.<Configuration>any(),
Mockito.eq(
CommonConfigurationKeys.HA_FC_GRACEFUL_FENCE_TIMEOUT_DEFAULT));
// Don't check svc1 because we can't reach it, but that's OK, it's been fenced.
assertEquals(HAServiceState.ACTIVE, svc2.state);
}
示例8: testExecuteOperationsSetsErrorOnInvalidRequestException
import org.mockito.internal.stubbing.answers.ThrowsException; //导入依赖的package包/类
public void testExecuteOperationsSetsErrorOnInvalidRequestException() throws Exception {
String operationId = "op1";
OperationRequest operation = new OperationRequest("wavelet.create", operationId);
OperationService service =
mock(OperationService.class, new ThrowsException(new InvalidRequestException("")));
when(operationRegistry.getServiceFor(any(OperationType.class))).thenReturn(service);
OperationUtil.executeOperation(operation, operationRegistry, context, ALEX);
assertTrue("Expected one response", context.getResponses().size() == 1);
assertTrue("Expected an error response", context.getResponse(operationId).isError());
}
示例9: testDeclaredExtensionsDontProduceWarning
import org.mockito.internal.stubbing.answers.ThrowsException; //导入依赖的package包/类
/**
* See #308
*/
@Test
public void testDeclaredExtensionsDontProduceWarning() {
ReportObservation obs = new ReportObservation();
obs.setReadOnly(true);
IParser p = ourCtx.newJsonParser();
p.setParserErrorHandler(mock(IParserErrorHandler.class, new ThrowsException(new IllegalStateException())));
String encoded = p.encodeResourceToString(obs);
ourLog.info(encoded);
obs = p.parseResource(ReportObservation.class, encoded);
assertEquals(true, obs.getReadOnly().getValue().booleanValue());
}
示例10: testParseBundleWithCustomObservationType
import org.mockito.internal.stubbing.answers.ThrowsException; //导入依赖的package包/类
@Test
public void testParseBundleWithCustomObservationType() {
ReportObservation obs = new ReportObservation();
obs.setReadOnly(true);
IParser p = ourCtx.newJsonParser();
// p.set
p.setParserErrorHandler(mock(IParserErrorHandler.class, new ThrowsException(new IllegalStateException())));
String encoded = p.encodeResourceToString(obs);
ourLog.info(encoded);
obs = p.parseResource(ReportObservation.class, encoded);
assertEquals(true, obs.getReadOnly().getValue().booleanValue());
}
示例11: shouldAllowThrowsExceptionToBeSerializable
import org.mockito.internal.stubbing.answers.ThrowsException; //导入依赖的package包/类
@Test
public void shouldAllowThrowsExceptionToBeSerializable() throws Exception {
// given
Bar mock = mock(Bar.class, new ThrowsException(new RuntimeException()));
// when-serialize then-deserialize
serializeAndBack(mock);
}
示例12: shouldAllowMethodDelegation
import org.mockito.internal.stubbing.answers.ThrowsException; //导入依赖的package包/类
@Test
public void shouldAllowMethodDelegation() throws Exception {
// given
Bar barMock = mock(Bar.class, withSettings().serializable());
Foo fooMock = mock(Foo.class);
when(barMock.doSomething()).thenAnswer(new ThrowsException(new RuntimeException()));
//when-serialize then-deserialize
serializeAndBack(barMock);
}
示例13: shouldFinishStubbingWhenWrongThrowableIsSet
import org.mockito.internal.stubbing.answers.ThrowsException; //导入依赖的package包/类
@Test
public void shouldFinishStubbingWhenWrongThrowableIsSet() throws Exception {
state.stubbingStarted();
try {
invocationContainerImpl.addAnswer(new ThrowsException(new Exception()));
fail();
} catch (MockitoException e) {
state.validateState();
}
}
示例14: shouldAddThrowableForVoidMethod
import org.mockito.internal.stubbing.answers.ThrowsException; //导入依赖的package包/类
@Test
public void shouldAddThrowableForVoidMethod() throws Throwable {
invocationContainerImpl.addAnswerForVoidMethod(new ThrowsException(new MyException()));
invocationContainerImpl.setMethodForStubbing(new InvocationMatcher(simpleMethod));
try {
invocationContainerImpl.answerTo(simpleMethod);
fail();
} catch (MyException e) {}
}
示例15: shouldValidateThrowableForVoidMethod
import org.mockito.internal.stubbing.answers.ThrowsException; //导入依赖的package包/类
@Test
public void shouldValidateThrowableForVoidMethod() throws Throwable {
invocationContainerImpl.addAnswerForVoidMethod(new ThrowsException(new Exception()));
try {
invocationContainerImpl.setMethodForStubbing(new InvocationMatcher(simpleMethod));
fail();
} catch (MockitoException e) {}
}