/* * Copyright 2015 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.test.map.mutable; import java.util.Collection; import java.util.Iterator; import java.util.Random; import java.util.Set; import com.gs.collections.api.map.MutableMap; import com.gs.collections.impl.map.mutable.UnifiedMap; import com.gs.collections.test.NoIteratorTestCase; import com.gs.junit.runners.Java8Runner; import org.junit.Assert; import org.junit.runner.RunWith; @RunWith(Java8Runner.class) public class UnifiedMapNoIteratorTest implements MutableMapTestCase, NoIteratorTestCase { private static final long CURRENT_TIME_MILLIS = System.currentTimeMillis(); @SafeVarargs @Override public final <T> MutableMap<Object, T> newWith(T... elements) { Random random = new Random(CURRENT_TIME_MILLIS); MutableMap<Object, T> result = new UnifiedMapNoIterator<>(); for (T each : elements) { Assert.assertNull(result.put(random.nextDouble(), each)); } return result; } @Override public void Iterable_next() { NoIteratorTestCase.super.Iterable_next(); } @Override public void Iterable_remove() { NoIteratorTestCase.super.Iterable_remove(); } @Override public void RichIterable_getFirst() { NoIteratorTestCase.super.RichIterable_getFirst(); } @Override public void RichIterable_getLast() { NoIteratorTestCase.super.RichIterable_getLast(); } @Override public void RichIterable_getFirst_and_getLast() { // Not applicable } @Override public void RichIterable_getLast_empty_null() { // Not applicable } public static class UnifiedMapNoIterator<K, V> extends UnifiedMap<K, V> { @Override public Iterator<V> iterator() { throw new AssertionError("No iteration patterns should delegate to iterator()"); } @Override public Set<Entry<K, V>> entrySet() { return new EntrySetNoIterator(); } @Override public Set<K> keySet() { return new KeySetNoIterator(); } @Override public Collection<V> values() { return new ValuesCollectionNoIterator(); } public class EntrySetNoIterator extends EntrySet { @Override public Iterator<Entry<K, V>> iterator() { throw new AssertionError("No iteration patterns should delegate to iterator()"); } } public class KeySetNoIterator extends KeySet { @Override public Iterator<K> iterator() { throw new AssertionError("No iteration patterns should delegate to iterator()"); } } public class ValuesCollectionNoIterator extends ValuesCollection { @Override public Iterator<V> iterator() { throw new AssertionError("No iteration patterns should delegate to iterator()"); } } } }