f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna/*
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna* The contents of this file are subject to the terms of the Common Development and
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna* Distribution License (the License). You may not use this file except in compliance with the
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna* License.
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna*
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna* specific language governing permission and limitations under the License.
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna*
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna* When distributing Covered Software, include this CDDL Header Notice in each file and include
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna* Header, with the fields enclosed by brackets [] replaced by your own identifying
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna* information: "Portions copyright [year] [name of copyright owner]".
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna*
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna* Copyright 2016 ForgeRock AS.
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna*/
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Lunapackage com.sun.identity.sm;
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Lunaimport static org.assertj.core.api.Assertions.*;
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Lunaimport java.util.Collections;
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Lunaimport java.util.HashSet;
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Lunaimport org.testng.annotations.Test;
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Lunapublic class RequiredValueValidatorTest {
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna private final RequiredValueValidator validator = new RequiredValueValidator();
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna @Test
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna public void checkReturnFalseIfEmptySet() {
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna //given
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna //when
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna boolean result = validator.validate(Collections.<String>emptySet());
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna //then
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna assertThat(result).isEqualTo(false);
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna }
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna @Test
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna public void checkReturnFalseIfEmptyStringInSet() {
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna //given
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna //when
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna boolean result = validator.validate(Collections.singleton(""));
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna //then
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna assertThat(result).isEqualTo(false);
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna }
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna @Test
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna public void checkReturnTrueIfBlankStringInSet() {
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna //given
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna //when
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna boolean result = validator.validate(Collections.singleton(" "));
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna //then
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna assertThat(result).isEqualTo(true);
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna }
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna @Test
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna public void checkReturnTrueIfSetValid() {
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna //given
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna HashSet<String> set = new HashSet<>();
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna set.add("one");
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna set.add("two");
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna set.add("three");
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna set.add("four");
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna //when
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna boolean result = validator.validate(set);
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna //then
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna assertThat(result).isEqualTo(true);
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna }
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna @Test
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna public void checkReturnFalseIfSetInvalid() {
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna //given
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna HashSet<String> set = new HashSet<>();
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna set.add("one");
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna set.add("two");
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna set.add("three");
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna set.add("");
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna //when
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna boolean result = validator.validate(set);
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna //then
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna assertThat(result).isEqualTo(false);
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna }
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna}