Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class FrameworkTest {
- @Mock
- private ConstrainValidatorContext context;
- private LengthValidator validator = new LengthValidator():
- @Test
- public void okRange() throws NoSuchFieldException {
- Length anno1 = MyClass1.class.getDeclaredField("name").getAnnotation(Length.class)
- validator.initialize(anno1);
- assertTrue(validator.isValid("RIKARD", context).isEmpty());
- }
- @Test(expected = IllegalMinValue.class)
- public void wrongOrder() throws NoSuchFieldException {
- Length length = MyClass1.class.getDeclaredField("name").getAnnotation(Length.class)
- validator.initialize(length);
- }
- @Test(expected = IllegalRangeException.class)
- public void illegalMin() throws NoSuchFieldException {
- Length length = MyClass1.class.getDeclaredField("illegal").getAnnotation(Length.class)
- validator.initialize(length);
- }
- private static class MyClass1 {
- @Length(min = 1, max = 6)
- private String name;
- @Length(min = 5, max = 1)
- private String wrong;
- @Length(min = -100)
- private String illegal;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement