/*
 *      Copyright 2018 The original authors.
 *
 *      Licensed under the Apache License, Version 2.0 (the "License");
 *      you may not use this file except in compliance with the License.
 *      You may obtain a copy of the License at
 *
 *          http://www.apache.org/licenses/LICENSE-2.0
 *
 *      Unless required by applicable law or agreed to in writing, software
 *      distributed under the License is distributed on an "AS IS" BASIS,
 *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *      See the License for the specific language governing permissions and
 *      limitations under the License.
 */

package io.sundr.examples.codegen;

import org.junit.Test;

import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.*;

public class MapTest {

    private final AttributeKey key1 = new AttributeKey("key1", String.class);
    private final AttributeKey key2 = new AttributeKey("key2", String.class);


    @Test
    public void testWithMap() {
        Map<AttributeKey, Object> map = new HashMap<>();

        map.put(key1, "value1");
        map.put(key2, "value2");
        AttributeSupport attributeSupport = new AttributeSupportBuilder()
                .withAttributes(map)
                .build();

        assertEquals("value1", attributeSupport.getAttributes().get(key1));
        assertEquals("value2", attributeSupport.getAttributes().get(key2));
    }

    @Test
    public void testAddToMap() {
        AttributeSupport attributeSupport = new AttributeSupportBuilder()
                .addToAttributes(key1, "value1")
                .addToAttributes(key2, "value2")
                .build();

        assertEquals("value1", attributeSupport.getAttributes().get(key1));
        assertEquals("value2", attributeSupport.getAttributes().get(key2));
    }

    @Test
    public void testRemoveFromMap() {
        AttributeSupport attributeSupport = new AttributeSupportBuilder()
                .removeFromAttributes(key1)
                .build();

        assertNull(attributeSupport.getAttributes());
    }

    @Test
    public void testRemoveMapFromMap() {
        Map<AttributeKey, Object> map = new HashMap<>();

        map.put(key1, "value1");
        map.put(key2, "value2");
        AttributeSupport attributeSupport = new AttributeSupportBuilder()
                .removeFromAttributes(map)
                .build();

        assertNull(attributeSupport.getAttributes());
    }
}

@@ -709,16 +709,46 @@
 .Test;%0A%0A
+import java.util.Collections;%0A
 import j
@@ -2067,36 +2067,38 @@
 %0A%0A        assert
-Null
+Equals
 (attributeSuppor
@@ -2106,32 +2106,56 @@
 .getAttributes()
+, Collections.emptyMap()
 );%0A    %7D%0A%0A    @T
@@ -2485,12 +2485,14 @@
 sert
-Null
+Equals
 (att
@@ -2520,16 +2520,40 @@
 ibutes()
+, Collections.emptyMap()
 );%0A    %7D

align tests.