Java Examples for org.assertj.core.api.Assertions.assertThatExceptionOfType
The following java examples will help you to understand the usage of org.assertj.core.api.Assertions.assertThatExceptionOfType. These source code samples are taken from different open source projects.
Example 1
| Project: jdbi-master File: TestJdbiFactoryBean.java View source code |
@Test
public void testFailsViaException() throws Exception {
assertThatExceptionOfType(ForceRollback.class).isThrownBy(() -> {
service.inPropagationRequired( jdbi -> {
Handle h = JdbiUtil.getHandle(jdbi);
final int count = h.execute("insert into something (id, name) values (7, 'ignored')");
if (count == 1) {
throw new ForceRollback();
} else {
throw new RuntimeException("!ZABAK");
}
});
});
try (final Handle h = Jdbi.open(ds)) {
int count = h.createQuery("select count(*) from something").mapTo(int.class).findOnly();
assertThat(count).isEqualTo(0);
}
}Example 2
| Project: assertj-core-master File: Assertions_assertThatExceptionOfType_Test.java View source code |
@Parameters
public static Iterable<? extends Object> data() {
return Arrays.asList(new Object[] { s(() -> assertThatExceptionOfType(UnsupportedOperationException.class)), UnsupportedOperationException.class, s(() -> new UnsupportedOperationException()) }, new Object[] { s(() -> assertThatNullPointerException()), NullPointerException.class, s(() -> new NullPointerException("value")) }, new Object[] { s(() -> assertThatIllegalArgumentException()), IllegalArgumentException.class, s(() -> new IllegalArgumentException("arg")) }, new Object[] { s(() -> assertThatIllegalStateException()), IllegalStateException.class, s(() -> new IllegalStateException("state")) }, new Object[] { s(() -> assertThatIOException()), IOException.class, s(() -> new IOException("io")) });
}Example 3
| Project: web-framework-master File: DbLocksCommandTest.java View source code |
@Test
public void testFailsWhenNoListOrRelease() throws Exception {
final Liquibase liquibase = Mockito.mock(Liquibase.class);
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> locksCommand.run(new Namespace(ImmutableMap.of("list", false, "release", false)), liquibase)).withMessage("Must specify either --list or --force-release");
}Example 4
| Project: reactor-core-master File: FluxSpecTests.java View source code |
@Test
public void fluxCanFilterTerminalStates() {
// "A deferred Flux can filter terminal states"
// given: "a composable with an initial value"
Flux<String> stream = Flux.just("test");
// when:"the complete signal is observed and flux is retrieved"
Mono<Void> tap = stream.then();
// then: "it is available"
assertThat(tap.block()).isNull();
// when: "the error signal is observed and flux is retrieved"
stream = Flux.error(new Exception());
final Mono<Void> errorTap = stream.then();
// then: "it is available"
assertThatExceptionOfType(Exception.class).isThrownBy(errorTap::block);
}Example 5
| Project: seed-master File: JndiIT.java View source code |
@Test
public void jndi_context_is_immutable() throws Exception {
Context context = injector.getInstance(Holder.class).ctx1;
assertThatExceptionOfType(NamingException.class).isThrownBy(() -> context.bind(new DummyName(), new Object()));
assertThatExceptionOfType(NamingException.class).isThrownBy(() -> context.bind("", new Object()));
assertThatExceptionOfType(NamingException.class).isThrownBy(() -> context.rebind(new DummyName(), new Object()));
assertThatExceptionOfType(NamingException.class).isThrownBy(() -> context.rebind("", new Object()));
assertThatExceptionOfType(NamingException.class).isThrownBy(() -> context.unbind(new DummyName()));
assertThatExceptionOfType(NamingException.class).isThrownBy(() -> context.unbind(""));
assertThatExceptionOfType(NamingException.class).isThrownBy(() -> context.rename(new DummyName(), new DummyName()));
assertThatExceptionOfType(NamingException.class).isThrownBy(() -> context.rename("", ""));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> context.list(new DummyName()));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> context.list(""));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> context.listBindings(new DummyName()));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> context.listBindings(""));
assertThatExceptionOfType(NamingException.class).isThrownBy(() -> context.destroySubcontext(new DummyName()));
assertThatExceptionOfType(NamingException.class).isThrownBy(() -> context.destroySubcontext(""));
assertThatExceptionOfType(NamingException.class).isThrownBy(() -> context.createSubcontext(new DummyName()));
assertThatExceptionOfType(NamingException.class).isThrownBy(() -> context.createSubcontext(""));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> context.lookupLink(new DummyName()));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> context.lookupLink(""));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> context.getNameParser(new DummyName()));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> context.getNameParser(""));
// Cannot test composeName methods (implemented in InitialContext)
assertThatExceptionOfType(NamingException.class).isThrownBy(() -> context.addToEnvironment("", new Object()));
assertThatExceptionOfType(NamingException.class).isThrownBy(() -> context.removeFromEnvironment(""));
assertThatExceptionOfType(NamingException.class).isThrownBy(() -> context.removeFromEnvironment(""));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(context::getNameInNamespace);
}Example 6
| Project: dropwizard-master File: DbLocksCommandTest.java View source code |
@Test
public void testFailsWhenNoListOrRelease() throws Exception {
final Liquibase liquibase = Mockito.mock(Liquibase.class);
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> locksCommand.run(new Namespace(ImmutableMap.of("list", false, "release", false)), liquibase)).withMessage("Must specify either --list or --force-release");
}Example 7
| Project: spring-data-commons-master File: ClassGeneratingPropertyAccessorFactoryTests.java View source code |
// DATACMNS-809
@Test
public void getPropertyShouldFailOnUnhandledProperty() {
//
assertThat(getProperty(new Dummy(), "dummy")).hasValueSatisfying(//
property -> assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> getPersistentPropertyAccessor(bean).getProperty(property)));
}