@Test public void factoryThrowingShouldNotRunTests() { TestNG tng = create(FactoryFailureSample.class); Throwable actual = new Throwable(); try { tng.run(); } catch (Exception ex) { actual = ex; } assertThat(actual.getCause()).hasCauseInstanceOf(NullPointerException.class); }
@Test public void fromJsonWithWhiteSpaceStringThrowsIllegalArgumentException() { // given: white space string String whiteSpaceString = " "; // when: passed to fromJson Throwable thrown = catchThrowable(() -> fromJson(whiteSpaceString)); // then: throws IllegalArgumentException with cause of GfJsonException assertThat(thrown).isInstanceOf(IllegalArgumentException.class) .hasCauseInstanceOf(GfJsonException.class); assertThat(thrown.getCause()).isInstanceOf(GfJsonException.class).hasNoCause(); }
@Test public void fromJsonWithEmptyStringThrowsIllegalArgumentException() { // given: empty string String emptyString = ""; // when: passed to fromJson Throwable thrown = catchThrowable(() -> fromJson(emptyString)); // then: throws IllegalArgumentException with cause of GfJsonException assertThat(thrown).isInstanceOf(IllegalArgumentException.class) .hasCauseInstanceOf(GfJsonException.class); assertThat(thrown.getCause()).isInstanceOf(GfJsonException.class).hasNoCause(); }
@Test public void testFailedCompletedFuture() throws Exception { final ThriftCompletableFuture<String> future = failedCompletedFuture(new IllegalStateException()); assertThat(catchThrowable(future::get)).hasCauseInstanceOf(IllegalStateException.class); }
@Test public void setServerBindAddressToUnknownHostThrowsIllegalArgumentException() { assertThatThrownBy(() -> new Builder().setServerBindAddress("badHostName.example.com")) .isInstanceOf(IllegalArgumentException.class) .hasCauseInstanceOf(UnknownHostException.class); }
@Test public void setBindAddressToUnknownHostThrowsIllegalArgumentException() { assertThatThrownBy(() -> new Builder().setBindAddress("badhostname.badcompany.bad")) .isInstanceOf(IllegalArgumentException.class) .hasCauseInstanceOf(UnknownHostException.class); }
@Test public void decodeWhenInvalidUrl() { this.decoder = new NimbusReactiveJwtDecoder("https://s"); assertThatCode(() -> this.decoder.decode(this.messageReadToken).block()) .isInstanceOf(IllegalStateException.class) .hasCauseInstanceOf(UnknownHostException.class); }
@Test public void shouldErrorOutWhenCipherTextIsTamperedWith() { assertThatCode(() -> desEncrypter.decrypt("some bad junk")) .hasMessageContaining("Illegal base64 character 20") .hasCauseInstanceOf(IllegalArgumentException.class) .isInstanceOf(CryptoException.class); }
@Test public void testStatementException() { h.execute(CREATE); Throwable e = catchThrowable(h.createUpdate(INSERT_NULL)::execute); assertThat(e) .isInstanceOf(RuntimeException.class) .hasCauseInstanceOf(SQLException.class); assertThat(logger.getRawSql()).containsExactly(CREATE, CREATE, INSERT_NULL, INSERT_NULL); assertThat(logger.getTimings()).hasSize(2).allMatch(IS_POSITIVE); assertThat(logger.getExceptions()).containsExactly((SQLException) e.getCause()); }
@Test public void testFailedListenableFuture() throws Exception { assumeUnshadedGuava(); final ThriftListenableFuture<String> future = failedListenableFuture(new IllegalStateException()); assertThat(catchThrowable(future::get)).hasCauseInstanceOf(IllegalStateException.class); }
@Test public void sendWhenNoIdSpecifiedThenIntegratesWithClientInboundChannel() { this.spring.configLocations(xml("NoIdConfig")).autowire(); this.clientInboundChannel.send(message("/permitAll")); assertThatThrownBy(() -> this.clientInboundChannel.send(message("/denyAll"))) .hasCauseInstanceOf(AccessDeniedException.class); }
@Test public void configureWhenUsingIndenticallyPatternedHttpElementsThenThrowsWiringException() { assertThatCode(() -> this.spring.configLocations(this.xml("IdenticallyPatternedHttpElements")).autowire()) .isInstanceOf(BeanCreationException.class) .hasCauseInstanceOf(IllegalArgumentException.class); }
@Test public void configureWhenUsingDuplicateHttpElementsThenThrowsWiringException() { assertThatCode(() -> this.spring.configLocations(this.xml("IdenticalHttpElements")).autowire()) .isInstanceOf(BeanCreationException.class) .hasCauseInstanceOf(IllegalArgumentException.class); }
@Test public void sendWhenInterceptWiredForMessageTypeThenDeniesOnTypeMismatch() { this.spring.configLocations(xml("MessageInterceptTypeConfig")).autowire(); Message<?> message = message("/permitAll", SimpMessageType.MESSAGE); assertThatCode(send(message)).doesNotThrowAnyException(); message = message("/permitAll", SimpMessageType.UNSUBSCRIBE); assertThatThrownBy(send(message)).hasCauseInstanceOf(AccessDeniedException.class); message = message("/anyOther", SimpMessageType.MESSAGE); assertThatThrownBy(send(message)).hasCauseInstanceOf(AccessDeniedException.class); }
@Test public void sendWhenInterceptWiredForSubscribeTypeThenDeniesOnTypeMismatch() { this.spring.configLocations(xml("SubscribeInterceptTypeConfig")).autowire(); Message<?> message = message("/permitAll", SimpMessageType.SUBSCRIBE); assertThatCode(send(message)).doesNotThrowAnyException(); message = message("/permitAll", SimpMessageType.UNSUBSCRIBE); assertThatThrownBy(send(message)).hasCauseInstanceOf(AccessDeniedException.class); message = message("/anyOther", SimpMessageType.SUBSCRIBE); assertThatThrownBy(send(message)).hasCauseInstanceOf(AccessDeniedException.class); }
@Test public void sendWhenConnectWithoutCsrfTokenThenDenied() { this.spring.configLocations(xml("SyncConfig")).autowire(); Message<?> message = message("/message", SimpMessageType.CONNECT); assertThatThrownBy(send(message)).hasCauseInstanceOf(InvalidCsrfTokenException.class); }
@Test public void sendWhenNoIdSpecifiedThenSecurityDoesntOverrideCustomInterceptors() { this.spring.configLocations(xml("CustomInterceptorConfig")).autowire(); Message<?> message = message("/throwAll"); assertThatThrownBy(send(message)).hasCauseInstanceOf(UnsupportedOperationException.class); }
@Test @WithMockUser(username = "nile") public void sendWhenCustomExpressionHandlerThenAuthorizesAccordingly() { this.spring.configLocations(xml("CustomExpressionHandlerConfig")).autowire(); Message<?> message = message("/denyNile"); assertThatThrownBy(send(message)).hasCauseInstanceOf(AccessDeniedException.class); }
@Test @WithMockUser public void sendWhenIdSpecifiedAndExplicitlyIntegratedWhenBrokerUsesClientInboundChannel() { this.spring.configLocations(xml("IdIntegratedConfig")).autowire(); Message<?> message = message("/denyAll"); assertThatThrownBy(send(message)).hasCauseInstanceOf(AccessDeniedException.class); }
@Test public void sendWhenUsingCustomPathMatcherThenSecurityAppliesIt() { this.spring.configLocations(xml("CustomPathMatcherConfig")).autowire(); Message<?> message = message("/denyAll.a"); assertThatThrownBy(send(message)).hasCauseInstanceOf(AccessDeniedException.class); message = message("/denyAll.a.b"); assertThatCode(send(message)).doesNotThrowAnyException(); }