io.github.sinri.keel.tesuto.TestUnitWrapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Keel Show documentation
Show all versions of Keel Show documentation
A website framework with VERT.X for ex-PHP-ers, exactly Ark Framework Users.
The newest version!
package io.github.sinri.keel.tesuto;
import io.vertx.core.Future;
import java.lang.reflect.Method;
/**
* @since 3.0.10
*/
class TestUnitWrapper {
private final Method method;
private final TestUnit annotation;
private final TestUnitResult testUnitResult;
public TestUnitWrapper(Method method, TestUnit annotation) {
this.method = method;
this.annotation = annotation;
this.testUnitResult = new TestUnitResult(method.getName());
}
public Future runTest(KeelTest testInstance) {
long startTime = System.currentTimeMillis();
return Future.succeededFuture(annotation.skip())
.compose(toSkip -> {
if (toSkip) {
long endTime = System.currentTimeMillis();
this.testUnitResult.setSpentTime(endTime - startTime);
this.testUnitResult.declareSkipped();
return Future.succeededFuture();
} else {
return Future.succeededFuture()
.compose(vv -> {
// testInstance.getLogger().setDynamicEventLogFormatter(keelEventLog -> {
// keelEventLog.classification(this.getName());
// });
try {
return (Future>) this.method.invoke(testInstance);
} catch (Throwable e) {
throw new RuntimeException(e);
}
})
.compose(passed -> {
long endTime = System.currentTimeMillis();
this.testUnitResult.setSpentTime(endTime - startTime).declareDone();
return Future.succeededFuture();
}, throwable -> {
long endTime = System.currentTimeMillis();
this.testUnitResult.setSpentTime(endTime - startTime).declareFailed(throwable);
return Future.succeededFuture();
});
}
})
.compose(v -> {
return Future.succeededFuture(testUnitResult);
});
}
public String getName() {
return this.method.getName();
}
public boolean isSkip() {
return this.annotation.skip();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy