本文整理汇总了Java中org.mockito.internal.stubbing.answers.ThrowsException类的典型用法代码示例。如果您正苦于以下问题:Java ThrowsException类的具体用法?Java ThrowsException怎么用?Java ThrowsException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ThrowsException类属于org.mockito.internal.stubbing.answers包,在下文中一共展示了ThrowsException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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));
}
开发者ID:WileyLabs,项目名称:teasy,代码行数:27,代码来源:FramesTransparentWebDriverTest.java
示例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();
}
开发者ID:intelie,项目名称:disq,代码行数:19,代码来源:LenientTest.java
示例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) {}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:17,代码来源:MockitoStubberTest.java
示例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) {}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:17,代码来源:InvocationContainerImplStubbingTest.java
示例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) {}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:17,代码来源:InvocationContainerImplStubbingTest.java
示例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));
}
开发者ID:WileyLabs,项目名称:teasy,代码行数:8,代码来源:FramesTransparentWebDriverTest.java
示例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);
}
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:34,代码来源:TestFailoverController.java
示例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());
}
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:14,代码来源:OperationUtilTest.java
示例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());
}
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:18,代码来源:XmlParserDstu2Test.java
示例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());
}
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:16,代码来源:JsonParserDstu2Test.java
示例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);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:8,代码来源:MocksSerializationTest.java
示例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);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:11,代码来源:MocksSerializationTest.java
示例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();
}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:11,代码来源:MockitoStubberTest.java
示例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) {}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:11,代码来源:MockitoStubberTest.java
示例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) {}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:10,代码来源:MockitoStubberTest.java
示例16: shouldValidateThrowable
import org.mockito.internal.stubbing.answers.ThrowsException; //导入依赖的package包/类
@Test
public void shouldValidateThrowable() throws Throwable {
try {
invocationContainerImpl.addAnswer(new ThrowsException(null));
fail();
} catch (MockitoException e) {}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:8,代码来源:MockitoStubberTest.java
示例17: should_allow_throws_exception_to_be_serializable
import org.mockito.internal.stubbing.answers.ThrowsException; //导入依赖的package包/类
@Test
public void should_allow_throws_exception_to_be_serializable() throws Exception {
// given
when(barMock.doSomething()).thenAnswer(new ThrowsException(new RuntimeException()));
//when-serialize then-deserialize
serializeAndBack(barMock);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:9,代码来源:MocksSerializationForAnnotationTest.java
示例18: should_allow_throws_exception_to_be_serializable
import org.mockito.internal.stubbing.answers.ThrowsException; //导入依赖的package包/类
@Test
public void should_allow_throws_exception_to_be_serializable() throws Exception {
// given
Bar mock = mock(Bar.class, new ThrowsException(new RuntimeException()));
// when-serialize then-deserialize
serializeAndBack(mock);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:8,代码来源:MocksSerializationTest.java
示例19: should_allow_method_delegation
import org.mockito.internal.stubbing.answers.ThrowsException; //导入依赖的package包/类
@Test
public void should_allow_method_delegation() 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);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:11,代码来源:MocksSerializationTest.java
示例20: should_finish_stubbing_when_wrong_throwable_is_set
import org.mockito.internal.stubbing.answers.ThrowsException; //导入依赖的package包/类
@Test
public void should_finish_stubbing_when_wrong_throwable_is_set() throws Exception {
state.stubbingStarted();
try {
invocationContainerImpl.addAnswer(new ThrowsException(new Exception()));
fail();
} catch (MockitoException e) {
state.validateState();
}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:11,代码来源:InvocationContainerImplStubbingTest.java
注:本文中的org.mockito.internal.stubbing.answers.ThrowsException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论