aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/junitparams/converters/Converter.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/junitparams/converters/Converter.java')
-rw-r--r--src/main/java/junitparams/converters/Converter.java26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/main/java/junitparams/converters/Converter.java b/src/main/java/junitparams/converters/Converter.java
new file mode 100644
index 0000000..1ef9c1b
--- /dev/null
+++ b/src/main/java/junitparams/converters/Converter.java
@@ -0,0 +1,26 @@
+package junitparams.converters;
+
+import java.lang.annotation.Annotation;
+
+/**
+ * Defines the logic to convert parameter annotated with A to type T. Converter must have a public no-args constructor. Configuration is
+ * done via {@link Converter#initialize(java.lang.annotation.Annotation)} method<br>
+ * Inspired by javax.validation.ConstraintValidator
+ *
+ * @param <A> type of annotation mentioning this converter
+ * @param <T> conversion target type
+ */
+public interface Converter<A extends Annotation, T> {
+
+ /**
+ * Initializes this converter - you can read your annotation config here.
+ */
+ void initialize(A annotation);
+
+ /**
+ * Converts param to desired type.
+ *
+ * @throws ConversionFailedException
+ */
+ T convert(Object param) throws ConversionFailedException;
+}