Search in sources :

Example 21 with DataContainer

use of org.spongepowered.api.data.DataContainer in project SpongeCommon by SpongePowered.

the class MemoryDataTest method testNumberedLists.

@Test
public void testNumberedLists() {
    DataContainer container = DataContainer.createNew();
    DataQuery testQuery = of("foo", "bar", "baz");
    List<Integer> intList = ImmutableList.of(1, 2, 3, 4);
    container.set(testQuery, intList);
    assertTrue(container.getIntegerList(testQuery).isPresent());
    assertTrue(container.getIntegerList(testQuery).get().equals(intList));
    List<Double> doubleList = ImmutableList.of(1.0D, 2.0D, 3.0D, 4.0D);
    container.set(testQuery, doubleList);
    assertTrue(container.getDoubleList(testQuery).isPresent());
    assertTrue(container.getDoubleList(testQuery).get().equals(doubleList));
    List<Short> shortList = ImmutableList.of((short) 1, (short) 2, (short) 3, (short) 4);
    container.set(testQuery, shortList);
    assertTrue(container.getShortList(testQuery).isPresent());
    assertTrue(container.getShortList(testQuery).get().equals(shortList));
    List<Byte> byteList = ImmutableList.of((byte) 1, (byte) 2, (byte) 3, (byte) 4);
    container.set(testQuery, byteList);
    assertTrue(container.getByteList(testQuery).isPresent());
    assertTrue(container.getByteList(testQuery).get().equals(byteList));
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer) DataQuery(org.spongepowered.api.data.DataQuery) Test(org.junit.Test)

Example 22 with DataContainer

use of org.spongepowered.api.data.DataContainer in project SpongeCommon by SpongePowered.

the class MemoryDataTest method testEmptyQuery.

@Test
public void testEmptyQuery() {
    DataContainer container = DataContainer.createNew();
    DataQuery query = of("");
    container.set(query, "foo");
    assertTrue(container.get(query).isPresent());
    assertTrue(container.get(query).get().equals("foo"));
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer) DataQuery(org.spongepowered.api.data.DataQuery) Test(org.junit.Test)

Example 23 with DataContainer

use of org.spongepowered.api.data.DataContainer in project SpongeCommon by SpongePowered.

the class MemoryDataTest method testBoolean.

@Test
public void testBoolean() {
    DataContainer container = DataContainer.createNew();
    DataQuery testQuery = of("foo", "bar");
    container.set(testQuery, false);
    Optional<Boolean> booleanOptional = container.getBoolean(testQuery);
    assertTrue(booleanOptional.isPresent());
    assertTrue(!booleanOptional.get());
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer) DataQuery(org.spongepowered.api.data.DataQuery) Test(org.junit.Test)

Example 24 with DataContainer

use of org.spongepowered.api.data.DataContainer in project SpongeCommon by SpongePowered.

the class MemoryDataTest method testIncorrectType.

@Test
public void testIncorrectType() {
    DataContainer container = DataContainer.createNew();
    DataQuery testQuery = of("foo", "bar");
    container.set(testQuery, "foo");
    Optional<Integer> optional = container.getInt(testQuery);
    assertTrue(!optional.isPresent());
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer) DataQuery(org.spongepowered.api.data.DataQuery) Test(org.junit.Test)

Example 25 with DataContainer

use of org.spongepowered.api.data.DataContainer in project SpongeCommon by SpongePowered.

the class MemoryDataTest method testSetData.

@Test
public void testSetData() {
    DataContainer container = DataContainer.createNew();
    DataQuery testQuery = of('.', "foo.bar");
    container.set(testQuery, 1);
    Optional<Integer> optional = container.getInt(testQuery);
    assertTrue(optional.isPresent());
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer) DataQuery(org.spongepowered.api.data.DataQuery) Test(org.junit.Test)

Aggregations

DataContainer (org.spongepowered.api.data.DataContainer)110 DataView (org.spongepowered.api.data.DataView)30 DataQuery (org.spongepowered.api.data.DataQuery)28 Test (org.junit.Test)24 List (java.util.List)15 Map (java.util.Map)15 ArrayList (java.util.ArrayList)13 Nullable (javax.annotation.Nullable)11 Collection (java.util.Collection)10 ImmutableList (com.google.common.collect.ImmutableList)9 ImmutableMap (com.google.common.collect.ImmutableMap)9 IOException (java.io.IOException)9 Path (java.nio.file.Path)9 Optional (java.util.Optional)9 CatalogType (org.spongepowered.api.CatalogType)9 Sponge (org.spongepowered.api.Sponge)8 Set (java.util.Set)7 Collectors (java.util.stream.Collectors)7 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)7 DataSerializable (org.spongepowered.api.data.DataSerializable)7