861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas/*
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas * The contents of this file are subject to the terms of the Common Development and
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas * Distribution License (the License). You may not use this file except in compliance with the
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas * License.
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas *
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas * specific language governing permission and limitations under the License.
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas *
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas * When distributing Covered Software, include this CDDL Header Notice in each file and include
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas * Header, with the fields enclosed by brackets [] replaced by your own identifying
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas * information: "Portions copyright [year] [name of copyright owner]".
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas *
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas * Copyright 2015 ForgeRock AS.
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas */
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomaspackage com.sun.identity.common;
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomasimport java.util.Set;
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomasimport org.forgerock.openam.utils.CollectionUtils;
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomasimport org.testng.annotations.Test;
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomasimport static org.fest.assertions.Assertions.*;
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomaspublic class CaseInsensitiveHashSetTest {
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas @Test
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas public void shouldRemoveTwoEntriesUsingHashSet() {
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas // Test removing elements using a standard HashSet
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas Set<String> setToRemove = CollectionUtils.asSet("inetuser", "iplanetpreferences", "three", "four", "five");
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas Set<String> setToInitialise = CollectionUtils.asSet("inetUser", "sunfederationmanagerdatastore",
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas "forgerock-am-dashboard-service", "iplanetpreferences");
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas Set<Object> ciHashSet = new CaseInsensitiveHashSet();
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas ciHashSet.addAll(setToInitialise);
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas ciHashSet.removeAll(setToRemove);
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas assertThat(ciHashSet).hasSize(2).contains("sunfederationmanagerdatastore", "forgerock-am-dashboard-service");
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas }
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas @Test
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas public void shouldRemoveTwoEntriesUsingciHashSet() {
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas // Test removing elements using a CaseInsensitiveHashSet
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas Set<String> ciSetToRemove = CollectionUtils.asCaseInsensitiveHashSet("inetuser", "iplanetpreferences", "three",
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas "four", "five");
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas Set<String> setToInitialise = CollectionUtils.asSet("inetUser", "sunfederationmanagerdatastore",
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas "forgerock-am-dashboard-service", "iplanetpreferences");
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas Set<Object> ciHashSet = new CaseInsensitiveHashSet();
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas ciHashSet.addAll(setToInitialise);
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas ciHashSet.removeAll(ciSetToRemove);
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas assertThat(ciHashSet).hasSize(2).contains("sunfederationmanagerdatastore", "forgerock-am-dashboard-service");
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas }
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas
861fc14ed1f9fd9538580a9137c266c2ec804a1eJon Jonthomas}