@Nonnull public MethodSpecAssert hasNoParameter() { isNotNull(); final List<ParameterSpec> actual = this.actual.parameters; Assertions.assertThat(actual) .overridingErrorMessage("Expected parameters to be empty, but was <%s>", actual) .isEmpty(); return this; }
@Nonnull public FieldSpecAssert hasNoAnnotation() { isNotNull(); final List<AnnotationSpec> actual = this.actual.annotations; Assertions.assertThat(actual) .overridingErrorMessage("Expected annotation to be empty, but was <%s>", actual) .isEmpty(); return this; }
@Nonnull public MethodSpecAssert hasNoException() { isNotNull(); final List<TypeName> actual = this.actual.exceptions; Assertions.assertThat(actual) .overridingErrorMessage("Expected exception to be empty, but was <%s>", actual) .isEmpty(); return this; }
@Nonnull public MethodSpecAssert hasNoAnnotation() { isNotNull(); final List<AnnotationSpec> actual = this.actual.annotations; Assertions.assertThat(actual) .overridingErrorMessage("Expected annotation to be empty, but was <%s>", actual) .isEmpty(); return this; }
@Nonnull public MethodSpecAssert hasAnnotation(@Nonnull AnnotationSpec expected) { isNotNull(); final List<AnnotationSpec> actual = this.actual.annotations; Assertions.assertThat(actual) .overridingErrorMessage("Expecting <%s> to contain but could not find <%s>", actual, expected) .contains(expected); return this; }
@Nonnull public MethodSpecAssert hasParameter(@Nonnull ParameterSpec expected) { isNotNull(); final List<ParameterSpec> actual = this.actual.parameters; Assertions.assertThat(actual) .overridingErrorMessage("Expecting <%s> to contain but could not find <%s>", actual, expected) .contains(expected); return this; }
@Nonnull public TypeSpecAssert hasAnnotation(@Nonnull AnnotationSpec expected) { isNotNull(); final List<AnnotationSpec> actual = this.actual.annotations; Assertions.assertThat(actual) .overridingErrorMessage("Expecting <%s> to contain but could not find <%s>", actual, expected) .contains(expected); return this; } }
@Nonnull public FieldSpecAssert hasAnnotation(@Nonnull AnnotationSpec expected) { isNotNull(); final List<AnnotationSpec> actual = this.actual.annotations; Assertions.assertThat(actual) .overridingErrorMessage("Expecting <%s> to contain but could not find <%s>", actual, expected) .contains(expected); return this; }
public DittoHeadersAssert hasNoAuthorizationSubjects() { isNotNull(); final List<String> actualAuthorizationSubjects = actual.getAuthorizationSubjects(); Assertions.assertThat(actualAuthorizationSubjects) .overridingErrorMessage("Expected DittoHeaders not to have authorization subjects but it had <%s>", actualAuthorizationSubjects) .isEmpty(); return myself; }
/** * Verifies that the JSON object contains all specified keys. * * @param expectedJsonKey the mandatory key whose existence is checked. * @param furtherExpectedJsonKeys further optional keys whose existence in the JSON object is checked. * @return this assertion object. */ public JsonObjectAssert containsKey(final CharSequence expectedJsonKey, final CharSequence... furtherExpectedJsonKeys) { isNotNull(); final Collection<CharSequence> allExpectedJsonKeys = new ArrayList<>(1 + furtherExpectedJsonKeys.length); allExpectedJsonKeys.add(expectedJsonKey); Collections.addAll(allExpectedJsonKeys, furtherExpectedJsonKeys); final List<CharSequence> missingKeys = new ArrayList<>(); for (final CharSequence jsonKey : allExpectedJsonKeys) { if (!actual.contains(jsonKey)) { missingKeys.add(jsonKey); } } Assertions.assertThat(missingKeys) .overridingErrorMessage("Expected JSON object to contain key(s) <%s> but it did not contain <%s>", allExpectedJsonKeys, missingKeys) .isEmpty(); return myself; }
private ProcessInstanceAssert isWaitingFor(final String[] messageNames, boolean isWaitingFor) { isNotNull(); Assertions.assertThat(messageNames) .overridingErrorMessage("Expecting list of messageNames not to be null, not to be empty and not to contain null values: %s." , Lists.newArrayList(messageNames)) .isNotNull().isNotEmpty().doesNotContainNull(); for (String messageName : messageNames) { List<Execution> executions = executionQuery().messageEventSubscriptionName(messageName).list(); ListAssert<Execution> assertion = Assertions.assertThat(executions).overridingErrorMessage("Expecting %s " + (isWaitingFor ? "to be waiting for %s, " : "NOT to be waiting for %s, ") + "but actually did " + (isWaitingFor ? "not " : "") + "find it to be waiting for message [%s].", actual, Arrays.asList(messageNames), messageName); if (isWaitingFor) { assertion.isNotEmpty(); } else { assertion.isEmpty(); } } return this; }
public void containsAuthorizationSubject(final String... expectedAuthSubject) { final DittoHeaders actualDittoHeaders = actual.getDittoHeaders(); final List<String> actualAuthorizationSubjects = actualDittoHeaders.getAuthorizationSubjects(); Assertions.assertThat(actualAuthorizationSubjects) .overridingErrorMessage("Expected command headers to contain <%s> but it did not", expectedAuthSubject) .contains(expectedAuthSubject); }
/** * Verifies that the actual JSON pointer does not contain the specified key(s). * * @param unexpectedKey the key which should not be contained in the JSON pointer. * @param furtherUnexpectedKeys further keys which should not be contained in the JSON pointer. * @return this assert to allow method chaining. */ public JsonPointerAssert doesNotContainKey(final CharSequence unexpectedKey, final CharSequence... furtherUnexpectedKeys) { isNotNull(); final List<CharSequence> allUnexpectedKeys = merge(unexpectedKey, furtherUnexpectedKeys); final List<CharSequence> existingKeys = new ArrayList<>(); for (final CharSequence unexpKey : allUnexpectedKeys) { if (containsKey(unexpectedKey)) { existingKeys.add(unexpKey); } } Assertions.assertThat(existingKeys) .overridingErrorMessage("Expected JSON pointer not to contain key(s) <%s> but it contained <%s>", allUnexpectedKeys, existingKeys) .isEmpty(); return myself; }
private ProcessInstanceAssert isWaitingAt(final String[] activityIds, boolean exactly) { ProcessInstance current = getExistingCurrent(); Assertions.assertThat(activityIds) .overridingErrorMessage("Expecting list of activityIds not to be null, not to be empty and not to contain null values: %s." , Lists.newArrayList(activityIds)) .isNotNull().isNotEmpty().doesNotContainNull(); final List<String> activeActivityIds = runtimeService().getActiveActivityIds(actual.getId()); ListAssert<String> assertion = Assertions.assertThat(activeActivityIds) .overridingErrorMessage("Expecting %s to be waiting at '%s' but it is actually waiting at %s", toString(current), Lists.newArrayList(activityIds), activeActivityIds); if (exactly) { String[] sorted = activityIds.clone(); Arrays.sort(sorted); assertion.containsExactly(sorted); } else { assertion.contains(activityIds); } return this; }
@Test public void queryByNameScenario() { assertModelsNotPresent(); final List<Product> instances = createInBackendByName(modelNames()); final List<String> actualNames = instances.stream().map(o -> extractName(o)). filter(name -> modelNames().contains(name)).sorted().collect(toList()); final StringJoiner joiner = new StringJoiner(", "); modelNames().forEach(item -> joiner.add(item.toString())); assertThat(actualNames). overridingErrorMessage(String.format("The test requires instances with the names %s.", "[" + joiner.toString() + "]")). isEqualTo(modelNames()); final String nameToFind = modelNames().get(1); final List<Product> results = client().executeBlocking(queryObjectForName(nameToFind)).getResults(); assertThat(results).hasSize(1); assertThat(getNames(results)).isEqualTo(asList(nameToFind)); assertModelsNotPresent(); }
@Test public void plusExpansionPathDemo() throws Exception { final ProductProjectionByIdGet fetch = ProductProjectionByIdGet.of("id", ProductProjectionType.CURRENT); assertThat(fetch.expansionPaths()).isEmpty(); final ProductProjectionByIdGet fetch2 = fetch.plusExpansionPaths(ProductProjectionExpansionModel.of().categories()); assertThat(fetch.expansionPaths()).overridingErrorMessage("old object is unchanged").isEmpty(); assertThat(fetch2.expansionPaths()).isEqualTo(asList(ExpansionPath.of("categories[*]"))); assertThat(fetch2).isNotSameAs(fetch); }
@Test public void withExpansionPathDslDemo() throws Exception { final ProductProjectionByIdGet fetch = ProductProjectionByIdGet.of("id", ProductProjectionType.CURRENT) .plusExpansionPaths(ProductProjectionExpansionModel.of().categories()); assertThat(fetch.expansionPaths()) .isEqualTo(asList(ExpansionPath.of("categories[*]"))); final ProductProjectionByIdGet fetch2 = fetch.withExpansionPaths(m -> m.productType()); assertThat(fetch.expansionPaths()).overridingErrorMessage("old object is unchanged") .isEqualTo(asList(ExpansionPath.of("categories[*]"))); assertThat(fetch2.expansionPaths()).isEqualTo(asList(ExpansionPath.of("productType"))); assertThat(fetch2).isNotSameAs(fetch); }
/** * Verifies that the actual JSON object contains the expected value for the specified key. * * @param key the key of the expected value. * @param expectedValue the expected value to be associated with {@code key}. * @return this assert to allow method chaining. */ public JsonObjectAssert contains(final JsonKey key, final JsonValue expectedValue) { isNotNull(); final List<JsonKey> actualNames = actual.getKeys(); Assertions.assertThat(actualNames).contains(key) .overridingErrorMessage("Expected JSON object to contain a field with name <%s> but it did not.", key); final Optional<JsonValue> actualValue = actual.getValue(key); assertThat(actualValue) .overridingErrorMessage("Expected JSON object to contain value <%s> for key <%s> but the actual value" + " was <%s>", expectedValue, key, actualValue.orElse(null)) .contains(expectedValue); return this; }
@Test public void withExpansionPathDemo() throws Exception { final ProductProjectionByIdGet fetch = ProductProjectionByIdGet.of("id", ProductProjectionType.CURRENT) .withExpansionPaths(ProductProjectionExpansionModel.of().categories()); assertThat(fetch.expansionPaths()) .isEqualTo(asList(ExpansionPath.of("categories[*]"))); final ProductProjectionByIdGet fetch2 = fetch.withExpansionPaths(ProductProjectionExpansionModel.of().productType()); assertThat(fetch.expansionPaths()).overridingErrorMessage("old object is unchanged") .isEqualTo(asList(ExpansionPath.of("categories[*]"))); assertThat(fetch2.expansionPaths()).isEqualTo(asList(ExpansionPath.of("productType"))); assertThat(fetch2).isNotSameAs(fetch); }
private void assertModelsNotPresent() { cleanUpByName(modelNames()); assertThat(getNames(client().executeBlocking(queryRequestForQueryAll()).getResults())).overridingErrorMessage("the instances with the names " + modelNames() + " should not be present.").doesNotContainAnyElementsOf(modelNames()); } }