-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change structure of assertion manager to rely on guice instead of flags
- Loading branch information
Showing
11 changed files
with
86 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package xbot.common.logging; | ||
|
||
public class LoudRobotAssertionManager extends RobotAssertionManager { | ||
|
||
@Override | ||
protected void handlePlatformException(RuntimeException e) { | ||
throw e; | ||
} | ||
|
||
@Override | ||
public boolean isExceptionsEnabled() { | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package xbot.common.logging; | ||
|
||
public class RobotAssertionException extends RuntimeException { | ||
public RobotAssertionException(String failureCauseCause) { | ||
super("Assertion error: " + failureCauseCause); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package xbot.common.logging; | ||
|
||
import java.util.Arrays; | ||
import java.util.stream.Collectors; | ||
|
||
import org.apache.log4j.Logger; | ||
|
||
public abstract class RobotAssertionManager { | ||
static Logger log = Logger.getLogger(RobotAssertionManager.class); | ||
|
||
public final void throwException(RuntimeException e) { | ||
log.error("Safe exception encountered (exception throw " + (this.isExceptionsEnabled() ? "enabled" : "disabled") + "): " | ||
+ e.getMessage()); | ||
log.error("Stack trace: \n " | ||
+ Arrays.stream(e.getStackTrace()) | ||
.map(elem -> elem.toString()) | ||
.collect(Collectors.joining("\n "))); | ||
|
||
handlePlatformException(e); | ||
} | ||
|
||
protected abstract void handlePlatformException(RuntimeException e); | ||
|
||
public abstract boolean isExceptionsEnabled(); | ||
|
||
public final void throwException(String message, Throwable cause) { | ||
throwException(new RuntimeException(message, cause)); | ||
} | ||
|
||
public final void assertTrue(boolean value, String assertionFaliureCause) { | ||
if(!value) { | ||
throwException(new RobotAssertionException(assertionFaliureCause)); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package xbot.common.logging; | ||
|
||
public class SilentRobotAssertionManager extends RobotAssertionManager { | ||
|
||
@Override | ||
protected void handlePlatformException(RuntimeException e) { | ||
// Don't do anything: we don't need to throw | ||
} | ||
|
||
@Override | ||
public boolean isExceptionsEnabled() { | ||
return false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters