/**
 * Copyright (C) Posten Norge AS
 *
 * 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 no.digipost;

import no.digipost.util.AtMostOne;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

import static no.digipost.DiggMaps.*;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;

public class DiggMapsTest {

    @Test
    public void unMapBySettingValueOnKey() {
        Map<AtomicReference<String>, String> map = new HashMap<>();
        map.put(new AtomicReference<>(), "x");

        assertThat(AtMostOne.from(unMapToKeys(map, AtomicReference::set)).toOptional().get().get(), is("x"));
    }


    @Test
    public void unMapBySettingKeyOnValue() {
        Map<String, AtomicReference<String>> map = new HashMap<>();
        map.put("x", new AtomicReference<>());

        assertThat(AtMostOne.from(unMapToValues(map, AtomicReference::set)).toOptional().get().get(), is("x"));
    }

    @Test
    public void unMapUsingBiFunction() {
        Map<AtomicReference<String>, String> map = new HashMap<>();
        map.put(new AtomicReference<>(), "x");

        assertThat(AtMostOne.from(unMap(map, (k, v) -> k.updateAndGet(old -> v))).toOptional().get(), is("x"));
    }
}

@@ -622,43 +622,8 @@
 t;%0A%0A
-import no.digipost.util.AtMostOne;%0A
 impo
@@ -637,24 +637,24 @@
 junit.Test;%0A
+
 %0Aimport java
@@ -743,16 +743,73 @@
 rence;%0A%0A
+import static no.digipost.DiggCollectors.allowAtMostOne;%0A
 import s
@@ -1137,39 +1137,24 @@
  assertThat(
-AtMostOne.from(
 unMapToKeys(
@@ -1175,37 +1175,49 @@
 erence::set)
-).toOptional(
+.collect(allowAtMostOne()
 ).get().get(
@@ -1236,17 +1236,16 @@
 %0A    %7D%0A%0A
-%0A
     @Tes
@@ -1422,39 +1422,24 @@
  assertThat(
-AtMostOne.from(
 unMapToValue
@@ -1466,29 +1466,41 @@
 ce::set)
-).toOptional(
+.collect(allowAtMostOne()
 ).get().
@@ -1713,23 +1713,8 @@
 hat(
-AtMostOne.from(
 unMa
@@ -1759,21 +1759,33 @@
  v))
-).toOptional(
+.collect(allowAtMostOne()
 ).ge

Remove use of deprecated API in test