package fr.sii.ogham.helper.rule;

import org.apache.commons.lang3.StringUtils;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LoggingTestRule implements TestRule {
	private static final Logger LOG = LoggerFactory.getLogger(LoggingTestRule.class);
	private static final int MAX_LENGTH = 100;
	private static final String DASH = "─";
	private static final String SEPARATOR = ".";
	
	private int maxLength;
	
	public LoggingTestRule(int maxLength) {
		super();
		this.maxLength = maxLength;
	}

	public LoggingTestRule() {
		this(MAX_LENGTH);
	}


	@Override
	public Statement apply(final Statement base, final Description description) {
		return new Statement() {
			@Override
			public void evaluate() throws Throwable {
				String testName = description.getTestClass().getSimpleName()+SEPARATOR+description.getMethodName();
				String dashLine = StringUtils.repeat(DASH, maxLength-2);
				String header = "┌"+dashLine+"┐";
				String footer = "└"+dashLine+"┘";
				LOG.info(header);
				LOG.info("│{}│", format("Starting test "+testName));
				LOG.info(footer);
				try {
					base.evaluate();
					LOG.info(header);
					LOG.info("│{}│", format("Test "+testName+" successfully done"));
					LOG.info(footer+"\r\n\r\n");
				} catch(Throwable e) {
					LOG.error(header);
					LOG.error("│{}│", format("Test "+testName+" has failed"));
					LOG.error("│{}│", format("Cause: "+e));
					LOG.error(footer);
					throw e;
				}
			}
			
			private String format(String text) {
				return StringUtils.center(StringUtils.abbreviate(text, maxLength-4), maxLength-2);
			}
		};
	}

}

@@ -1528,24 +1528,35 @@
 error(footer
++%22%5Cr%5Cn%5Cr%5Cn%22
 );%0A%09%09%09%09%09thro

Add new lines