/* * 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.set.mutable; import java.util.Collections; import com.gs.collections.api.RichIterable; import com.gs.collections.api.bag.sorted.MutableSortedBag; import com.gs.collections.api.set.MutableSet; import com.gs.collections.impl.bag.sorted.mutable.TreeBag; import com.gs.collections.impl.collection.mutable.AbstractCollectionTestCase; import com.gs.collections.impl.test.Verify; import org.junit.Assert; import org.junit.Test; public class MultiReaderUnifiedSetAsWriteUntouchableTest extends AbstractCollectionTestCase { @Override protected <T> MutableSet<T> newWith(T... littleElements) { return MultiReaderUnifiedSet.newSetWith(littleElements).asWriteUntouchable(); } @Override public void getLast() { Assert.assertNotNull(this.newWith(1, 2, 3).getLast()); Assert.assertNull(this.newWith().getLast()); } @Override @Test public void makeString() { Assert.assertEquals("1, 2, 3", this.newWith(1, 2, 3).makeString()); } @Override @Test public void appendString() { Appendable builder = new StringBuilder(); this.newWith(1, 2, 3).appendString(builder); Assert.assertEquals("1, 2, 3", builder.toString()); } @Override @Test public void testToString() { Assert.assertEquals("[1, 2, 3]", this.newWith(1, 2, 3).toString()); } @Override @Test public void asSynchronized() { Verify.assertThrows(UnsupportedOperationException.class, () -> this.newWith().asSynchronized()); } @Override @Test public void asUnmodifiable() { Verify.assertThrows(UnsupportedOperationException.class, () -> this.newWith().asUnmodifiable()); } @Override @Test public void toSortedBag_natural_ordering() { RichIterable<Integer> integers = this.newWith(1, 2, 5, 3, 4); MutableSortedBag<Integer> bag = integers.toSortedBag(); Verify.assertSortedBagsEqual(TreeBag.newBagWith(1, 2, 3, 4, 5), bag); } @Override @Test public void toSortedBag_with_comparator() { RichIterable<Integer> integers = this.newWith(2, 4, 1, 3); MutableSortedBag<Integer> bag = integers.toSortedBag(Collections.<Integer>reverseOrder()); Verify.assertSortedBagsEqual(TreeBag.newBagWith(Collections.<Integer>reverseOrder(), 4, 3, 2, 1), bag); } @Override @Test(expected = NullPointerException.class) public void toSortedBag_with_null() { this.newWith(3, 4, null, 1, 2).toSortedBag(); } @Override @Test public void toSortedBagBy() { RichIterable<Integer> integers = this.newWith(2, 4, 1, 3); MutableSortedBag<Integer> bag = integers.toSortedBagBy(String::valueOf); Verify.assertSortedBagsEqual(TreeBag.newBagWith(1, 2, 3, 4), bag); } }