@Test public void shouldReturnNormallyIfExceptionIsThrownOnErrorDuringSwitching() { Signal<? extends Long>[] first = new Signal[1]; NullPointerException npe = new NullPointerException(); RuntimeException error = new RuntimeException(); StepVerifier.create(Flux.<Long>error(error) .switchOnFirst((s, f) -> { first[0] = s; throw npe; })) .expectSubscription() .expectError(NullPointerException.class) .verifyThenAssertThat() .hasOperatorErrorsSatisfying(c -> { Iterator<Tuple2<Optional<Throwable>, Optional<?>>> iterator = c.iterator(); iterator.next(); Tuple2<Optional<Throwable>, Optional<?>> t = iterator.next(); Assertions.assertThat(t.getT1()) .containsInstanceOf(NullPointerException.class); Assertions.assertThat(t.getT2()) .containsInstanceOf(RuntimeException.class); }); Assertions.assertThat(first).containsExactly(Signal.error(error)); }
@Test public void shouldReturnNormallyIfExceptionIsThrownOnNextDuringSwitching() { Signal<? extends Long>[] first = new Signal[1]; StepVerifier.create(Flux.just(1L) .switchOnFirst((s, f) -> { first[0] = s; throw new NullPointerException(); })) .expectSubscription() .expectError(NullPointerException.class) .verifyThenAssertThat() .hasOperatorErrorsSatisfying(c -> Assertions.assertThat(c) .hasOnlyOneElementSatisfying(t -> { Assertions.assertThat(t.getT1()).containsInstanceOf(NullPointerException.class); Assertions.assertThat((Optional)t.getT2()).hasValue(1L); }) ); Assertions.assertThat((long) first[0].get()).isEqualTo(1L); }
@Test void strategies() { final StrategyProvider s = mock(StrategyProvider.class); when(s.getToInvest()).thenReturn(Optional.of(mock(InvestmentStrategy.class))); when(s.getToSell()).thenReturn(Optional.of(mock(SellStrategy.class))); when(s.getToPurchase()).thenReturn(Optional.of(mock(PurchaseStrategy.class))); final PowerTenantImpl t = new PowerTenantImpl(SESSION_DRY, null, null, s, null); assertThat(t.getInvestmentStrategy()).containsInstanceOf(InvestmentStrategy.class); assertThat(t.getSellStrategy()).containsInstanceOf(SellStrategy.class); assertThat(t.getPurchaseStrategy()).containsInstanceOf(PurchaseStrategy.class); }
@org.junit.jupiter.api.Test void testWithExpectedException_exceptionThrownOfSupertype_fails() { ExecutionEventRecorder eventRecorder = executeTests(TestTestCase.class, "testWithExpectedException_exceptionThrownOfSupertype"); assertThat(eventRecorder.getTestStartedCount()).isEqualTo(1); assertThat(eventRecorder.getTestFailedCount()).isEqualTo(1); //@formatter:off Optional<Throwable> failedTestThrowable = eventRecorder .getFailedTestFinishedEvents().get(0) .getPayload(TestExecutionResult.class) .flatMap(TestExecutionResult::getThrowable); //@formatter:on assertThat(failedTestThrowable).containsInstanceOf(RuntimeException.class); }
@Test void withConfirmation() { final CommandLine cli = mock(CommandLine.class); when(cli.isDryRunEnabled()).thenReturn(true); when(cli.getStrategyLocation()).thenReturn(""); final SecretProvider secretProvider = SecretProvider.inMemory("user", "pass".toCharArray()); when(cli.getConfirmationCredentials()).thenReturn(Optional.of(SERVICE + ":" + SERVICE_TOKEN)); final OperatingMode mode = new OperatingMode(mock(Supplier.class)); final Optional<InvestmentMode> config = mode.configure(cli, secretProvider); assertSoftly(softly -> { softly.assertThat(config).containsInstanceOf(DaemonInvestmentMode.class); softly.assertThat(secretProvider.getSecret(SERVICE)).contains(SERVICE_TOKEN.toCharArray()); }); }
private void assertSingleFailedTest(ExecutionEventRecorder executionEventRecorder, Class<? extends Throwable> clazz, String message) { assertEquals(1, executionEventRecorder.getTestStartedCount()); assertEquals(1, executionEventRecorder.getTestFailedCount()); assertEquals(0, executionEventRecorder.getTestSuccessfulCount()); ExecutionEvent executionEvent = executionEventRecorder.getFailedTestFinishedEvents().get(0); Optional<TestExecutionResult> result = executionEvent.getPayload(TestExecutionResult.class); assertThat(result).isPresent(); assertThat(result.get().getStatus()).isEqualTo(FAILED); Optional<Throwable> throwable = result.get().getThrowable(); assertThat(throwable).containsInstanceOf(clazz); assertThat(throwable.get()).hasMessageContaining(message); } }
@Test public void putMailRepositoryShouldReturnOkWhenRepositoryIsCreated() { given() .params("protocol", "memory") .when() .put(PATH_ESCAPED_MY_REPO) .then() .statusCode(HttpStatus.NO_CONTENT_204); assertThat(mailRepositoryStore.get(URL_MY_REPO)) .isNotEmpty() .containsInstanceOf(MemoryMailRepository.class); }
@Test public void putMailRepositoryShouldReturnOkWhenRepositoryAlreadyExists() throws Exception { given() .params("protocol", "memory") .when() .put(PATH_ESCAPED_MY_REPO) .then() .statusCode(HttpStatus.NO_CONTENT_204); given() .params("protocol", "memory") .when() .put(PATH_ESCAPED_MY_REPO) .then() .statusCode(HttpStatus.NO_CONTENT_204); assertThat(mailRepositoryStore.get(URL_MY_REPO)) .isNotEmpty() .containsInstanceOf(MemoryMailRepository.class); assertThat(mailRepositoryStore.getByPath(PATH_MY_REPO)) .hasSize(1); }