package at.gv.egiz.eaaf.core.impl.idp.auth.data; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import org.apache.commons.lang3.RandomStringUtils; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.BlockJUnit4ClassRunner; import at.gv.egiz.eaaf.core.impl.idp.AuthenticationData; @RunWith(BlockJUnit4ClassRunner.class) public class AuthenticationDataTest { @Test public void formatedDateButNotSet() { AuthenticationData authData = new AuthenticationData(); assertNull("formatedDateOfBirth", authData.getDateOfBirthFormated("dd/MM/yyy")); } @Test public void formatedDateButInvalidPattern() { AuthenticationData authData = new AuthenticationData(); authData.setDateOfBirth("1940-01-01"); assertNull("formatedDateOfBirth", authData.getDateOfBirthFormated("aa-bb-cccc")); } @Test public void validDateStatic() { AuthenticationData authData = new AuthenticationData(); String date = "1940-01-01"; authData.setDateOfBirth(date); assertNotNull("birthday", authData.getDateOfBirth()); assertEquals("birthday attribute", date, authData.getDateOfBirth()); assertEquals("birthday attribute", "01/01/1940", authData.getDateOfBirthFormated("dd/MM/yyy")); } @Test public void validButNotUsal() { AuthenticationData authData = new AuthenticationData(); authData.setDateOfBirth("1970-00-00"); assertNotNull("birthday", authData.getDateOfBirth()); assertEquals("birthday attribute", "1970-00-00", authData.getDateOfBirth()); assertNull("formatedDateOfBirth", authData.getDateOfBirthFormated("dd/MM/yyy")); } @Test public void invalidDate() { AuthenticationData authData = new AuthenticationData(); authData.setDateOfBirth("1970/00/00"); assertNull("birthday", authData.getDateOfBirth()); assertNull("formatedDateOfBirth", authData.getDateOfBirthFormated("dd/MM/yyy")); } @Test public void validDateRandom() { AuthenticationData authData = new AuthenticationData(); String date = RandomStringUtils.randomNumeric(4) + "-" + RandomStringUtils.randomNumeric(2) + "-" + RandomStringUtils.randomNumeric(2); authData.setDateOfBirth(date); assertNotNull("birthday", authData.getDateOfBirth()); assertEquals("birthday attribute", date, authData.getDateOfBirth()); } }