/*
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you 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 org.apache.groovy.util.concurrentlinkedhashmap;

import org.junit.Test;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

public class ConcurrentLinkedHashMapTest {
    @Test
    public void computeIfAbsent() {
        ConcurrentLinkedHashMap m = new ConcurrentLinkedHashMap.Builder<>()
                .maximumWeightedCapacity(3)
                .build();

        assertEquals(1, m.computeIfAbsent("a", k -> 1));
        assertEquals(1, m.computeIfAbsent("a", k -> 2));

        assertEquals(1, m.get("a"));

        assertEquals(3, m.computeIfAbsent("b", k -> 3));
        assertEquals(4, m.computeIfAbsent("c", k -> 4));
        assertEquals(5, m.computeIfAbsent("d", k -> 5));
        assertEquals(5, m.computeIfAbsent("d", k -> 6));

        assertArrayEquals(new String[] {"b", "c", "d"}, m.keySet().toArray(new String[0]));
        assertArrayEquals(new Integer[] {3, 4, 5}, m.values().toArray(new Integer[0]));
    }

}
@@ -897,16 +897,61 @@
 .Test;%0A%0A
+import java.util.concurrent.CountDownLatch;%0A%0A
 import s
@@ -984,32 +984,32 @@
 ertArrayEquals;%0A
-
 import static or
@@ -1040,51 +1040,8 @@
 als;
-%0Aimport static org.junit.Assert.assertNull;
 %0A%0Apu
@@ -1843,9 +1843,1263 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void computeIfAbsentConcurrently() throws InterruptedException %7B%0A        final ConcurrentLinkedHashMap m = new ConcurrentLinkedHashMap.Builder%3C%3E()%0A                .maximumWeightedCapacity(3)%0A                .build();%0A%0A        final int threadNum = 20;%0A        final CountDownLatch countDownLatch = new CountDownLatch(1);%0A        final CountDownLatch countDownLatch2 = new CountDownLatch(threadNum);%0A%0A        for (int i = 0; i %3C threadNum; i++) %7B%0A            final int num = i;%0A            new Thread(() -%3E %7B%0A                try %7B%0A                    countDownLatch.await();%0A%0A                    if (num != 0 && num != 1 && num != 2) %7B%0A                        Thread.sleep(500);%0A                    %7D%0A%0A                    m.computeIfAbsent(num %25 3, k -%3E num);%0A                %7D catch (InterruptedException e) %7B%0A                    e.printStackTrace();%0A                %7D finally %7B%0A                    countDownLatch2.countDown();%0A                %7D%0A            %7D).start();%0A        %7D%0A%0A        countDownLatch.countDown();%0A        countDownLatch2.await();%0A%0A        assertArrayEquals(new Integer%5B%5D %7B0, 1, 2%7D, m.keySet().toArray(new Integer%5B0%5D));%0A        assertArrayEquals(new Integer%5B%5D %7B0, 1, 2%7D, m.values().toArray(new Integer%5B0%5D));%0A    %7D%0A
 %7D

Add `computeIfAbsentConcurrently` test for `ConcurrentLinkedHashMap`