Added Safty methods and test into IObjectArray to reduce crashes.

This commit is contained in:
2021-04-26 23:02:51 +02:00
parent a9a38f7853
commit d18324619c
4 changed files with 59 additions and 2 deletions
@@ -0,0 +1,33 @@
package speiger.src.collections.objects.list;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Assert;
import org.junit.Test;
import speiger.src.collections.objects.lists.ObjectArrayList;
import speiger.src.collections.objects.utils.IObjectArray;
@SuppressWarnings("javadoc")
public class ObjectArrayListTest
{
@Test
public void testCastable()
{
ObjectArrayList<String> list = new ObjectArrayList<>();
list.add("Test");
list.add("Testing");
list.add("Testing stuff");
testCastable(list, false);
testCastable(ObjectArrayList.wrap("Test", "Testing", "Testing stuff"), true);
}
public <T> void testCastable(IObjectArray<T> castable, boolean result)
{
Assert.assertTrue(castable.isCastable() == result);
AtomicInteger amount = new AtomicInteger();
castable.elements(T -> amount.set(T.length));
Assert.assertTrue(amount.get() > 0 == result);
}
}