import java.io.OutputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
-import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.maven.plugin.MojoExecutionException;
import org.ops4j.pax.exam.ExamSystem;
import org.ops4j.pax.exam.TestContainer;
final var stdout = System.out;
System.setOut(new PrintStream(OutputStream.nullOutputStream(), true, StandardCharsets.UTF_8));
- final var containerStarted = new AtomicBoolean(false);
try {
- container.start();
- containerStarted.set(true);
-
- // build probe
- final var probeBuilder = examSystem.createProbe();
- final var address = probeBuilder.addTest(TestProbe.class, "testFeature");
- probeBuilder.addTest(TestProbe.CheckResult.class);
+ try {
+ container.start();
+ } catch (RuntimeException e) {
+ throw new MojoExecutionException(e);
+ }
- // install probe bundle
- container.install(probeBuilder.build().getStream());
- // execute probe testMethod
- container.call(address);
+ try {
+ // build probe
+ final var probeBuilder = examSystem.createProbe();
+ final var address = probeBuilder.addTest(TestProbe.class, "testFeature");
+ probeBuilder.addTest(TestProbe.CheckResult.class);
- } catch (RuntimeException | IOException e) {
- throw new MojoExecutionException(e);
- } finally {
- if (containerStarted.get()) {
+ // install probe bundle
+ container.install(probeBuilder.build().getStream());
+ // execute probe testMethod
+ container.call(address);
+ } catch (RuntimeException | IOException e) {
+ throw new MojoExecutionException(e);
+ } finally {
container.stop();
}
+ } finally {
// restore stdout
System.setOut(stdout);
}