/*
 *
 *  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.api;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.Collections;
import java.util.Map;

import static java.util.Collections.singletonMap;
import static org.hamcrest.Matchers.contains;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.hamcrest.MatcherAssert.assertThat;

public class DefaultSettingsTest {


    @Test
    public void shouldReturnNPEWhenInstanceIsNull() {
        Assertions.assertThrows(NullPointerException.class, () -> Settings.of((Map<String, Object>) null));

    }

    @Test
    public void shouldReturnNewInstance() {
        Settings settings = Settings.of();
        assertTrue(settings.isEmpty());
        assertEquals(0, settings.size());
    }

    @Test
    public void shouldCreatefromMap() {
        Settings settings = Settings.of(singletonMap("key", "value"));
        assertFalse(settings.isEmpty());
        assertEquals(1, settings.size());
        assertEquals("value", settings.get("key"));
    }

    @Test
    public void shouldContainsKeys() {
        Settings settings = Settings.of(singletonMap("key", "value"));
        assertTrue(settings.containsKey("key"));
        assertFalse(settings.containsKey("key2"));
    }


    @Test
    public void shouldGetKeys() {
        Settings settings = Settings.of(singletonMap("key", "value"));
        assertThat(settings.keySet(), contains("key"));
    }

    @Test
    public void shouldGetEntrySet() {
        Settings settings = Settings.of(singletonMap("key", "value"));
        assertEquals(settings.entrySet().stream().findFirst().get().getKey(), "key");
    }

    @Test
    public void shouldSize() {
        Settings settings = Settings.of(singletonMap("key", "value"));
        assertEquals(1, settings.size());
        settings = Settings.of(Collections.emptyMap());
        assertEquals(0, settings.size());
    }

    @Test
    public void shouldIsEmpty() {
        Settings settings = Settings.of(singletonMap("key", "value"));
        assertFalse(settings.isEmpty());
        settings = Settings.of(Collections.emptyMap());
        assertTrue(settings.isEmpty());
    }

    @Test
    public void shouldGetValueClass() {
        Settings settings = Settings.of(singletonMap("key", "12"));

        Integer value = settings.get("key", Integer.class);
        assertEquals(12, value);

        value = settings.get("key2", Integer.class);
        assertNull(value);
    }
}

@@ -688,16 +688,74 @@
 .Test;%0A%0A
+import java.util.AbstractMap;%0Aimport java.util.ArrayList;%0A
 import j
@@ -772,24 +772,47 @@
 ollections;%0A
+import java.util.List;%0A
 import java.
@@ -868,24 +868,77 @@
 ngletonMap;%0A
+import static org.hamcrest.MatcherAssert.assertThat;%0A
 import stati
@@ -1213,61 +1213,8 @@
 rue;
-%0Aimport static org.hamcrest.MatcherAssert.assertThat;
 %0A%0Apu
@@ -3311,11 +3311,534 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void shouldInterateUsingForEach() %7B%0A        Settings settings = Settings.of(singletonMap(%22key%22, %2212%22));%0A        List%3CMap.Entry%3CString, Object%3E%3E references = new ArrayList%3C%3E();%0A        settings.forEach((k, v) -%3E references.add(new AbstractMap.SimpleEntry%3C%3E(k, v)));%0A%0A        Assertions.assertFalse(references.isEmpty());%0A        Map.Entry%3CString, Object%3E entry = references.get(0);%0A        Assertions.assertEquals(%22key%22, entry.getKey());%0A        Assertions.assertEquals(%2212%22, entry.getValue());%0A%0A    %7D
 %0A%7D%0A

add a new test to settings