Your task is to implement a class called Validator
which will have two public static methods:
boolean isValid(Object o)
– determines if the argumento
is valid according to the rules described belowvoid validate(Object o)
– if the argumento
is not valid, then throwsValidationException
, otherwise does nothing
## Validation Classes are validated according to the annotations present on the fields. Example:
class C {
@MyAnnotation
Object field1;
}
Each annotation has a special meaning which represents specific constraint. These annotations will need to be created by you. Annotations to create:
-
@AssertFalse
– the field must be aboolean
with a value offalse
-
@AssertTrue
– the field must be aboolean
with a value oftrue
-
@Future
– the field must be aLocalDateTime
and the value must specify time in future -
@Ignored
– the field will not be validated. This annotation supersedes the importance of other annotations -
@NotBlank
– the field must be aString
with non-whitespace character -
@NotNull
– the field value cannot benull
-
@Null
– the fiel value must benull
-
@Pattern
– the field must be aString
which adheres to the regex specified inregex
attributeAttributes:
regex
– (String
) regex to which the value must adhere
-
@Size
– specifies the size of the value. Can be applied to multiple types which changes semantics a little. Allowed types:String
– length is evaluatedCollection
– collection size is evaluatedMap
– map size is evaluatedArray
– array length is evaluated
Attributes:
min
– (int
) specifies the minimum allowed value (included)max
– (int
) specifies the maximum allowed value (included)
Note: Every annotation will have one additional attribute message
(String
, ""
by default) which will be used in the validate
method which will pass the value to ValidationException
.
Once the implementation is complete, please write a bunch of unit tests to prove that your solution is working. You don't need to use testing framework (e.g. JUnit), you can just use one test class with main method which will call the "tests".