private void verifyFailedLogin() { ArgumentCaptor<JaasAuthenticationFailedEvent> event = ArgumentCaptor.forClass(JaasAuthenticationFailedEvent.class); verify(publisher).publishEvent(event.capture()); assertThat(event.getValue()).isInstanceOf(JaasAuthenticationFailedEvent.class); assertThat(event.getValue().getException()).isNotNull(); verifyNoMoreInteractions(publisher); } }
@Test public void returnsExceptionWithCauseForNonSqlExceptionWithMessage() { Exception e = JdbcConnectorException.createException("message", new IllegalStateException()); assertThat(e.getMessage()).isEqualTo("message"); assertThat(e.getCause()).isNotNull().isInstanceOf(IllegalStateException.class); }
@Test public void returnsExceptionWithCauseForNonSqlException() { Exception e = JdbcConnectorException.createException(new IllegalStateException()); assertThat(e.getCause()).isNotNull().isInstanceOf(IllegalStateException.class); }
@Test public void returnsExceptionWithCauseForNonSqlExceptionAndNonSqlNestedCause() { IllegalStateException cause = new IllegalStateException(new IllegalStateException()); Exception e = JdbcConnectorException.createException(cause); assertThat(e.getCause()).isNotNull().isSameAs(cause); }
@Test public void deserializeBadCredentialsExceptionMixinTest() throws IOException { BadCredentialsException exception = mapper.readValue(EXCEPTION_JSON, BadCredentialsException.class); assertThat(exception).isNotNull(); assertThat(exception.getCause()).isNull(); assertThat(exception.getMessage()).isEqualTo("message"); assertThat(exception.getLocalizedMessage()).isEqualTo("message"); } }
@Test public void createAlertListenerMessage_requiresInternalDistributedMember() { member = mock(DistributedMember.class); Throwable thrown = catchThrowable( () -> alertListenerMessageFactory.createAlertListenerMessage(member, AlertLevel.WARNING, new Date(), "connectionName", "threadName", "formattedMessage", null)); assertThat(thrown).isNotNull().isInstanceOf(IllegalArgumentException.class); } }
private static void assertResponseTimeoutExceptionOrDeadlineExceeded(@Nullable Throwable cause) { assertThat(cause).isNotNull(); // Both exceptions can be raised when a timeout occurs due to timing issues, // and the first triggered one wins. if (cause instanceof ResponseTimeoutException) { return; } if (cause instanceof StatusException) { assertThat(((StatusException) cause).getStatus().getCode()).isEqualTo(Code.DEADLINE_EXCEEDED); return; } fail("cause must be a ResponseTimeoutException or a StatusException: ", cause); }
@Test public void testNotSql() { String query = "herp derp"; assertThatThrownBy(() -> h.execute(query)).isNotNull(); assertThat(logger.getRawSql()).isEmpty(); assertThat(logger.getTimings()).isEmpty(); assertThat(logger.getExceptions()).isEmpty(); }
@Test public void testBadPassword() { try { jaasProvider.authenticate(new UsernamePasswordAuthenticationToken("user", "asdf")); fail("LoginException should have been thrown for the bad password"); } catch (AuthenticationException e) { } assertThat(eventCheck.failedEvent).as("Failure event not fired").isNotNull(); assertThat(eventCheck.failedEvent.getException()).withFailMessage("Failure event exception was null").isNotNull(); assertThat(eventCheck.successEvent).as("Success event was fired").isNull(); }
@Test public void testBadUser() { try { jaasProvider.authenticate(new UsernamePasswordAuthenticationToken("asdf", "password")); fail("LoginException should have been thrown for the bad user"); } catch (AuthenticationException e) { } assertThat(eventCheck.failedEvent).as("Failure event not fired").isNotNull(); assertThat(eventCheck.failedEvent.getException()).withFailMessage("Failure event exception was null").isNotNull(); assertThat(eventCheck.successEvent).as("Success event was fired").isNull(); }
private void assertPreConditions() { Throwable thrown = catchThrowable(() -> SerializationUtils.clone(nonSerializableNamingException)); assertThat(thrown).isNotNull(); assertThat(thrown.getCause()) .isInstanceOf(NotSerializableException.class); thrown = catchThrowable(() -> SerializationUtils.clone(serializableNamingException)); assertThat(thrown).isNull(); assertThat(nonSerializableResolvedObj).isNotInstanceOf(Serializable.class); thrown = catchThrowable(() -> SerializationUtils.clone(serializableResolvedObj)); assertThat(thrown).isNull(); }
private static void checkRequestLogStatus(RequestLogStatusChecker checker) throws Exception { final RequestLog log = requestLogQueue.take(); assertThat(log.availabilities()).contains(RequestLogAvailability.COMPLETE); final RpcRequest rpcReq = (RpcRequest) log.requestContent(); final RpcResponse rpcRes = (RpcResponse) log.responseContent(); assertThat(rpcReq).isNull(); assertThat((Object) rpcRes).isNotNull(); assertThat(rpcRes.cause()).isNotNull(); checker.check(((StatusException) rpcRes.cause()).getStatus()); }
private void assertPreconditions() { Throwable thrown = catchThrowable(() -> SerializationUtils.clone(nonSerializableNamingException)); assertThat(thrown).isNotNull(); assertThat(thrown.getCause()).isInstanceOf(NotSerializableException.class); thrown = catchThrowable(() -> SerializationUtils.clone(serializableNamingException)); assertThat(thrown).isNull(); assertThat(nonSerializableResolvedObj).isNotInstanceOf(Serializable.class); thrown = catchThrowable(() -> SerializationUtils.clone(serializableResolvedObj)); assertThat(thrown).isNull(); assertThat(nonSerializablePrincipal).isNotInstanceOf(Serializable.class); thrown = catchThrowable(() -> SerializationUtils.clone(serializablePrincipal)); assertThat(thrown).isNull(); }
@Test public void verifyErrorAssertionTriggersVerificationFailBadSignal() { assertThatExceptionOfType(AssertionError.class) .isThrownBy(() -> StepVerifier.create(Flux.empty()) .verifyErrorSatisfies(e -> assertThat(e).isNotNull())) .withMessage("expectation \"verifyErrorSatisfies\" failed (expected: onError(); actual: onComplete())"); }
@Test public void testOnCreateLayoutErrorWithoutBoundaryWhenEnabled() { ComponentsConfiguration.enableOnErrorHandling = true; final ComponentContext c = mComponentsRule.getContext(); final TestCrasherOnCreateLayout.Builder builder = TestCrasherOnCreateLayout.create(c); RuntimeException exception = null; try { ComponentTestHelper.mountComponent(builder); } catch (RuntimeException e) { exception = e; } assertThat(exception).isNotNull().hasStackTraceContaining("onCreateLayout crash"); }
@Test public void testOnCreateLayoutWithSizeSpecErrorWithoutBoundaryWhenEnabled() { ComponentsConfiguration.enableOnErrorHandling = true; final ComponentContext c = mComponentsRule.getContext(); final TestCrasherOnCreateLayoutWithSizeSpec.Builder builder = TestCrasherOnCreateLayoutWithSizeSpec.create(c); RuntimeException exception = null; try { ComponentTestHelper.mountComponent(builder); } catch (RuntimeException e) { exception = e; } assertThat(exception).isNotNull().hasStackTraceContaining("onCreateLayoutWithSizeSpec crash"); }
@Test public void testOnMountErrorWithoutBoundaryWhenEnabled() throws Exception { ComponentsConfiguration.enableOnErrorHandling = true; final ComponentContext c = mComponentsRule.getContext(); final TestCrasherOnMount.Builder builder = TestCrasherOnMount.create(c); RuntimeException exception = null; try { ComponentTestHelper.mountComponent(builder); } catch (RuntimeException e) { exception = e; } assertThat(exception).isNotNull().hasMessageContaining("onMount crash"); } }
@Test public void testOnCreateLayoutErrorBoundaryWhenDisabled() { ComponentsConfiguration.enableOnErrorHandling = false; final ComponentContext c = mComponentsRule.getContext(); final TestErrorBoundary.Builder builder = TestErrorBoundary.create(c).child(TestCrasherOnCreateLayout.create(c).build()); RuntimeException exception = null; try { ComponentTestHelper.mountComponent(builder); } catch (RuntimeException e) { exception = e; } assertThat(exception).isNotNull().hasStackTraceContaining("onCreateLayout crash"); }
@Test public void testOnMountErrorBoundaryWhenDisabled() throws Exception { ComponentsConfiguration.enableOnErrorHandling = false; final ComponentContext c = mComponentsRule.getContext(); final TestErrorBoundary.Builder builder = TestErrorBoundary.create(c).child(TestCrasherOnMount.create(c).build()); RuntimeException exception = null; try { ComponentTestHelper.mountComponent(builder); } catch (RuntimeException e) { exception = e; } assertThat(exception).isNotNull().hasMessageContaining("onMount crash"); }
@Test public void testOnCreateLayoutWithSizeSpecErrorBoundaryWhenDisabled() { ComponentsConfiguration.enableOnErrorHandling = false; final ComponentContext c = mComponentsRule.getContext(); final TestErrorBoundary.Builder builder = TestErrorBoundary.create(c).child(TestCrasherOnCreateLayoutWithSizeSpec.create(c).build()); RuntimeException exception = null; try { ComponentTestHelper.mountComponent(builder); } catch (RuntimeException e) { exception = e; } assertThat(exception).isNotNull().hasStackTraceContaining("onCreateLayoutWithSizeSpec crash"); }