private void assertNoIssues(Set<AnalyzerMessage> issues, boolean bypass) { assertThat(issues).overridingErrorMessage("No issues expected but got: " + issues).isEmpty(); if (!bypass) { // make sure we do not copy&paste verifyNoIssue call when we intend to call verify assertThat(expected.isEmpty()).overridingErrorMessage("The file should not declare noncompliants when no issues are expected").isTrue(); } } }
private void testForJavaxAnnotation(Class<? extends Annotation> annotation) { Reflections reflections = new Reflections(""); Set<Class<?>> googleInjects = reflections.getTypesAnnotatedWith(annotation); String outputMsg = "Testing for incorrect use of " + annotation.getName(); if (!googleInjects.isEmpty()) { StringBuilder buf = new StringBuilder(); for (Class<?> clazz : googleInjects) { buf.append(clazz.getName()); buf.append(";"); } outputMsg = buf.toString(); } assertThat(googleInjects).hasSize(0) .overridingErrorMessage(outputMsg); }
@Nonnull public MethodSpecAssert hasModifier(@Nonnull Modifier... expected) { isNotNull(); final Set<Modifier> actual = this.actual.modifiers; Assertions.assertThat(actual) .overridingErrorMessage("Expecting <%s> to contain but could not find <%s>", actual, expected) .contains(expected); return this; }
@Nonnull public FieldSpecAssert hasModifier(@Nonnull Modifier... expected) { isNotNull(); final Set<Modifier> actual = this.actual.modifiers; Assertions.assertThat(actual) .overridingErrorMessage("Expected modifier to be <%s>, but was <%s>", expected, actual) .contains(expected); return this; }
public ThingAssert hasFeatureProperties(final String featureId, final FeatureProperties expectedFeatureProperties) { isNotNull(); final FeatureProperties actualProperties = actual.getFeatures() // .flatMap(features -> features.getFeature(featureId)) // .flatMap(Feature::getProperties) // .orElse(null); assertThat(actualProperties) // .overridingErrorMessage("Expected Thing Feature <%s> to have the properties \n<%s> but it had \n<%s>", featureId, expectedFeatureProperties, actualProperties) // .isEqualTo(expectedFeatureProperties); return this; }
public DittoHeadersAssert hasAuthorizationContext(final AuthorizationContext expectedAuthorizationContext) { isNotNull(); final AuthorizationContext actualAuthorizationContext = actual.getAuthorizationContext(); Assertions.assertThat(actualAuthorizationContext) .overridingErrorMessage("Expected AuthorizationContext of DittoHeaders to be\n<%s> but it " + "was\n<%s>", expectedAuthorizationContext, actualAuthorizationContext) .isEqualTo(expectedAuthorizationContext); return myself; }
public DittoHeadersAssert hasNoReadSubjects() { isNotNull(); final Set<String> actualReadSubjects = actual.getReadSubjects(); Assertions.assertThat(actualReadSubjects) .overridingErrorMessage("Expected DittoHeaders not to have read subjects but it had <%s>", actualReadSubjects) .isEmpty(); return myself; }
@Test public void createByMap() { final Map<Locale, String> map = new HashMap<>(); map.put(Locale.GERMAN, "Hundefutter"); map.put(Locale.ENGLISH, "dog food"); final LocalizedString ls = LocalizedString.of(map); assertThat(ls.getLocales()).containsExactly(Locale.GERMAN, Locale.ENGLISH); assertThat(ls).isEqualTo(LocalizedString.of(Locale.GERMAN, "Hundefutter", Locale.ENGLISH, "dog food")); map.remove(Locale.GERMAN); map.put(Locale.forLanguageTag("es"), "Comida para perro"); assertThat(ls.getLocales()) .overridingErrorMessage("changes in the creation map do not change the created object") .containsExactly(Locale.GERMAN, Locale.ENGLISH); assertThat(ls).isEqualTo(LocalizedString.of(Locale.GERMAN, "Hundefutter", Locale.ENGLISH, "dog food")); assertThat(ls.get(Locale.GERMAN)).isEqualTo("Hundefutter"); }
@Test public void createHierarchy() throws Exception { final List<Category> allCategories = createCategoryHierarchyAsFlatList(); final CategoryTree tree = CategoryTree.of(allCategories); assertThat(extractIdSet(tree.getAllAsFlatList())) .overridingErrorMessage("all categories are present").isEqualTo(extractIdSet(allCategories)); assertThat(extractIdSet(tree.getRoots())) .isEqualTo(new HashSet<>(rootIds)); final List<Category> nameSortedRoots = byNameSorted(tree); final Category category0 = nameSortedRoots.get(0); assertThat(category0.getId()).isEqualTo(rootIds.get(0)); final List<Category> childrenOf0 = tree.findChildren(category0); assertThat(childrenOf0).hasSize(childIds.size()); final List<Category> sortedChildren = childrenOf0.stream().sorted(byNameComparator).collect(toList()); assertThat(sortedChildren.get(1).getId()).isEqualTo("0b"); final List<Category> sortedGrandChildren = tree.findChildren(sortedChildren.get(1)).stream().sorted(byNameComparator).collect(toList()); assertThat(extractIdList(sortedGrandChildren)).isEqualTo(asList("0bu", "0bv", "0bw", "0bx")); }
.overridingErrorMessage(outputMsg);
public PolicyAssert hasLabel(final Label expectedLabel) { isNotNull(); assertThat(actual.getLabels()).contains(expectedLabel) // .overridingErrorMessage("Expected Labels to contain \n<%s> but did not: \n<%s>", expectedLabel, actual.getLabels()); return this; }
public PolicyAssert doesNotHaveLabel(final Label expectedLabel) { isNotNull(); assertThat(actual.getLabels()).doesNotContain(expectedLabel) // .overridingErrorMessage("Expected Labels to NOT contain \n<%s> but it did: \n<%s>", expectedLabel, actual.getLabels()); return this; }
private void isEqualTo(final Iterable<JsonField> expectedFields, final boolean compareFieldDefinitions) { isNotNull(); final Collection<JsonField> missingFields = new ArrayList<>(); for (final JsonField expectedField : expectedFields) { final Optional<JsonField> actualFieldOptional = actual.getField(expectedField.getKey()); if (!actualFieldOptional.isPresent()) { missingFields.add(expectedField); } else { compareFields(expectedField, actualFieldOptional.get(), compareFieldDefinitions); } } Assertions.assertThat(missingFields) .overridingErrorMessage("Expected JSON object to contain \n<%s> but it did not contain \n<%s>", expectedFields, missingFields) .isEmpty(); final Collection<JsonField> unexpectedActualFields = new ArrayList<>(); for (final JsonField actualField : actual) { final Optional<JsonField> expectedFieldOptional = getField(expectedFields, actualField.getKey()); if (!expectedFieldOptional.isPresent()) { unexpectedActualFields.add(actualField); } } Assertions.assertThat(unexpectedActualFields) .overridingErrorMessage("Expected JSON object not to contain\n<%s> but it did", unexpectedActualFields) .isEmpty(); }
/** * Asserts that a {@link JavaCheck} will raise the expected issue provided as method parameter, and not more. Expected issues are provided as a parameter. * * @see ExpectedIssuesCollector * @param testFileName the name of the test file that has to be checked for issues * @param check the {@link JavaCheck} that is to be run against the test file * @param expectedLine the line number on which the issue message is expected (or 0 if it is a file wide issue) * @param expectedMessage the expected message */ public static void assertHasSingleIssue(final String testFileName, final JavaFileScanner check, @Nonnull @Nonnegative final Integer expectedLine, final String expectedMessage) { final TreeMultimap<Integer, String> actualIssues = ActualIssuesCollector.collect(new File(testFileName), check); final SoftAssertions softly = new SoftAssertions(); softly.assertThat(actualIssues.get(expectedLine)) .overridingErrorMessage(EXPECTED_MESSAGE_PREFIX, formatIssue(expectedLine, expectedMessage)) .contains(expectedMessage); actualIssues.remove(expectedLine, expectedMessage); softly.assertThat(actualIssues.size()) .overridingErrorMessage(UNEXPECTED_MESSAGE_PREFIX, formatIssues(actualIssues)) .isEqualTo(0); softly.assertAll(); }
assertThat(result.head().map(e -> e.getId())).contains(entry.getId()); assertThat(result.head().get().getSupplyChannel().getObj().getRoles()) .overridingErrorMessage("can expand supplyChannel reference") .contains(channelRole); return entry;