Blame view

src/test/java/fr/plil/sio/web/mvc/UserValidatorTest.java 1.18 KB
aa193b2b   Julien Iguchi-Cartigny   First version
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  package fr.plil.sio.web.mvc;
  
  import static org.junit.Assert.*;
  import org.junit.Before;
  import org.junit.Test;
  import org.springframework.validation.BeanPropertyBindingResult;
  import org.springframework.validation.Errors;
  
  public class UserValidatorTest {
  
      private User user;
      private UserValidator validator;
      private Errors results;
  
      @Before
      public void createInstances() {
          validator = new UserValidator();
          user = new User();
          user.setUsername("abc");
          user.setPassword("abc");
          results = new BeanPropertyBindingResult(user, "user");
      }
  
      @Test
      public void testSupports() {
          assertTrue(validator.supports(User.class));
      }
  
      @Test
      public void testValidateCorrect() {
          validator.validate(user,results);
          assertFalse(results.hasErrors());
      }
  
      @Test
      public void testValidatePasswordTooShort() {
          user.setPassword("ab");
          validator.validate(user,results);
          assertTrue(results.hasErrors());
      }
  
      @Test
      public void testValidateUsernameTooShort() {
          user.setUsername("ab");
          validator.validate(user,results);
          assertTrue(results.hasErrors());
      }
  }