Search in sources :

Example 1 with PersistedIntegerArray

use of org.terasology.persistence.typeHandling.inMemory.arrays.PersistedIntegerArray in project Terasology by MovingBlocks.

the class ArrayTypeHandlerTest method testDeserialize.

@Test
void testDeserialize() {
    IntTypeHandler elementTypeHandler = mock(IntTypeHandler.class);
    ArrayTypeHandler<Integer> typeHandler = new ArrayTypeHandler<>(elementTypeHandler, TypeInfo.of(Integer.class));
    TIntList intList = new TIntArrayList(ARRAY_SIZE);
    for (Integer i : Collections.nCopies(ARRAY_SIZE, -1)) {
        intList.add(i);
    }
    typeHandler.deserialize(new PersistedIntegerArray(intList));
    verify(elementTypeHandler, times(intList.size())).deserialize(any());
}
Also used : TIntList(gnu.trove.list.TIntList) TIntArrayList(gnu.trove.list.array.TIntArrayList) PersistedIntegerArray(org.terasology.persistence.typeHandling.inMemory.arrays.PersistedIntegerArray) Test(org.junit.jupiter.api.Test)

Example 2 with PersistedIntegerArray

use of org.terasology.persistence.typeHandling.inMemory.arrays.PersistedIntegerArray in project Terasology by MovingBlocks.

the class CollectionTypeHandlerTest method testDeserialize.

@Test
void testDeserialize() {
    IntTypeHandler elementTypeHandler = mock(IntTypeHandler.class);
    CollectionCopyConstructor<Collection<Integer>, Integer> constructor = mock(CollectionCopyConstructor.class);
    when(constructor.construct(Lists.newArrayList())).then((Answer<Collection<Integer>>) invocation -> Queues.newArrayDeque());
    CollectionTypeHandler<Integer> typeHandler = new CollectionTypeHandler<>(elementTypeHandler, constructor);
    TIntList intList = new TIntArrayList();
    for (Integer i : Collections.nCopies(500, -1)) {
        intList.add(i);
    }
    typeHandler.deserialize(new PersistedIntegerArray(intList));
    verify(constructor).construct(Lists.newArrayList());
    verify(elementTypeHandler, times(intList.size())).deserialize(any());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) TIntList(gnu.trove.list.TIntList) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Collection(java.util.Collection) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) PersistedData(org.terasology.persistence.typeHandling.PersistedData) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) ArgumentMatcher(org.mockito.ArgumentMatcher) Answer(org.mockito.stubbing.Answer) Queues(com.google.common.collect.Queues) Lists(com.google.common.collect.Lists) PersistedDataSerializer(org.terasology.persistence.typeHandling.PersistedDataSerializer) CollectionCopyConstructor(org.terasology.reflection.reflect.CollectionCopyConstructor) Queue(java.util.Queue) Collections(java.util.Collections) PersistedIntegerArray(org.terasology.persistence.typeHandling.inMemory.arrays.PersistedIntegerArray) Mockito.mock(org.mockito.Mockito.mock) Collection(java.util.Collection) TIntList(gnu.trove.list.TIntList) TIntArrayList(gnu.trove.list.array.TIntArrayList) PersistedIntegerArray(org.terasology.persistence.typeHandling.inMemory.arrays.PersistedIntegerArray) Test(org.junit.jupiter.api.Test)

Aggregations

TIntList (gnu.trove.list.TIntList)2 TIntArrayList (gnu.trove.list.array.TIntArrayList)2 Test (org.junit.jupiter.api.Test)2 PersistedIntegerArray (org.terasology.persistence.typeHandling.inMemory.arrays.PersistedIntegerArray)2 Lists (com.google.common.collect.Lists)1 Queues (com.google.common.collect.Queues)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Queue (java.util.Queue)1 ArgumentMatcher (org.mockito.ArgumentMatcher)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.times (org.mockito.Mockito.times)1 Mockito.verify (org.mockito.Mockito.verify)1 Mockito.when (org.mockito.Mockito.when)1 Answer (org.mockito.stubbing.Answer)1 PersistedData (org.terasology.persistence.typeHandling.PersistedData)1 PersistedDataSerializer (org.terasology.persistence.typeHandling.PersistedDataSerializer)1 CollectionCopyConstructor (org.terasology.reflection.reflect.CollectionCopyConstructor)1