Add a password settings testcase (#1058)

* Add a simple testcase

This commit was done to understand how JUnit
and its friends are working. Expect more useful tests
in the future ;)

* Factorise a bit the tests
master
jvoisin 5 years ago committed by Jonas L
parent 27ee009b69
commit 33bf68aaa5
  1. 46
      airsonic-main/src/test/java/org/airsonic/player/validator/PasswordSettingsValidatorTestCase.java

@ -0,0 +1,46 @@
package org.airsonic.player.validator;
import junit.framework.TestCase;
import org.airsonic.player.command.PasswordSettingsCommand;
import org.junit.Before;
import org.springframework.validation.BeanPropertyBindingResult;
import org.springframework.validation.Errors;
public class PasswordSettingsValidatorTestCase extends TestCase {
private PasswordSettingsCommand psc;
@Before
public void setUp() throws Exception {
psc = new PasswordSettingsCommand();
psc.setUsername("username");
psc.setPassword("1234");
}
private Errors validatePassword(){
PasswordSettingsValidator psv = new PasswordSettingsValidator();
Errors errors = new BeanPropertyBindingResult(psc, "psv");
psv.validate(psc, errors);
return errors;
}
public void testValidateEmptyPassword() {
psc.setPassword("");
Errors errors = this.validatePassword();
assertTrue(errors.hasErrors());
}
public void testValidateDifferentPasswords() {
psc.setConfirmPassword("5678");
Errors errors = this.validatePassword();
assertTrue(errors.hasErrors());
}
public void testValidateEverythingOK() {
psc.setConfirmPassword("1234");
Errors errors = this.validatePassword();
assertFalse(errors.hasErrors());
}
}
Loading…
Cancel
Save