All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.softicar.platform.common.testing.TextLinesAsserter Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
package com.softicar.platform.common.testing;

import com.softicar.platform.common.string.Imploder;
import java.util.List;
import org.junit.Assert;

public class TextLinesAsserter {

	private final List lines;
	private int currentLine;

	public TextLinesAsserter(String text) {

		this(List.of(text.split("\n")));
	}

	public TextLinesAsserter(List lines) {

		this.lines = lines;
		this.currentLine = 0;
	}

	public TextLinesAsserter assertLine(String expectedLine) {

		// search for expected line
		for (int i = currentLine; i < lines.size(); ++i) {
			if (lines.get(i).equals(expectedLine)) {
				this.currentLine = i + 1;
				return this;
			}
		}

		// not found
		String remainingText = Imploder.implode(lines.subList(currentLine, lines.size()), "\n");
		String message = "Expected to find '%s' in the following:\n---\n%s\n---".formatted(expectedLine, remainingText);
		Assert.fail(message);
		return this;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy