/* * Copyright 2014 Goldman Sachs. * * 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 com.gs.collections.impl.map.immutable; import com.gs.collections.api.map.ImmutableMap; import com.gs.collections.impl.math.IntegerSum; import com.gs.collections.impl.math.Sum; import com.gs.collections.impl.parallel.BatchIterable; import com.gs.collections.impl.tuple.Tuples; import org.junit.Assert; import org.junit.Test; public class ImmutableUnifiedMapTest extends ImmutableMapTestCase { @Override protected ImmutableMap<Integer, String> classUnderTest() { return new ImmutableUnifiedMap<>(Tuples.pair(1, "1"), Tuples.pair(2, "2"), Tuples.pair(3, "3"), Tuples.pair(4, "4")); } @Override protected int size() { return 4; } @Test @Override public void testToString() { Assert.assertEquals("{1=1, 2=2, 3=3, 4=4}", this.classUnderTest().toString()); } @Test public void getBatchCount() { BatchIterable<Integer> integerBatchIterable = (BatchIterable<Integer>) this.classUnderTest(); Assert.assertEquals(5, integerBatchIterable.getBatchCount(3)); } @Test public void batchForEach() { Sum sum = new IntegerSum(0); BatchIterable<String> integerBatchIterable = (BatchIterable<String>) this.classUnderTest(); integerBatchIterable.batchForEach(each -> sum.add(Integer.valueOf(each)), 0, 1); Assert.assertEquals(10, sum.getValue()); } }