com.github.dakusui.actionunit.io.Writer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of actionunit Show documentation
Show all versions of actionunit Show documentation
A library to build 'action' structure for testing
package com.github.dakusui.actionunit.io;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* An interface that abstracts various destinations to which {@link com.github.dakusui.actionunit.visitors.ActionPrinter}'s
* output goes.
*/
public interface Writer {
void writeLine(String s);
class Impl implements Writer, Iterable {
List arr = new ArrayList<>();
@Override
public void writeLine(String s) {
arr.add(s);
}
@Override
public Iterator iterator() {
return this.arr.iterator();
}
}
enum Std implements Writer {
OUT {
@Override
public void writeLine(String s) {
System.out.println(s);
}
},
ERR {
@Override
public void writeLine(String s) {
System.err.println(s);
}
};
@Override
public abstract void writeLine(String s);
}
enum Slf4J implements Writer {
TRACE {
@Override
public void writeLine(String s) {
LOGGER.trace(s);
}
},
DEBUG {
@Override
public void writeLine(String s) {
LOGGER.debug(s);
}
},
INFO {
@Override
public void writeLine(String s) {
LOGGER.info(s);
}
},
WARN {
@Override
public void writeLine(String s) {
LOGGER.warn(s);
}
},
ERROR {
@Override
public void writeLine(String s) {
LOGGER.error(s);
}
};
private static final Logger LOGGER = LoggerFactory.getLogger(Slf4J.class);
}
}