Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. public class FrameworkTest {
  2.  
  3.  
  4. @Mock
  5. private ConstrainValidatorContext context;
  6. private LengthValidator validator = new LengthValidator():
  7.  
  8. @Test
  9. public void okRange() throws NoSuchFieldException {
  10. Length anno1 = MyClass1.class.getDeclaredField("name").getAnnotation(Length.class)
  11.  
  12. validator.initialize(anno1);
  13.  
  14. assertTrue(validator.isValid("RIKARD", context).isEmpty());
  15. }
  16.  
  17. @Test(expected = IllegalMinValue.class)
  18. public void wrongOrder() throws NoSuchFieldException {
  19. Length length = MyClass1.class.getDeclaredField("name").getAnnotation(Length.class)
  20.  
  21. validator.initialize(length);
  22. }
  23.  
  24. @Test(expected = IllegalRangeException.class)
  25. public void illegalMin() throws NoSuchFieldException {
  26. Length length = MyClass1.class.getDeclaredField("illegal").getAnnotation(Length.class)
  27.  
  28. validator.initialize(length);
  29. }
  30.  
  31.  
  32. private static class MyClass1 {
  33. @Length(min = 1, max = 6)
  34. private String name;
  35.  
  36. @Length(min = 5, max = 1)
  37. private String wrong;
  38.  
  39. @Length(min = -100)
  40. private String illegal;
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement