org.assertj.core.api.ListAssert Java Examples

The following examples show how to use org.assertj.core.api.ListAssert. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InternalArraysTest.java    From r2dbc-mysql with Apache License 2.0 6 votes vote down vote up
@Test
void toReadOnlyList() {
    Integer[] arr = new Integer[] { 1, 2, 3, 4 };

    ListAssert<Integer> listAssert = assertThat(InternalArrays.toImmutableList(arr))
        .isEqualTo(Arrays.asList(1, 2, 3, 4))
        .isNotInstanceOf(Arrays.asList(1, 2, 3, 4).getClass());

    Arrays.fill(arr, 6);

    listAssert.isEqualTo(Arrays.asList(1, 2, 3, 4));

    assertThat(InternalArrays.toImmutableList(1))
        .isEqualTo(Collections.singletonList(1))
        .isExactlyInstanceOf(Collections.singletonList(1).getClass());
    assertThat(InternalArrays.toImmutableList())
        .isEqualTo(Collections.emptyList())
        .isExactlyInstanceOf(Collections.emptyList().getClass());
}
 
Example #2
Source File: QueryAssertions.java    From presto with Apache License 2.0 6 votes vote down vote up
public QueryAssert matches(@Language("SQL") String query)
{
    MaterializedResult expected = runner.execute(session, query);

    return satisfies(actual -> {
        assertThat(actual.getTypes())
                .as("Output types")
                .isEqualTo(expected.getTypes());

        ListAssert<MaterializedRow> assertion = assertThat(actual.getMaterializedRows())
                .as("Rows")
                .withRepresentation(ROWS_REPRESENTATION);

        if (ordered) {
            assertion.containsExactlyElementsOf(expected.getMaterializedRows());
        }
        else {
            assertion.containsExactlyInAnyOrderElementsOf(expected.getMaterializedRows());
        }
    });
}
 
Example #3
Source File: Assertions.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Asserts a list by applying the given {@code elementAssert} and provides information about the concrete element
 * and index where the assertion failed.
 * @param actual the actual list to be asserted
 * @param elementAssert a {@link BiFunction} providing the actual and expected list
 * @param <T> the type of the list elements
 * @return an instance of {@link ListAssert}
 */
@SuppressWarnings("unchecked")
public static <T> ListAssert<T> assertListWithIndexInfo(final List<T> actual, final BiConsumer<T, T> elementAssert) {
    return new ListAssert<>(actual).usingComparator((actualList, expectedList) -> {
        assertThat(actualList).hasSize(expectedList.size());

        for (int i = 0; i < actualList.size(); i++) {
            final T actualElement = actualList.get(i);
            final T expectedElement = expectedList.get(i);

            try {
                elementAssert.accept(actualElement, expectedElement);
            } catch (final AssertionError e) {
                throw new AssertionError(String.format("List assertion failed at index %s:%nActual list: " +
                        "%s%nExpected list: " +
                        "%s%n%nActual element: %s%nExpected element: %s%nDetailed message: %s", i, actualList,
                        expectedList, actualElement, expectedElement, e.getMessage()), e.getCause());
            }
        }

        return 0;
    });
}
 
Example #4
Source File: Assertions.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Asserts a list by applying the given {@code elementAssert} and provides information about the concrete element
 * and index where the assertion failed.
 *
 * @param actual the actual list to be asserted
 * @param elementAssert a {@link BiFunction} providing the actual and expected list
 * @param <T> the type of the list elements
 * @return an instance of {@link ListAssert}
 */
public static <T> ListAssert<T> assertListWithIndexInfo(final List<T> actual,
        final BiConsumer<T, T> elementAssert) {
    return new ListAssert<>(actual).usingComparator((actualList, expectedList) -> {
        assertThat(actualList).hasSize(expectedList.size());

        for (int i = 0; i < actualList.size(); i++) {
            final T actualElement = actualList.get(i);
            final T expectedElement = expectedList.get(i);

            try {
                elementAssert.accept(actualElement, expectedElement);
            } catch (final AssertionError e) {
                throw new AssertionError(String.format("List assertion failed at index %s:%nActual list: " +
                                "%s%nExpected list: " +
                                "%s%n%nActual element: %s%nExpected element: %s%nDetailed message: %s", i, actualList,
                        expectedList, actualElement, expectedElement, e.getMessage()), e.getCause());
            }
        }

        return 0;
    });
}
 
Example #5
Source File: InternalArraysTest.java    From r2dbc-mysql with Apache License 2.0 6 votes vote down vote up
@Test
void toReadOnlyList() {
    Integer[] arr = new Integer[] { 1, 2, 3, 4 };

    ListAssert<Integer> listAssert = assertThat(InternalArrays.toImmutableList(arr))
        .isEqualTo(Arrays.asList(1, 2, 3, 4))
        .isNotInstanceOf(Arrays.asList(1, 2, 3, 4).getClass());

    Arrays.fill(arr, 6);

    listAssert.isEqualTo(Arrays.asList(1, 2, 3, 4));

    assertThat(InternalArrays.toImmutableList(1))
        .isEqualTo(Collections.singletonList(1))
        .isExactlyInstanceOf(Collections.singletonList(1).getClass());
    assertThat(InternalArrays.toImmutableList())
        .isEqualTo(Collections.emptyList())
        .isExactlyInstanceOf(Collections.emptyList().getClass());
}
 
Example #6
Source File: NodeAssert.java    From initializr with Apache License 2.0 5 votes vote down vote up
ListAssert<Node> nodesAtPath(String xpath) {
	try {
		NodeList nodeList = (NodeList) this.xpath.evaluate(xpath, this.actual, XPathConstants.NODESET);
		return new ListAssert<>(toList(nodeList));
	}
	catch (XPathExpressionException ex) {
		throw new RuntimeException(ex);
	}
}
 
Example #7
Source File: NodeAssert.java    From initializr with Apache License 2.0 5 votes vote down vote up
public ListAssert<Node> nodesAtPath(String xpath) {
	try {
		NodeList nodeList = (NodeList) this.xpath.evaluate(xpath, this.actual, XPathConstants.NODESET);
		return new ListAssert<>(toList(nodeList));
	}
	catch (XPathExpressionException ex) {
		throw new RuntimeException(ex);
	}
}
 
Example #8
Source File: AbstractProjectAssert.java    From initializr with Apache License 2.0 5 votes vote down vote up
/**
 * Return an {@link ListAssert assert} for the local file paths of this project, to
 * allow chaining of list-specific assertions from this call.
 * @return a {@link ListAssert} with the files of this project
 */
public ListAssert<String> filePaths() {
	if (this.filesAssert == null) {
		this.filesAssert = new ListAssert<>(getRelativePathsOfProjectFiles());
	}
	return this.filesAssert;
}
 
Example #9
Source File: TraceBaggageConfigurationTests.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
static ListAssert<Tuple> assertThatBaggageFieldNameToKeyNames(
		AssertableApplicationContext context) {
	return assertThat(context.getBean(Propagation.Factory.class))
			.extracting("configs").asInstanceOf(InstanceOfAssertFactories.ARRAY)
			.extracting("field.name", "keyNames.toArray")
			.asInstanceOf(InstanceOfAssertFactories.list(Tuple.class));
}
 
Example #10
Source File: JarFileShadingTest.java    From reactor-netty with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private ListAssert<String> assertThatFileList(Stream<Path> path) {
	return (ListAssert) assertThat(path)
			.extracting(Path::getFileName)
			.extracting(Path::toString)
			.extracting(it -> it.endsWith("/") ? it.substring(0, it.length() - 1) : it);
}
 
Example #11
Source File: CasAssert.java    From inception with Apache License 2.0 5 votes vote down vote up
public ListAssert<AnnotationFS> extractNamedEntities()
{
    isNotNull();

    Type type = CasUtil.getType(actual, TYPE_NE);
    List<AnnotationFS> result = new ArrayList<>(CasUtil.select(actual, type));
    return new ListAssert<>(result);
}
 
Example #12
Source File: GradleBuildSystemHelpDocumentCustomizerTests.java    From start.spring.io with Apache License 2.0 5 votes vote down vote up
private ListAssert<String> assertHelpDocument(String type, String version) {
	ProjectRequest request = createProjectRequest("web");
	request.setType(type);
	request.setBootVersion(version);
	ProjectStructure project = generateProject(request);
	return new TextAssert(project.getProjectDirectory().resolve("HELP.md")).lines();
}
 
Example #13
Source File: MavenBuildSystemHelpDocumentCustomizerTests.java    From start.spring.io with Apache License 2.0 5 votes vote down vote up
private ListAssert<String> assertHelpDocument(String type, String version) {
	ProjectRequest request = createProjectRequest("web");
	request.setType(type);
	request.setBootVersion(version);
	ProjectStructure project = generateProject(request);
	return new TextAssert(project.getProjectDirectory().resolve("HELP.md")).lines();
}
 
Example #14
Source File: MarkdownAssert.java    From doov with Apache License 2.0 5 votes vote down vote up
public ListAssert<String> textNodes() {
    final List<String> collector = new ArrayList<String>();
    actual.accept(new AbstractVisitor() {

        @Override
        public void visit(Text text) {
            collector.add(text.getLiteral());
            super.visit(text);
        }
    });
    return new ListAssert<>(collector);
}
 
Example #15
Source File: JarFileShadingTest.java    From testcontainers-java with MIT License 4 votes vote down vote up
private ListAssert<String> assertThatFileList(Path path) throws IOException {
    return (ListAssert) assertThat(Files.list(path))
            .extracting(Path::getFileName)
            .extracting(Path::toString)
            .extracting(it -> it.endsWith("/") ? it.substring(0, it.length() - 1) : it);
}
 
Example #16
Source File: HtmlAssert.java    From doov with Apache License 2.0 4 votes vote down vote up
public ListAssert<Element> when_UL() {
    return new ListAssert<>(actual.select("ul.dsl-ul-when").stream().collect(toList()));
}
 
Example #17
Source File: JarFileShadingTest.java    From BlockHound with Apache License 2.0 4 votes vote down vote up
private ListAssert<String> assertThatFileList(Path path) throws IOException {
	return (ListAssert) assertThat(Files.list(path))
			.extracting(Path::getFileName)
			.extracting(Path::toString)
			.extracting(it -> it.endsWith("/") ? it.substring(0, it.length() - 1) : it);
}
 
Example #18
Source File: ComponentAssert.java    From litho with Apache License 2.0 4 votes vote down vote up
/** Extract the sub components from the underlying Component, returning a ListAssert over it. */
@CheckReturnValue
public ListAssert<InspectableComponent> extractingSubComponents(ComponentContext c) {
  return extracting(SubComponentExtractor.subComponents(c));
}
 
Example #19
Source File: ComponentAssert.java    From litho with Apache License 2.0 4 votes vote down vote up
/**
 * Extract the sub components recursively from the underlying Component, returning a ListAssert
 * over it.
 */
@CheckReturnValue
public ListAssert<InspectableComponent> extractingSubComponentsDeeply(ComponentContext c) {
  return extracting(SubComponentDeepExtractor.subComponentsDeeply(c));
}
 
Example #20
Source File: DependencyAssertion.java    From smart-testing with Apache License 2.0 4 votes vote down vote up
public ListAssert<Exclusion> exclusions() {
    isNotNull();
    return Assertions.assertThat(actual.getExclusions());
}
 
Example #21
Source File: PlantUmlArchConditionTest.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
private ListAssert<String> assertThatEvaluatedConditionWithConfiguration(
        File diagramFile, Configuration configuration) {
    PlantUmlArchCondition condition = adhereToPlantUmlDiagram(diagramFile, configuration);
    EvaluationResult result = createEvaluationResult(condition, "simpledependency");
    return assertThat(result.getFailureReport().getDetails());
}
 
Example #22
Source File: HtmlAssert.java    From doov with Apache License 2.0 4 votes vote down vote up
public ListAssert<Element> binary_LI() {
    return new ListAssert<>(actual.select("li.dsl-li-binary").stream().collect(toList()));
}
 
Example #23
Source File: HtmlAssert.java    From doov with Apache License 2.0 4 votes vote down vote up
public ListAssert<Element> nary_OL() {
    return new ListAssert<>(actual.select("ol.dsl-ol-nary").stream().collect(toList()));
}
 
Example #24
Source File: HtmlAssert.java    From doov with Apache License 2.0 4 votes vote down vote up
public ListAssert<Element> nary_LI() {
    return new ListAssert<>(actual.select("li.dsl-li-nary").stream().collect(toList()));
}
 
Example #25
Source File: JsonPathAssert.java    From spring-cloud-open-service-broker with Apache License 2.0 4 votes vote down vote up
public <T> ListAssert<T> hasListAtPath(String path) {
	TypeRef<List<T>> listTypeRef = new TypeRef<List<T>>() {
	};
	return Assertions.assertThat(actual.read(path, listTypeRef));
}
 
Example #26
Source File: JarFileShadingTest.java    From reactor-core with Apache License 2.0 4 votes vote down vote up
private ListAssert<String> assertThatFileList(Path path) throws IOException {
	return (ListAssert) assertThat(Files.list(path))
			.extracting(Path::getFileName)
			.extracting(Path::toString)
			.extracting(it -> it.endsWith("/") ? it.substring(0, it.length() - 1) : it);
}
 
Example #27
Source File: CasAssert.java    From termsuite-core with Apache License 2.0 4 votes vote down vote up
public ListAssert<Annotation> getAnnotations(Class<? extends Annotation> annotationClass) {
	ListAssert<Annotation> assertThat = assertThat(getAnnotationList(annotationClass));
	return assertThat;
}
 
Example #28
Source File: TerminationSubscriberContract.java    From james-project with Apache License 2.0 4 votes vote down vote up
default ListAssert<Event> assertEvents(TerminationSubscriber subscriber) {
    return assertThat(collectEvents(subscriber.listenEvents())
        .block());
}
 
Example #29
Source File: WavefrontHelpDocumentCustomizerTests.java    From start.spring.io with Apache License 2.0 4 votes vote down vote up
private ListAssert<String> assertHelpDocument(String version, String... dependencies) {
	ProjectRequest request = createProjectRequest(dependencies);
	request.setBootVersion(version);
	ProjectStructure project = generateProject(request);
	return new TextAssert(project.getProjectDirectory().resolve("HELP.md")).lines();
}
 
Example #30
Source File: HelpDocumentProjectContributorTests.java    From initializr with Apache License 2.0 4 votes vote down vote up
private ListAssert<String> assertHelpDocument(HelpDocument document) throws IOException {
	Path projectDir = Files.createTempDirectory(this.directory, "project-");
	new HelpDocumentProjectContributor(document).contribute(projectDir);
	return new TextAssert(projectDir.resolve("HELP.md")).lines();
}