/*
 *  Copyright (c) 2017 Otávio Santana and others
 *   All rights reserved. This program and the accompanying materials
 *   are made available under the terms of the Eclipse Public License v1.0
 *   and Apache License v2.0 which accompanies this distribution.
 *   The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
 *   and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
 *
 *   You may elect to redistribute this code under either of these licenses.
 *
 *   Contributors:
 *
 *   Otavio Santana
 */

package org.jnosql.diana.redis.key;


import org.jnosql.diana.api.key.BucketManagerFactory;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertTrue;

public class RedisSetTest {


    private BucketManagerFactory keyValueEntityManagerFactory;
    private User userOtavioJava = new User("otaviojava");
    private User felipe = new User("ffrancesquini");
    private Set<User> users;

    @BeforeEach
    public void init() {
        keyValueEntityManagerFactory = RedisTestUtils.get();
        users = keyValueEntityManagerFactory.getSet("social-media", User.class);
    }

    @Test
    public void shouldAddUsers() {
        assertTrue(users.isEmpty());
        users.add(userOtavioJava);
        assertTrue(users.size() == 1);

        users.remove(userOtavioJava);
        assertTrue(users.isEmpty());
    }


    @SuppressWarnings("unused")
    @Test
    public void shouldIterate() {

        users.add(userOtavioJava);
        users.add(userOtavioJava);
        users.add(felipe);
        users.add(userOtavioJava);
        users.add(felipe);
        int count = 0;
        for (User user : users) {
            count++;
        }
        assertTrue(count == 2);
        users.remove(userOtavioJava);
        users.remove(felipe);
        count = 0;
        for (User user : users) {
            count++;
        }
        assertTrue(count == 0);
    }

    @AfterEach
    public void dispose() {
        users.clear();
    }
}

@@ -803,24 +803,164 @@
 .util.Set;%0A%0A
+import static org.hamcrest.MatcherAssert.assertThat;%0Aimport static org.hamcrest.Matchers.contains;%0Aimport static org.hamcrest.Matchers.not;%0A
 import stati
@@ -1036,17 +1036,16 @@
 Test %7B%0A%0A
-%0A
     priv
@@ -1479,45 +1479,8 @@
 ) %7B%0A
-        assertTrue(users.isEmpty());%0A
     
@@ -1553,80 +1553,244 @@
 1);%0A
-%0A        users.remove(userOtavioJava);%0A        assertTrue(users.isEmpty(
+    %7D%0A%0A    @Test%0A    public void shouldRemove() %7B%0A        users.add(userOtavioJava);%0A        users.add(felipe);%0A        users.remove(felipe);%0A        %0A        assertTrue(users.size() == 1);%0A        assertThat(users, not(contains(felipe)
 ));%0A
@@ -1796,17 +1796,16 @@
 %0A    %7D%0A%0A
-%0A
     @Sup
@@ -1872,17 +1872,16 @@
 ate() %7B%0A
-%0A
         

remove remove() test fromm addUsers and create a new one