本文整理了Java中org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown()
方法的一些代码示例,展示了Assertions.failBecauseExceptionWasNotThrown()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Assertions.failBecauseExceptionWasNotThrown()
方法的具体详情如下:
包路径:org.assertj.core.api.Assertions
类名称:Assertions
方法名:failBecauseExceptionWasNotThrown
[英]Throws an AssertionError with a message explaining that a Throwable of given class was expected to be thrown but had not been.
Assertions#shouldHaveThrown(Class) can be used as a replacement.
[中]抛出一个AssertionError,其中包含一条消息,说明给定类的Throwable应该被抛出,但没有被抛出。
断言#shouldhavehown(类)可以用作替换。
代码示例来源:origin: org.assertj/assertj-core
/**
* Throws an {@link AssertionError} with a message explaining that a {@link Throwable} of given class was expected to be thrown
* but had not been.
* <p>
* {@link Assertions#shouldHaveThrown(Class)} can be used as a replacement.
* <p>
* @param <T> dummy return value type
* @param throwableClass the Throwable class that was expected to be thrown.
* @return nothing, it's just to be used in doSomething(optional.orElse(() -> failBecauseExceptionWasNotThrown(IOException.class)));.
* @throws AssertionError with a message explaining that a {@link Throwable} of given class was expected to be thrown but had
* not been.
*/
default <T> T failBecauseExceptionWasNotThrown(final Class<? extends Throwable> throwableClass) {
return Assertions.failBecauseExceptionWasNotThrown(throwableClass);
}
代码示例来源:origin: joel-costigliola/assertj-core
/**
* Throws an {@link AssertionError} with a message explaining that a {@link Throwable} of given class was expected to be thrown
* but had not been.
* <p>
* {@link Assertions#shouldHaveThrown(Class)} can be used as a replacement.
* <p>
* @param <T> dummy return value type
* @param throwableClass the Throwable class that was expected to be thrown.
* @return nothing, it's just to be used in doSomething(optional.orElse(() -> failBecauseExceptionWasNotThrown(IOException.class)));.
* @throws AssertionError with a message explaining that a {@link Throwable} of given class was expected to be thrown but had
* not been.
*/
default <T> T failBecauseExceptionWasNotThrown(final Class<? extends Throwable> throwableClass) {
return Assertions.failBecauseExceptionWasNotThrown(throwableClass);
}
代码示例来源:origin: cbeust/testng
@Test(description = "https://github.com/cbeust/testng/issues/876")
public void testExceptionWithNonStaticFactoryMethod() {
TestNG tng = create(GitHub876Sample.class);
try {
tng.run();
failBecauseExceptionWasNotThrown(TestNGException.class);
} catch (TestNGException e) {
assertThat(e)
.hasMessage(
"\nCan't invoke public java.lang.Object[] test.factory.GitHub876Sample.createInstances(): either make it static or add a no-args constructor to your class");
}
}
代码示例来源:origin: cbeust/testng
@Test
public void testExceptionWithBadFactoryMethodReturnType() {
TestNG tng = create(BadMethodReturnTypeFactory.class);
try {
tng.run();
failBecauseExceptionWasNotThrown(TestNGException.class);
} catch (TestNGException e) {
assertThat(e)
.hasMessage(
"\ntest.factory.BadMethodReturnTypeFactory.createInstances MUST return [ java.lang.Object[] or org.testng.IInstanceInfo[] ] but returns java.lang.Object");
}
}
代码示例来源:origin: openzipkin/brave
/**
* TODO: While it is an instrumentation bug to not close a scope, we should be tolerant. For
* example, considering weak references or similar.
*/
@SuppressWarnings("CheckReturnValue")
@Test public void notUnloadable_whenScopeLeaked() {
try {
assertRunIsUnloadableWithSupplier(LeakedScope.class, currentSupplier());
failBecauseExceptionWasNotThrown(AssertionError.class);
} catch (AssertionError e) {
// clear the leaked scope so other tests don't break
currentTraceContext.newScope(null);
}
}
代码示例来源:origin: springside/springside4
ReflectionUtil.invokeMethod(bean, "notExistMethod", new Object[] { "calvin" },
new Class[] { String.class });
failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
} catch (IllegalArgumentException e) {
ReflectionUtil.invokeMethod(bean, "privateMethod", new Object[] { "calvin" },
new Class[] { Integer.class });
failBecauseExceptionWasNotThrown(RuntimeException.class);
} catch (RuntimeException e) {
failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
} catch (IllegalArgumentException e) {
代码示例来源:origin: springside/springside4
failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
} catch (IllegalArgumentException e) { // NOSONAR
failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
} catch (IllegalArgumentException e) { // NOSONAR
代码示例来源:origin: json-path/JsonPath
@Test
public void issue_46() {
String json = "{\"a\": {}}";
Configuration configuration = Configuration.defaultConfiguration().setOptions(Option.SUPPRESS_EXCEPTIONS);
assertThat((String)JsonPath.using(configuration).parse(json).read("a.x")).isNull();
try {
read(json, "a.x");
failBecauseExceptionWasNotThrown(PathNotFoundException.class);
} catch (PathNotFoundException e) {
assertThat(e).hasMessage("No results for path: $['a']['x']");
}
}
代码示例来源:origin: Swagger2Markup/swagger2markup
@Test
public void testByTagsWithMissingTag() throws IOException, URISyntaxException {
//Given
Path file = Paths.get(AsciidocConverterTest.class.getResource("/json/swagger_missing_tag.json").toURI());
Path outputDirectory = Paths.get("build/test/asciidoc/generated");
FileUtils.deleteQuietly(outputDirectory.toFile());
//When
try {
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
.withPathsGroupedBy(GroupBy.TAGS)
.build();
Swagger2MarkupConverter.from(file)
.withConfig(config)
.build()
.toFolder(outputDirectory);
// If NullPointerException was not thrown, test would fail the specified message
failBecauseExceptionWasNotThrown(NullPointerException.class);
} catch (Exception e) {
assertThat(e).hasMessage("Can't GroupBy.TAGS. Operation 'updatePet' has no tags");
}
}
代码示例来源:origin: spring-projects/spring-session
@Test
public void enableRedisKeyspaceNotificationsInitializerAfterPropertiesSetWhenExceptionThenCloseConnection()
throws Exception {
ConfigureRedisAction action = mock(ConfigureRedisAction.class);
willThrow(new RuntimeException()).given(action).configure(this.connection);
EnableRedisKeyspaceNotificationsInitializer init = new EnableRedisKeyspaceNotificationsInitializer(
this.factory, action);
try {
init.afterPropertiesSet();
failBecauseExceptionWasNotThrown(Throwable.class);
}
catch (Throwable success) {
}
verify(this.connection).close();
}
代码示例来源:origin: json-path/JsonPath
@Test
public void issue_43() {
String json = "{\"test\":null}";
assertThat((String)read(json, "test")).isNull();
assertThat((String)JsonPath.using(Configuration.defaultConfiguration().setOptions(Option.SUPPRESS_EXCEPTIONS)).parse(json).read("nonExistingProperty")).isNull();
try {
read(json, "nonExistingProperty");
failBecauseExceptionWasNotThrown(PathNotFoundException.class);
} catch (PathNotFoundException e) {
}
try {
read(json, "nonExisting.property");
failBecauseExceptionWasNotThrown(PathNotFoundException.class);
} catch (PathNotFoundException e) {
}
}
代码示例来源:origin: grandcentrix/ThirtyInch
@Test
public void testGetViewOrThrow() {
mPresenter.create();
mPresenter.attachView(mView);
mPresenter.detachView();
try {
mPresenter.getViewOrThrow();
failBecauseExceptionWasNotThrown(IllegalStateException.class);
} catch (IllegalStateException e) {
assertThat(e).
hasMessage("The view is currently not attached. Use 'sendToView(ViewAction)' instead.");
}
}
代码示例来源:origin: org.uberfire/uberfire-nio2-jgit
@Test
public void testInvalidURIGetFileSystem() {
final URI newRepo = URI.create("git:///new-repo-name");
try {
provider.getFileSystem(newRepo);
failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
} catch (final IllegalArgumentException ex) {
assertThat(ex.getMessage()).isEqualTo("Parameter named 'uri' is invalid, missing host repository!");
}
}
代码示例来源:origin: org.uberfire/uberfire-nio2-jgit
@Test
public void testInvalidURINewFileSystem() {
final URI newRepo = URI.create("git:///repo-name");
try {
provider.newFileSystem(newRepo,
EMPTY_ENV);
failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
} catch (final IllegalArgumentException ex) {
assertThat(ex.getMessage()).isEqualTo("Parameter named 'uri' is invalid, missing host repository!");
}
}
代码示例来源:origin: org.uberfire/uberfire-nio2-jgit
@Test
public void testInvalidURIGetPath() {
final URI uri = URI.create("git:///master@new-get-repo-name/home");
try {
provider.getPath(uri);
failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
} catch (final IllegalArgumentException ex) {
assertThat(ex.getMessage()).isEqualTo("Parameter named 'uri' is invalid, missing host repository!");
}
}
代码示例来源:origin: kiegroup/appformer
@Test
public void testInvalidURINewFileSystem() {
final URI newRepo = URI.create("git:///repo-name");
try {
provider.newFileSystem(newRepo,
EMPTY_ENV);
failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
} catch (final IllegalArgumentException ex) {
assertThat(ex.getMessage()).isEqualTo("Parameter named 'uri' is invalid, missing host repository!");
}
}
代码示例来源:origin: mannodermaus/retrofit-logansquare
@Test
public void testDoesntSupportMapRequest() throws IOException, InterruptedException {
Map<String, de.mannodermaus.retrofit2.model.ForeignModel> requestBody = new HashMap<>();
requestBody.put("obj", new de.mannodermaus.retrofit2.model.ForeignModel());
try {
// Call the API and execute it
service.callMapRequestNotSupported(requestBody).execute();
Assertions.failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
} catch (IllegalArgumentException ignored) {
}
}
代码示例来源:origin: mannodermaus/retrofit-logansquare
@Test
public void testDoesntSupportMapResponse() throws IOException, InterruptedException {
BasicModel requestBody = new BasicModel();
try {
// Call the API and execute it
service.callMapResponseNotSupported(requestBody).execute();
Assertions.failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
} catch (IllegalArgumentException ignored) {
}
}
代码示例来源:origin: mannodermaus/retrofit-logansquare
@Test
public void testDoesntSupportObjectResponse() throws IOException, InterruptedException {
BasicModel requestBody = new BasicModel();
try {
// Call the API and execute it
service.callObjectResponseNotSupported(requestBody).execute();
Assertions.failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
} catch (IllegalArgumentException ignored) {
}
}
代码示例来源:origin: mannodermaus/retrofit-logansquare
@Test
public void testDoesntSupportListResponse() throws IOException, InterruptedException {
BasicModel requestBody = new BasicModel();
try {
// Call the API and execute it
service.callListResponseNotSupported(requestBody).execute();
Assertions.failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
} catch (IllegalArgumentException ignored) {
}
}
内容来源于网络,如有侵权,请联系作者删除!