/*
* Copyright 2013 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.primitive;
import com.gs.collections.api.iterator.MutableBooleanIterator;
import com.gs.collections.api.set.primitive.MutableBooleanSet;
import com.gs.collections.impl.list.mutable.primitive.BooleanArrayList;
import com.gs.collections.impl.test.Verify;
import org.junit.Assert;
import org.junit.Test;
/**
* JUnit test for {@link UnmodifiableBooleanSet}.
*/
public class UnmodifiableBooleanSetTest extends AbstractBooleanSetTestCase
{
@Override
protected final UnmodifiableBooleanSet classUnderTest()
{
return new UnmodifiableBooleanSet(BooleanHashSet.newSetWith(true, false, true));
}
@Override
protected UnmodifiableBooleanSet newWith(boolean... elements)
{
return new UnmodifiableBooleanSet(BooleanHashSet.newSetWith(elements));
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void clear()
{
this.classUnderTest().clear();
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void add()
{
this.newWith().add(true);
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void addAllArray()
{
this.classUnderTest().addAll(true, false, true);
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void addAllIterable()
{
this.classUnderTest().addAll(this.newMutableCollectionWith());
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void remove()
{
this.classUnderTest().remove(false);
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void removeAll()
{
this.classUnderTest().removeAll(true, false);
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void removeAll_iterable()
{
this.classUnderTest().removeAll(this.newMutableCollectionWith());
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void retainAll()
{
this.classUnderTest().retainAll();
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void retainAll_iterable()
{
this.classUnderTest().retainAll(this.newMutableCollectionWith());
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void with()
{
this.newWith().with(true);
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void withAll()
{
this.newWith().withAll(this.newMutableCollectionWith(true));
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void without()
{
this.newWith(true, false, true, false, true).without(true);
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void withoutAll()
{
this.newWith(true, false, true, false, true).withoutAll(this.newMutableCollectionWith(false, false));
}
@Override
@Test
public void containsAllArray()
{
UnmodifiableBooleanSet collection = this.classUnderTest();
Assert.assertTrue(collection.containsAll(true));
Assert.assertTrue(collection.containsAll(true, false, true));
Assert.assertTrue(collection.containsAll(true, false));
Assert.assertTrue(collection.containsAll(true, true));
Assert.assertTrue(collection.containsAll(false, false));
UnmodifiableBooleanSet emptyCollection = this.newWith();
Assert.assertFalse(emptyCollection.containsAll(true));
Assert.assertFalse(emptyCollection.containsAll(false));
Assert.assertFalse(emptyCollection.containsAll(false, true, false));
Assert.assertFalse(this.newWith(true, true).containsAll(false, true, false));
UnmodifiableBooleanSet trueCollection = this.newWith(true, true, true, true);
Assert.assertFalse(trueCollection.containsAll(true, false));
UnmodifiableBooleanSet falseCollection = this.newWith(false, false, false, false);
Assert.assertFalse(falseCollection.containsAll(true, false));
}
@Override
@Test
public void containsAllIterable()
{
UnmodifiableBooleanSet emptyCollection = this.newWith();
Assert.assertTrue(emptyCollection.containsAll(new BooleanArrayList()));
Assert.assertFalse(emptyCollection.containsAll(BooleanArrayList.newListWith(true)));
Assert.assertFalse(emptyCollection.containsAll(BooleanArrayList.newListWith(false)));
UnmodifiableBooleanSet collection = this.newWith(true, true, false, false, false);
Assert.assertTrue(collection.containsAll(BooleanArrayList.newListWith(true)));
Assert.assertTrue(collection.containsAll(BooleanArrayList.newListWith(false)));
Assert.assertTrue(collection.containsAll(BooleanArrayList.newListWith(true, false)));
Assert.assertTrue(collection.containsAll(BooleanArrayList.newListWith(true, true)));
Assert.assertTrue(collection.containsAll(BooleanArrayList.newListWith(false, false)));
Assert.assertTrue(collection.containsAll(BooleanArrayList.newListWith(true, false, true)));
Assert.assertFalse(this.newWith(true, true).containsAll(BooleanArrayList.newListWith(false, true, false)));
UnmodifiableBooleanSet trueCollection = this.newWith(true, true, true, true);
Assert.assertFalse(trueCollection.containsAll(BooleanArrayList.newListWith(true, false)));
UnmodifiableBooleanSet falseCollection = this.newWith(false, false, false, false);
Assert.assertFalse(falseCollection.containsAll(BooleanArrayList.newListWith(true, false)));
}
@Override
@Test
public void asUnmodifiable()
{
super.asUnmodifiable();
MutableBooleanSet set = this.classUnderTest();
Assert.assertSame(set, set.asUnmodifiable());
Assert.assertEquals(set, set.asUnmodifiable());
}
@Override
@Test
public void booleanIterator_with_remove()
{
MutableBooleanIterator booleanIterator = this.classUnderTest().booleanIterator();
Assert.assertTrue(booleanIterator.hasNext());
booleanIterator.next();
Verify.assertThrows(UnsupportedOperationException.class, booleanIterator::remove);
}
@Override
@Test
public void iterator_throws_on_invocation_of_remove_before_next()
{
MutableBooleanIterator booleanIterator = this.classUnderTest().booleanIterator();
Assert.assertTrue(booleanIterator.hasNext());
Verify.assertThrows(UnsupportedOperationException.class, booleanIterator::remove);
}
@Override
@Test
public void iterator_throws_on_consecutive_invocation_of_remove()
{
// Not applicable for Unmodifiable*
}
}