1 package com.atlassian.webdriver.rule;
2
3 import org.junit.runners.model.Statement;
4
5 import static com.google.common.base.Preconditions.checkNotNull;
6
7
8
9
10
11
12 public final class SafeStatementInvoker
13 {
14 private boolean success = true;
15 private Throwable error = null;
16
17 private final Statement statement;
18
19 public SafeStatementInvoker(Statement statement)
20 {
21 this.statement = checkNotNull(statement);
22 }
23
24 public void invokeSafely()
25 {
26 try
27 {
28 statement.evaluate();
29 }
30 catch (Throwable throwable)
31 {
32 this.error = throwable;
33 this.success = false;
34 }
35 }
36
37 public boolean isSuccess()
38 {
39 return success;
40 }
41
42 public Throwable getError()
43 {
44 return error;
45 }
46 }