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

com.github.t1.testcontainers.tools.AbstractLogLinesAssert Maven / Gradle / Ivy

The newest version!
package com.github.t1.testcontainers.tools;

import org.assertj.core.api.AbstractAssert;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import static com.github.t1.testcontainers.tools.LogLine.parseLines;

@SuppressWarnings("UnusedReturnValue")
abstract public class AbstractLogLinesAssert>
        extends AbstractAssert> {
    public AbstractLogLinesAssert(String actual) {this(parseLines(actual));}

    public AbstractLogLinesAssert(Iterator actual) {this(actual, AbstractLogLinesAssert.class);}

    protected AbstractLogLinesAssert(Iterator actual, Class selfType) {super(actual, selfType);}

    public AbstractLogLinesAssert hasFollowingMessage(String expected) {
        return hasFollowing(LogLine.message(expected));
    }

    public AbstractLogLinesAssert hasFollowing(LogLine expected) {
        while (actual.hasNext()) {
            LogLine next = actual.next();
            if (next.matches(expected)) return this;
        }
        throw failure("expected logs to contain <%s>", expected);
    }

    public AbstractLogLinesAssert hasNoFollowingMessage(String expected) {
        return hasNoFollowing(LogLine.message(expected));
    }

    public AbstractLogLinesAssert hasNoFollowing(LogLine expected) {
        while (actual.hasNext()) {
            LogLine next = actual.next();
            if (next.matches(expected)) {
                throw failure("expected logs to NOT contain <%s>", expected);
            }
        }
        return this;
    }

    public LogLinesAssert thread(String thread) {
        List filtered = new ArrayList<>();
        while (actual.hasNext()) {
            LogLine next = actual.next();
            if (thread.equals(next.getThread())) filtered.add(next);
        }
        var iterator = filtered.iterator();
        return new LogLinesAssert(iterator);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy