From 33bf68aaa56230d5601cdd180248b69ab17a0b69 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Mon, 20 May 2019 18:26:00 +0000 Subject: [PATCH] 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 --- .../PasswordSettingsValidatorTestCase.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 airsonic-main/src/test/java/org/airsonic/player/validator/PasswordSettingsValidatorTestCase.java diff --git a/airsonic-main/src/test/java/org/airsonic/player/validator/PasswordSettingsValidatorTestCase.java b/airsonic-main/src/test/java/org/airsonic/player/validator/PasswordSettingsValidatorTestCase.java new file mode 100644 index 00000000..70e678cb --- /dev/null +++ b/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()); + } +}