本文整理汇总了Java中org.assertj.core.api.ThrowableAssert.ThrowingCallable类的典型用法代码示例。如果您正苦于以下问题:Java ThrowingCallable类的具体用法?Java ThrowingCallable怎么用?Java ThrowingCallable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ThrowingCallable类属于org.assertj.core.api.ThrowableAssert包,在下文中一共展示了ThrowingCallable类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: should_mock_final_method
import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@Test
public void should_mock_final_method() {
final FinalClass finalClass = Mockito.mock(FinalClass.class);
doNothing().when(finalClass).say(anyString());
Throwable throwable = catchThrowable(new ThrowingCallable() {
@Override
public void call() throws Throwable {
finalClass.say(RandomStringUtils.random(10));
}
});
assertThat(throwable)
.as("Final method is mocked and exception is not thrown")
.isNull();
}
开发者ID:powermock,项目名称:powermock-examples-maven,代码行数:19,代码来源:OnlyMockitoTest.java
示例2: validation_should_work_everytime_when_no_exception_is_thrown
import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@Test
public void validation_should_work_everytime_when_no_exception_is_thrown() {
InterfaceAvecDesMethodes mock = mock(InterfaceAvecDesMethodes.class);
when(mock.recuperationDesDonnees(anyString())).thenReturn(resultListMock());
final ServiceInterface service = getInterface(mock);
Throwable thrownByMethod = catchThrowable(new ThrowingCallable() {
@Override
public void call() throws Throwable {
service.validationDonneesForId("0");
}
});
assertThat(thrownByMethod).isNull();
}
开发者ID:Eulbobo,项目名称:java-samples,代码行数:17,代码来源:AbstractServiceInterfaceTest.java
示例3: validation_should_work_everytime_when_sqlexception_is_thrown
import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@Test
public void validation_should_work_everytime_when_sqlexception_is_thrown() throws SQLException {
InterfaceAvecDesMethodes mock = mock(InterfaceAvecDesMethodes.class);
when(mock.recuperationDesDonnees(anyString())).thenReturn(resultListMock());
doThrow(SQLException.class)
.when(mock)
.verificationDesDonnees(anyList());
final ServiceInterface service = getInterface(mock);
Throwable thrownByMethod = catchThrowable(new ThrowingCallable() {
@Override
public void call() throws Throwable {
service.validationDonneesForId("0");
}
});
assertThat(thrownByMethod).isNull();
}
开发者ID:Eulbobo,项目名称:java-samples,代码行数:21,代码来源:AbstractServiceInterfaceTest.java
示例4: should_raise_and_exception_when_querying_for_unknow_object
import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@Test
public void should_raise_and_exception_when_querying_for_unknow_object() {
Throwable thrown = Assertions.catchThrowable(new ThrowingCallable() {
@Override
public void call() throws Throwable {
queryForObject.getIdForUser(4);
failBecauseExceptionWasNotThrown(EmptyResultDataAccessException.class);
}
});
Assertions.assertThat(thrown)
.isNotNull()
.isInstanceOf(EmptyResultDataAccessException.class);
}
开发者ID:Eulbobo,项目名称:java-samples,代码行数:17,代码来源:QueryForObjectTest.java
示例5: saveOrUpdate_should_raise_and_SQLException
import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@Test
public void saveOrUpdate_should_raise_and_SQLException() {
final UserService service = new UserServiceImpl(mock(UserDao.class));
Throwable throwable = Assertions.catchThrowable(new ThrowingCallable() {
@Override
public void call() throws Throwable {
service.saveOrUpdate(user(1l, "one"));
}
});
Assertions.assertThat(throwable)
.isNotNull()
.isInstanceOf(SQLException.class);
}
开发者ID:Eulbobo,项目名称:java-samples,代码行数:17,代码来源:UserServiceImplTest.java
示例6: delete_should_raise_and_UnsupportedOperationException
import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@Test
public void delete_should_raise_and_UnsupportedOperationException() {
final UserService service = new UserServiceImpl(mock(UserDao.class));
Throwable throwable = Assertions.catchThrowable(new ThrowingCallable() {
@Override
public void call() throws Throwable {
service.delete(user(1l, "one"));
}
});
Assertions.assertThat(throwable)
.isNotNull()
.isInstanceOf(UnsupportedOperationException.class);
}
开发者ID:Eulbobo,项目名称:java-samples,代码行数:17,代码来源:UserServiceImplTest.java
示例7: thisWillFailMiserabily_should_raise_and_UnsupportedOperationException
import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@Test
public void thisWillFailMiserabily_should_raise_and_UnsupportedOperationException() {
final UserService service = new UserServiceImpl(mock(UserDao.class));
Throwable throwable = Assertions.catchThrowable(new ThrowingCallable() {
@Override
public void call() throws Throwable {
service.thisWillFailMiserabily();
}
});
Assertions.assertThat(throwable)
.isNotNull()
.isInstanceOf(UnsupportedOperationException.class);
}
开发者ID:Eulbobo,项目名称:java-samples,代码行数:17,代码来源:UserServiceImplTest.java
示例8: should_catch_any_exception_but_DomainException_and_wrap_it_into_DomainException
import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@Test
public void should_catch_any_exception_but_DomainException_and_wrap_it_into_DomainException() {
final Exception thrown = new Exception();
assertThatThrownBy(new ThrowingCallable() {
@Override
public void call() throws Throwable {
final ExceptionAutoWrap aspect = new ExceptionAutoWrap();
aspect.catchLogAndRethrow(thrown);
failBecauseExceptionWasNotThrown(Exception.class);
}
})
.isNotNull()
.isInstanceOf(DomainException.class)
.hasCause(thrown);
}
开发者ID:Eulbobo,项目名称:java-samples,代码行数:17,代码来源:ExceptionAutoWrapTest.java
示例9: should_catch_any_RuntimeException_and_wrap_it_into_DomainException
import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@Test
public void should_catch_any_RuntimeException_and_wrap_it_into_DomainException() {
final Exception thrown = new RuntimeException();
assertThatThrownBy(new ThrowingCallable() {
@Override
public void call() throws Throwable {
final ExceptionAutoWrap aspect = new ExceptionAutoWrap();
aspect.catchLogAndRethrow(thrown);
failBecauseExceptionWasNotThrown(Exception.class);
}
})
.isNotNull()
.isInstanceOf(DomainException.class)
.hasCause(thrown);
}
开发者ID:Eulbobo,项目名称:java-samples,代码行数:17,代码来源:ExceptionAutoWrapTest.java
示例10: should_not_wrap_DomainException
import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@Test
public void should_not_wrap_DomainException() {
final Exception thrown = new DomainException("Test message");
assertThatThrownBy(new ThrowingCallable() {
@Override
public void call() throws Throwable {
final ExceptionAutoWrap aspect = new ExceptionAutoWrap();
aspect.catchLogAndRethrow(thrown);
failBecauseExceptionWasNotThrown(DomainException.class);
}
})
.isNotNull()
.isInstanceOf(DomainException.class)
.hasNoCause()
.isEqualTo(thrown);
}
开发者ID:Eulbobo,项目名称:java-samples,代码行数:18,代码来源:ExceptionAutoWrapTest.java
示例11: should_wrap_any_RuntimeException_into_Checked_Exception
import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@Test
public void should_wrap_any_RuntimeException_into_Checked_Exception() {
final RuntimeException thrown = new DomainException("Test message");
assertThatThrownBy(new ThrowingCallable() {
@Override
public void call() throws Throwable {
final ExceptionAutoWrap aspect = new ExceptionAutoWrap();
aspect.wrapIntoNotRuntimeException(thrown);
failBecauseExceptionWasNotThrown(Exception.class);
}
})
.isNotNull()
.isInstanceOf(Exception.class)
.hasCause(thrown);
}
开发者ID:Eulbobo,项目名称:java-samples,代码行数:17,代码来源:ExceptionAutoWrapTest.java
示例12: should_raise_DiceException_when_rolling_dice_with_a_beautiful_test
import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@Test
public void should_raise_DiceException_when_rolling_dice_with_a_beautiful_test() {
final MethodsThrowingExceptions method = new MethodsThrowingExceptions(21);
// la meilleure façon de tester si on est en Java7 avec assertJ 2.X
Throwable thrownByMethod = Assertions.catchThrowable(new ThrowingCallable() {
@Override
public void call() throws Throwable {
method.rollDice();
failBecauseExceptionWasNotThrown(DiceException.class);
}
});
assertThat(thrownByMethod)
.isInstanceOf(RandomException.class)
.isExactlyInstanceOf(DiceException.class)
.hasMessageContaining("21 failures yet");
}
开发者ID:Eulbobo,项目名称:java-samples,代码行数:19,代码来源:MethodsThrowingExceptionsTest.java
示例13: assertThatThrownByWithExpectedException
import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
/**
* Adds {@code "(expected exception)"} to the log message and lower its logging level to
* {@link Level#DEBUG} if the exception occurred from the {@code shouldRaiseThrowable} matches
* {@code throwable} and contains {@code message}.
*/
public static AbstractThrowableAssert<?, ? extends Throwable> assertThatThrownByWithExpectedException(
Class<?> throwable, String message, ThrowingCallable shouldRaiseThrowable) throws Exception {
requireNonNull(throwable, "throwable");
requireNonNull(message, "message");
requireNonNull(shouldRaiseThrowable, "shouldRaiseThrowable");
exceptionAndMessage.put(throwable.getName(), message);
try {
return assertThatThrownBy(shouldRaiseThrowable);
} finally {
exceptionAndMessage.remove(throwable.getName());
}
}
开发者ID:line,项目名称:centraldogma,代码行数:18,代码来源:ExpectedExceptionAppender.java
示例14: shouldThrowForNonDataenumClassName
import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@Test
public void shouldThrowForNonDataenumClassName() throws Exception {
assertThatThrownBy(
new ThrowingCallable() {
@Override
public void call() throws Throwable {
OutputSpecFactory.toOutputClass(ClassName.get("com.spotify", "My"));
}
})
.isInstanceOf(ParserException.class)
.hasMessageContaining("Bad name");
}
开发者ID:spotify,项目名称:dataenum,代码行数:13,代码来源:OutputSpecFactoryTest.java
示例15: shouldThrowForNonClassName
import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@Test
public void shouldThrowForNonClassName() throws Exception {
assertThatThrownBy(
new ThrowingCallable() {
@Override
public void call() throws Throwable {
OutputSpecFactory.toOutputClass(TypeName.BOOLEAN);
}
})
.isInstanceOf(ClassCastException.class);
}
开发者ID:spotify,项目名称:dataenum,代码行数:12,代码来源:OutputSpecFactoryTest.java
示例16: shouldCrash_WhenDataAvailable_ForViewTypes
import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@Test public void shouldCrash_WhenDataAvailable_ForViewTypes() {
Activity host = buildActivity(FactsAboutNumbersActivity.class).create().get();
adapter = new FactsAdapter(LayoutInflater.from(host));
assertThat(adapter.getItemCount()).isEqualTo(0);
ThrowingCallable call = () -> adapter.getItemViewType(0);
assertThatThrownBy(call).isInstanceOf(IllegalStateException.class);
}
开发者ID:ubiratansoares,项目名称:reactive-architectures-playground,代码行数:10,代码来源:FactsAdapterTests.java
示例17: verifyUnsupportedOperation
import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
private void verifyUnsupportedOperation(ThrowingCallable operation) {
// when
Throwable ex = catchThrowable(operation);
// then
assertThat(ex).isInstanceOf(UnsupportedOperationException.class);
}
开发者ID:Nike-Inc,项目名称:riposte,代码行数:8,代码来源:HttpServletRequestWrapperForRequestInfoTest.java
示例18: test_media_range_constructor_throws_exception_with_null_values
import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
/**
* MediaRange constructor should throw an IllegalArgumentException when the type, subtype, or qualityFactor properties are null.
* Additionally, the constructor should throw an IllegalArgumentException when the quality factor value is less than 0 or greater than 1.
*/
@Test
@UseDataProvider("nullMediaRangeConstructorTestSet")
public void test_media_range_constructor_throws_exception_with_null_values (final String expectedErrorMessage, final ThrowingCallable callable) {
// when
Throwable ex = catchThrowable(callable);
// then
assertThat(ex)
.isInstanceOf(IllegalArgumentException.class)
.hasMessageStartingWith(expectedErrorMessage);
}
开发者ID:Nike-Inc,项目名称:riposte,代码行数:16,代码来源:MediaRangeTest.java
示例19: call_handles_tracing_and_mdc_info_as_expected
import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@DataProvider(value = {
"true",
"false"
})
@Test
public void call_handles_tracing_and_mdc_info_as_expected(boolean throwException) throws Exception {
// given
throwExceptionDuringCall = throwException;
Tracer.getInstance().startRequestWithRootSpan("foo");
Deque<Span> spanStack = Tracer.getInstance().getCurrentSpanStackCopy();
Map<String, String> mdcInfo = MDC.getCopyOfContextMap();
final CallableWithTracing instance = new CallableWithTracing(
callableMock, spanStack, mdcInfo
);
resetTracing();
assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull();
assertThat(MDC.getCopyOfContextMap()).isNullOrEmpty();
// when
Throwable ex = catchThrowable(new ThrowingCallable() {
@Override
public void call() throws Throwable {
instance.call();
}
});
// then
verify(callableMock).call();
if (throwException)
assertThat(ex).isNotNull();
else
assertThat(ex).isNull();
assertThat(currentSpanStackWhenCallableWasCalled.get(0)).isEqualTo(spanStack);
assertThat(currentMdcInfoWhenCallableWasCalled.get(0)).isEqualTo(mdcInfo);
assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull();
assertThat(MDC.getCopyOfContextMap()).isNullOrEmpty();
}
开发者ID:Nike-Inc,项目名称:wingtips,代码行数:40,代码来源:CallableWithTracingTest.java
示例20: run_handles_tracing_and_mdc_info_as_expected
import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@DataProvider(value = {
"true",
"false"
})
@Test
public void run_handles_tracing_and_mdc_info_as_expected(boolean throwException) {
// given
throwExceptionDuringCall = throwException;
Tracer.getInstance().startRequestWithRootSpan("foo");
Deque<Span> spanStack = Tracer.getInstance().getCurrentSpanStackCopy();
Map<String, String> mdcInfo = MDC.getCopyOfContextMap();
final RunnableWithTracing instance = new RunnableWithTracing(
runnableMock, spanStack, mdcInfo
);
resetTracing();
assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull();
assertThat(MDC.getCopyOfContextMap()).isNullOrEmpty();
// when
Throwable ex = catchThrowable(new ThrowingCallable() {
@Override
public void call() throws Throwable {
instance.run();
}
});
// then
verify(runnableMock).run();
if (throwException)
assertThat(ex).isNotNull();
else
assertThat(ex).isNull();
assertThat(currentSpanStackWhenRunnableWasCalled.get(0)).isEqualTo(spanStack);
assertThat(currentMdcInfoWhenRunnableWasCalled.get(0)).isEqualTo(mdcInfo);
assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull();
assertThat(MDC.getCopyOfContextMap()).isNullOrEmpty();
}
开发者ID:Nike-Inc,项目名称:wingtips,代码行数:40,代码来源:RunnableWithTracingTest.java
注:本文中的org.assertj.core.api.ThrowableAssert.ThrowingCallable类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论