Refine search
@Test public void optionalValued() { Optional<String> result = Mono.just("foo").blockOptional(); assertThat(result).contains("foo"); }
@Test public void optional() { Type optionalString = new GenericType<Optional<String>>() {}.getType(); assertThat(factory.accepts(optionalString)).isTrue(); assertThat(factory.accepts(Optional.class)).isFalse(); assertThat(factory.elementType(optionalString)).contains(String.class); Collector<String, ?, Optional<String>> collector = (Collector<String, ?, Optional<String>>) factory.build(optionalString); assertThat(Stream.<String>empty().collect(collector)).isEmpty(); assertThat(Stream.of("foo").collect(collector)).contains("foo"); assertThatThrownBy(() -> Stream.of("foo", "bar").collect(collector)) .isInstanceOf(IllegalStateException.class) .hasMessageContaining("Multiple values"); } }
private <C extends Collection<String>> void testCollectionType(GenericType<C> genericType) { Type containerType = genericType.getType(); Class<?> erasedType = getErasedType(containerType); assertThat(factory.accepts(containerType)).isTrue(); assertThat(factory.accepts(erasedType)).isFalse(); assertThat(factory.elementType(containerType)).contains(String.class); Collector<String, ?, C> collector = (Collector<String, ?, C>) factory.build(containerType); assertThat(Stream.of("foo", "bar", "baz").collect(collector)) .isInstanceOf(erasedType) .containsOnly("foo", "bar", "baz"); } }
private <M extends Map<Long, String>> void testMapType(GenericType<M> genericType) { Type containerType = genericType.getType(); Class<?> erasedType = getErasedType(containerType); assertThat(factory.accepts(containerType)).isTrue(); assertThat(factory.accepts(erasedType)).isFalse(); assertThat(factory.elementType(containerType)).contains(resolveMapEntryType(Long.class, String.class)); Collector<Map.Entry<Long, String>, ?, M> collector = (Collector<Map.Entry<Long, String>, ?, M>) factory.build(containerType); assertThat(Stream.of(entry(1L, "foo"), entry(2L, "bar"), entry(3L, "baz")).collect(collector)) .isInstanceOf(erasedType) .containsOnly(entry(1L, "foo"), entry(2L, "bar"), entry(3L, "baz")); assertThatThrownBy(() -> Stream.of(entry(1L, "foo"), entry(1L, "bar")).collect(collector)) .isInstanceOf(IllegalStateException.class) .hasMessageContaining("Multiple values"); } }
@Test public void timeoutOptionalValued() { Optional<String> result = Mono.just("foo") .blockOptional(Duration.ofMillis(500)); assertThat(result).contains("foo"); }
private <C extends Collection<String>> void testCollectionType(GenericType<C> genericType) { Type containerType = genericType.getType(); Class<?> erasedType = getErasedType(containerType); assertThat(factory.accepts(containerType)).isTrue(); assertThat(factory.accepts(erasedType)).isFalse(); assertThat(factory.elementType(containerType)).contains(String.class); Collector<String, ?, C> collector = (Collector<String, ?, C>) factory.build(containerType); assertThat(Stream.of("foo", "bar", "baz").collect(collector)) .isInstanceOf(erasedType) .containsOnly("foo", "bar", "baz"); } }
@Test public void findOptionalAmongstColl_found() { assertThat(ServiceUtils.findOptionalAmongst(String.class, Arrays.asList( 2, "t1"))).contains("t1"); }
private void verifyCeTask(CeTaskSubmit taskSubmit, CeTask task, @Nullable ComponentDto componentDto, @Nullable UserDto userDto) { if (componentDto == null) { assertThat(task.getOrganizationUuid()).isEqualTo(defaultOrganizationProvider.get().getUuid()); } else { assertThat(task.getOrganizationUuid()).isEqualTo(componentDto.getOrganizationUuid()); } assertThat(task.getUuid()).isEqualTo(taskSubmit.getUuid()); assertThat(task.getType()).isEqualTo(taskSubmit.getType()); if (componentDto != null) { CeTask.Component component = task.getComponent().get(); assertThat(component.getUuid()).isEqualTo(componentDto.uuid()); assertThat(component.getKey()).contains(componentDto.getDbKey()); assertThat(component.getName()).contains(componentDto.name()); } else if (taskSubmit.getComponent().isPresent()) { assertThat(task.getComponent()).contains(new CeTask.Component(taskSubmit.getComponent().get().getUuid(), null, null)); } else { assertThat(task.getComponent()).isEmpty(); } if (taskSubmit.getSubmitterUuid() != null) { if (userDto == null) { assertThat(task.getSubmitter().getUuid()).isEqualTo(taskSubmit.getSubmitterUuid()); assertThat(task.getSubmitter().getLogin()).isNull(); } else { assertThat(task.getSubmitter().getUuid()).isEqualTo(userDto.getUuid()).isEqualTo(taskSubmit.getSubmitterUuid()); assertThat(task.getSubmitter().getUuid()).isEqualTo(userDto.getLogin()); } } }
@Test public void findOptionalAmongstArray_found() { assertThat(ServiceUtils.findOptionalAmongst(String.class, 2, "t1")).contains("t1"); }
@SuppressWarnings("unchecked") private <M extends Multimap<Long, String>> void testMultimapCollector(Class<? extends Multimap> erasedType, GenericType<M> genericType) { JdbiCollectors registry = dbRule.getJdbi().getConfig(JdbiCollectors.class); assertThat(registry.findElementTypeFor(genericType.getType())) .contains(new GenericType<Map.Entry<Long, String>>(){}.getType()); Collector<Map.Entry<Long, String>, ?, M> collector = (Collector<Map.Entry<Long, String>, ?, M>) registry .findFor(genericType.getType()) .orElseThrow(() -> new IllegalStateException("Missing collector for " + genericType)); M map = Stream.of(entry(1L, "foo"), entry(2L, "bar")).collect(collector); assertThat(map) .isInstanceOf(erasedType) .containsAllEntriesOf(ImmutableMultimap.of(1L, "foo", 2L, "bar")); } }
@Test public void testOptionalReturnPresent() { assertThat(dao.findNameById(1)).contains("brian"); }
@SuppressWarnings("unchecked") private <M extends Map<Long, String>> void testMapCollector(Class<? extends Map> erasedType, GenericType<M> genericType) { JdbiCollectors registry = dbRule.getJdbi().getConfig(JdbiCollectors.class); assertThat(registry.findElementTypeFor(genericType.getType())) .contains(new GenericType<Map.Entry<Long, String>>(){}.getType()); Collector<Map.Entry<Long, String>, ?, M> collector = (Collector<Map.Entry<Long, String>, ?, M>) registry .findFor(genericType.getType()) .orElseThrow(() -> new IllegalStateException("Missing collector for " + genericType)); M map = Stream.of(entry(1L, "foo"), entry(2L, "bar")).collect(collector); assertThat(map) .isInstanceOf(erasedType) .containsExactly(entry(1L, "foo"), entry(2L, "bar")); }
@Test public void getLastMigrationNumber_returns_last_version_assuming_version_are_only_number() throws SQLException { insert(12, 5, 30, 8); assertThat(underTest.getLastMigrationNumber()).contains(30L); }
private void verifyCeTask(CeTaskSubmit taskSubmit, CeTask task, @Nullable ComponentDto componentDto, @Nullable ComponentDto mainComponentDto, @Nullable UserDto userDto) { if (componentDto == null) { assertThat(task.getOrganizationUuid()).isEqualTo(defaultOrganizationProvider.get().getUuid()); } else { assertThat(task.getOrganizationUuid()).isEqualTo(componentDto.getOrganizationUuid()); assertThat(task.getUuid()).isEqualTo(taskSubmit.getUuid()); if (componentDto != null) { CeTask.Component component = task.getComponent().get(); assertThat(component.getUuid()).isEqualTo(componentDto.uuid()); assertThat(component.getKey()).contains(componentDto.getDbKey()); assertThat(component.getName()).contains(componentDto.name()); } else if (taskSubmit.getComponent().isPresent()) { assertThat(task.getComponent()).contains(new CeTask.Component(taskSubmit.getComponent().get().getUuid(), null, null)); } else { assertThat(task.getComponent()).isEmpty(); CeTask.Component component = task.getMainComponent().get(); assertThat(component.getUuid()).isEqualTo(mainComponentDto.uuid()); assertThat(component.getKey()).contains(mainComponentDto.getDbKey()); assertThat(component.getName()).contains(mainComponentDto.name()); } else if (taskSubmit.getComponent().isPresent()) { assertThat(task.getMainComponent()).contains(new CeTask.Component(taskSubmit.getComponent().get().getMainComponentUuid(), null, null)); } else { assertThat(task.getMainComponent()).isEmpty();
@Test public void selectByKey_returns_value_when_property_has_value_stored_in_clob() { underTest.save(dbSession, A_KEY, VALUE_SIZE_4001); assertThat(underTest.selectByKey(dbSession, A_KEY)).contains(VALUE_SIZE_4001); }
@Test public void selectByKey_returns_empty_string_when_property_is_empty_in_DB() { underTest.saveAsEmpty(dbSession, A_KEY); assertThat(underTest.selectByKey(dbSession, A_KEY)).contains(EMPTY_STRING); }
@Test public void selectByKey_returns_value_when_property_has_value_stored_in_varchar() { underTest.save(dbSession, A_KEY, VALUE_SMALL); assertThat(underTest.selectByKey(dbSession, A_KEY)).contains(VALUE_SMALL); }
@Test public void isCauseInterruptedException_returns_CeTaskInterruptedException_or_subclass_in_cause_chain() { String message = randomAlphabetic(50); CeActivityDto.Status status = randomStatus(); CeTaskInterruptedException e1 = new CeTaskInterruptedException(message, status) { }; CeTaskInterruptedException e2 = new CeTaskInterruptedExceptionSubclass(message, status); assertThat(isTaskInterruptedException(new RuntimeException(e1))).contains(e1); assertThat(isTaskInterruptedException(new Exception(new RuntimeException(e2)))).contains(e2); }
@Test public void optionalValuedDelayed() { Optional<String> result = Mono.just("foo") .delayElement(Duration.ofMillis(500)) .blockOptional(); assertThat(result).contains("foo"); }
@Test public void getPreviousStatus_returns_empty_when_previousStatus_is_null() { QGChangeEvent underTest = new QGChangeEvent(project, branch, analysis, configuration, previousStatus, supplier); assertThat(underTest.getPreviousStatus()).contains(previousStatus); }