com.github.robindevilliers.cascade.utils.Utils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cascade Show documentation
Show all versions of cascade Show documentation
Cascade is a blackbox testing framework
The newest version!
package com.github.robindevilliers.cascade.utils;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
public class Utils {
public static Map map(String name, T o) {
Map map = new HashMap<>();
map.put(name, o);
return map;
}
public static void sleep(long millis){
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
//ignore
}
}
public static void printException(String message, Throwable f){
StringWriter stringWriter = new StringWriter();
stringWriter.append("------------ CASCADE ERROR -----------------\n");
stringWriter.append("\n");
stringWriter.append(message).append("\n");
stringWriter.append("\n");
f.printStackTrace(new PrintWriter(stringWriter));
stringWriter.append("--------------------------------------------");
System.err.println(stringWriter.toString());
}
@FunctionalInterface
public interface ExceptionalRunnable {
void doIt() throws Exception;
}
public static void wrapChecked(ExceptionalRunnable runnable){
try {
runnable.doIt();
} catch (Exception e){
if (e instanceof RuntimeException){
throw (RuntimeException) e;
} else {
throw new RuntimeException(e);
}
}
}
}