/*
 *  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.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.time.Duration;

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


public class DefaultCounterTest {

    private static final String BRAZIL = "Brazil";
    private static final String USA = "USA";
    private static final String ENGLAND = "England";

    private RedisBucketManagerFactory keyValueEntityManagerFactory;
    private Counter counter;

    @BeforeEach
    public void init() {
        keyValueEntityManagerFactory = RedisTestUtils.get();
        counter = keyValueEntityManagerFactory.getCounter("counter-redis");
        counter.delete();
    }

    @Test
    public void shouldIncrement() {
        assertEquals(1D, counter.increment());
        assertEquals(10D, counter.increment(9));
    }

    @Test
    public void shouldDecrement() {
        counter.increment(10.15);
        assertEquals(9.15D, counter.decrement());
        assertEquals(0.15D, counter.decrement(9));
    }

    @Test
    public void shouldGet() {
        counter.increment(10.15);
        assertEquals(10.15D, counter.get().doubleValue());
    }

    @Test
    public void shouldShouldExpires() throws InterruptedException {
        counter.increment(10.15);
        counter.expire(Duration.ofSeconds(1));
        Thread.sleep(2_000L);
        assertEquals(0D, counter.get().doubleValue());
    }

    @Test
    public void shouldPersist() throws InterruptedException {
        counter.increment(10.15);
        counter.expire(Duration.ofSeconds(1));
        counter.persist();
        Thread.sleep(2_000L);
        assertEquals(10.15D, counter.get().doubleValue());
    }

    @Test
    public void shouldDelete() {
        counter.increment(10.15);
        counter.delete();
        assertEquals(0D, counter.get().doubleValue());
    }
}
@@ -610,32 +610,39 @@
 is.key;%0A%0Aimport 
+static 
 org.junit.jupite
@@ -651,143 +651,176 @@
 api.
-BeforeEach;%0Aimport org.junit.jupiter.api.Test;%0A%0Aimport java.time.Duration;%0A%0Aimport static org.junit.jupiter.api.Assertions.assertEquals
+Assertions.assertEquals;%0A%0Aimport java.time.Duration;%0A%0Aimport org.junit.jupiter.api.AfterEach;%0Aimport org.junit.jupiter.api.BeforeEach;%0Aimport org.junit.jupiter.api.Test
 ;%0A%0A%0A
@@ -2481,9 +2481,167 @@
 ;%0A    %7D%0A
+%0A    @AfterEach%0A    public void removeCounter()%7B%0A        counter = keyValueEntityManagerFactory.getCounter(%22counter-redis%22);%0A        counter.delete();%0A    %7D%0A%0A
 %7D

Remove counter after test