mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-23 18:55:22 +01:00
Make BoundedArrayList follow the old behavior.
Unit tests have been included.
This commit is contained in:
parent
aa214c0b54
commit
a1895c556f
@ -16,7 +16,7 @@ public class BoundedArrayList<E> extends ArrayList<E>
|
||||
|
||||
private void checkSize(int increment)
|
||||
{
|
||||
Preconditions.checkState( size() + increment < maxSize, "Adding %s elements would exceed capacity of %s", increment, maxSize );
|
||||
Preconditions.checkState( size() + increment <= maxSize, "Adding %s elements would exceed capacity of %s", increment, maxSize );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,77 @@
|
||||
package net.md_5.bungee.util;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class BoundedArrayListTest {
|
||||
|
||||
@Test
|
||||
public void testGoodAdd() throws Exception
|
||||
{
|
||||
BoundedArrayList<Object> list = new BoundedArrayList<>( 2 );
|
||||
list.add( new Object() );
|
||||
list.add( new Object() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSizeOneAdd() throws Exception
|
||||
{
|
||||
BoundedArrayList<Object> list = new BoundedArrayList<>( 1 );
|
||||
list.add( new Object() );
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testBadAdd() throws Exception
|
||||
{
|
||||
BoundedArrayList<Object> list = new BoundedArrayList<>( 0 );
|
||||
list.add( new Object() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGoodAdd1() throws Exception
|
||||
{
|
||||
BoundedArrayList<Object> list = new BoundedArrayList<>( 2 );
|
||||
list.add( new Object() );
|
||||
list.add( 0, new Object() );
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testBadAdd1() throws Exception
|
||||
{
|
||||
BoundedArrayList<Object> list = new BoundedArrayList<>( 1 );
|
||||
list.add( new Object() );
|
||||
list.add( 0, new Object() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGoodAddAll() throws Exception
|
||||
{
|
||||
BoundedArrayList<Object> list = new BoundedArrayList<>( 1 );
|
||||
list.addAll( ImmutableList.of( new Object() ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGoodAddAll1() throws Exception
|
||||
{
|
||||
BoundedArrayList<Object> list = new BoundedArrayList<>( 2 );
|
||||
list.add( new Object() );
|
||||
list.addAll( 0, ImmutableList.of( new Object() ) );
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testBadAddAll() throws Exception
|
||||
{
|
||||
BoundedArrayList<Object> list = new BoundedArrayList<>(0);
|
||||
list.addAll( ImmutableList.of( new Object() ) );
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testBadAddAll1() throws Exception
|
||||
{
|
||||
BoundedArrayList<Object> list = new BoundedArrayList<>( 1 );
|
||||
list.add( new Object() );
|
||||
list.addAll( ImmutableList.of( new Object() ) );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user