diff options
Diffstat (limited to 'src/main/java/ftbsc/geb/exceptions')
-rw-r--r-- | src/main/java/ftbsc/geb/exceptions/BadListenerArgumentsException.java | 52 | ||||
-rw-r--r-- | src/main/java/ftbsc/geb/exceptions/MissingInterfaceException.java | 17 |
2 files changed, 69 insertions, 0 deletions
diff --git a/src/main/java/ftbsc/geb/exceptions/BadListenerArgumentsException.java b/src/main/java/ftbsc/geb/exceptions/BadListenerArgumentsException.java new file mode 100644 index 0000000..a15b4e5 --- /dev/null +++ b/src/main/java/ftbsc/geb/exceptions/BadListenerArgumentsException.java @@ -0,0 +1,52 @@ +package ftbsc.geb.exceptions; + +/** + * Thrown when there is something wrong with a listener method. + */ +public class BadListenerArgumentsException extends RuntimeException { + + /** + * The constructor. It's not meant to be used as is, refer to the subclasses + * @param message the message to pass along to the superclass + */ + protected BadListenerArgumentsException(String message) { + super(message); + } + + /** + * Thrown when the number of arguments is off. + */ + public static class Count extends BadListenerArgumentsException { + + /** + * The public constructor. + * @param clazz the fully-qualified name of the parent class + * @param method the annotated listener method + * @param count the number of arguments found + */ + public Count(String clazz, String method, int count) { + super(String.format( + "An error occurred while evaluating method %s::%s: found %d arguments, expected 1!", + clazz, method, count)); + } + } + + /** + * Thrown when the argument is of the wrong type. + */ + public static class Type extends BadListenerArgumentsException { + + /** + * The public constructor. + * @param clazz the fully-qualified name of the parent class + * @param method the annotated listener method + * @param parameterName the name of the parameter + */ + public Type(String clazz, String method, String parameterName) { + super(String.format( + "The parameter %s of %s::%s does not implement the IEvent interface!", + parameterName, clazz, method + )); + } + } +} diff --git a/src/main/java/ftbsc/geb/exceptions/MissingInterfaceException.java b/src/main/java/ftbsc/geb/exceptions/MissingInterfaceException.java new file mode 100644 index 0000000..e792729 --- /dev/null +++ b/src/main/java/ftbsc/geb/exceptions/MissingInterfaceException.java @@ -0,0 +1,17 @@ +package ftbsc.geb.exceptions; + +/** + * Thrown when a parent of a listener method does not implement the + * appropriate interface, + */ +public class MissingInterfaceException extends RuntimeException { + + /** + * The public constructor. + * @param clazz the fully-qualified name of the parent class + * @param method the annotated listener method + */ + public MissingInterfaceException(String clazz, String method) { + super(String.format("The parent of %s::%s does not implement the IListener interface!", clazz, method)); + } +} |