13
0
geforkt von Mirrors/Paper

[Bleeding] Added Enchantment and misc tests to ItemStack (de)serialization

By: Wesley Wolfe <weswolf@aol.com>
Dieser Commit ist enthalten in:
Bukkit/Spigot 2012-02-16 14:37:57 -06:00
Ursprung e106970af9
Commit 95dc319bed
2 geänderte Dateien mit 76 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,50 @@
package org.bukkit.configuration.file;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.inventory.ItemStack;
public class TestEnchantment extends Enchantment {
public static void registerEnchantments() {
Enchantment.registerEnchantment(new TestEnchantment(0, "DUMMY_0"));
Enchantment.registerEnchantment(new TestEnchantment(1, "DUMMY_1"));
Enchantment.registerEnchantment(new TestEnchantment(2, "DUMMY_2"));
Enchantment.registerEnchantment(new TestEnchantment(3, "DUMMY_3"));
Enchantment.registerEnchantment(new TestEnchantment(4, "DUMMY_4"));
Enchantment.registerEnchantment(new TestEnchantment(5, "DUMMY_5"));
}
private final String name;
private TestEnchantment(final int id, final String name) {
super(id);
this.name = name;
}
@Override
public String getName() {
return name;
}
@Override
public int getMaxLevel() {
return 5;
}
@Override
public int getStartLevel() {
return 1;
}
@Override
public EnchantmentTarget getItemTarget() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean canEnchantItem(ItemStack item) {
return true;
}
}

Datei anzeigen

@ -4,12 +4,17 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.*; import static org.junit.Assert.*;
public class YamlConfigurationTest extends FileConfigurationTest { public class YamlConfigurationTest extends FileConfigurationTest {
static {
TestEnchantment.registerEnchantments();
}
@Override @Override
public YamlConfiguration getConfig() { public YamlConfiguration getConfig() {
return new YamlConfiguration(); return new YamlConfiguration();
@ -67,6 +72,21 @@ public class YamlConfigurationTest extends FileConfigurationTest {
stacks.add(new ItemStack(1)); stacks.add(new ItemStack(1));
stacks.add(new ItemStack(2)); stacks.add(new ItemStack(2));
stacks.add(new ItemStack(3)); stacks.add(new ItemStack(3));
stacks.add(new ItemStack(4, 17));
stacks.add(new ItemStack(5, 63));
stacks.add(new ItemStack(6, 1, (short) 1));
stacks.add(new ItemStack(18, 32, (short) 2));
ItemStack item7 = new ItemStack(256);
item7.addEnchantment(Enchantment.getById(1), 1);
stacks.add(item7);
ItemStack item8 = new ItemStack(257);
item8.addEnchantment(Enchantment.getById(2), 2);
item8.addEnchantment(Enchantment.getById(3), 1);
item8.addEnchantment(Enchantment.getById(4), 5);
item8.addEnchantment(Enchantment.getById(5), 4);
stacks.add(item8);
out.set("composite-list.abc.def", stacks); out.set("composite-list.abc.def", stacks);
String yaml = out.saveToString(); String yaml = out.saveToString();
@ -79,5 +99,11 @@ public class YamlConfigurationTest extends FileConfigurationTest {
assertEquals(stacks.get(0), raw.get(0)); assertEquals(stacks.get(0), raw.get(0));
assertEquals(stacks.get(1), raw.get(1)); assertEquals(stacks.get(1), raw.get(1));
assertEquals(stacks.get(2), raw.get(2)); assertEquals(stacks.get(2), raw.get(2));
assertEquals(stacks.get(3), raw.get(3));
assertEquals(stacks.get(4), raw.get(4));
assertEquals(stacks.get(5), raw.get(5));
assertEquals(stacks.get(6), raw.get(6));
assertEquals(stacks.get(7), raw.get(7));
assertEquals(stacks.get(8), raw.get(8));
} }
} }