/*
 *  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.NoSuchElementException;
import java.util.Queue;

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

public class RedisQueueStringTest {


    private BucketManagerFactory keyValueEntityManagerFactory;

    private Queue<String> lineBank;

    @BeforeEach
    public void init() {

        keyValueEntityManagerFactory = RedisTestUtils.get();
        lineBank = keyValueEntityManagerFactory.getQueue("physical-bank-string", String.class);


    }

    @Test
    public void shouldPushInTheLine() {
        assertTrue(lineBank.add("Otavio"));
        assertTrue(lineBank.size() == 1);
        String otavio = lineBank.poll();
        assertEquals(otavio, "Otavio");
        assertNull(lineBank.poll());
        assertTrue(lineBank.isEmpty());
    }

    @Test
    public void shouldPeekInTheLine() {
        lineBank.add("Otavio");
        String otavio = lineBank.peek();
        assertNotNull(otavio);
        assertNotNull(lineBank.peek());
        String otavio2 = lineBank.remove();
        assertEquals(otavio, otavio2);
        boolean happendException = false;
        try {
            lineBank.remove();
        } catch (NoSuchElementException e) {
            happendException = true;
        }
        assertTrue(happendException);
    }

    @Test
    public void shouldElementInTheLine() {
        lineBank.add("Otavio");
        assertNotNull(lineBank.element());
        assertNotNull(lineBank.element());
        lineBank.remove("Otavio");
        boolean happendException = false;
        try {
            lineBank.element();
        } catch (NoSuchElementException e) {
            happendException = true;
        }
        assertTrue(happendException);
    }

    @SuppressWarnings("unused")
    @Test
    public void shouldIterate() {
        lineBank.add("Otavio");
        lineBank.add("Gama");
        int count = 0;
        for (String line : lineBank) {
            count++;
        }
        assertTrue(count == 2);
        lineBank.remove();
        lineBank.remove();
        count = 0;
        for (String line : lineBank) {
            count++;
        }
        assertTrue(count == 0);
    }

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

@@ -1081,17 +1081,16 @@
 nit() %7B%0A
-%0A
         
@@ -1238,18 +1238,16 @@
 class);%0A
-%0A%0A
     %7D%0A%0A 
@@ -2919,24 +2919,171 @@
  0);%0A    %7D%0A%0A
+    @Test%0A    public void shouldClear() %7B%0A        lineBank.add(%22Otavio%22);%0A        lineBank.clear();%0A        assertTrue(lineBank.isEmpty());%0A    %7D%0A%0A
     @AfterEa

add clear method test on map