mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-15 04:05:50 -07:00
Clarify dye and wool color datas in DyeColor. Addresses BUKKIT-2786
DyeColor used the wool data for getData(), which is very misleading based on class name. The old method has been deprecated and replaced with getWoolData() and getDyeData() for the appropriate types of data values. The MaterialData classes Dye and Wool were updated appropriately, especially Dye innapropriately using a DyeColor data value compensation. Unit tests were added for the new methods, as well as the getColor on Dye and Wool. By: Wesley Wolfe <weswolf@aol.com>
This commit is contained in:
@@ -1,15 +1,70 @@
|
||||
package org.bukkit;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.material.Colorable;
|
||||
import org.bukkit.material.Dye;
|
||||
import org.bukkit.material.Wool;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameter;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class DyeColorTest {
|
||||
@Test
|
||||
public void getByData() {
|
||||
for (DyeColor dyeColor : DyeColor.values()) {
|
||||
assertThat(DyeColor.getByData(dyeColor.getData()), is(dyeColor));
|
||||
|
||||
@Parameters(name= "{index}: {0}")
|
||||
public static List<Object[]> data() {
|
||||
List<Object[]> list = new ArrayList<Object[]>();
|
||||
for (DyeColor dye : DyeColor.values()) {
|
||||
list.add(new Object[] {dye});
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Parameter public DyeColor dye;
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void getByData() {
|
||||
byte data = dye.getData();
|
||||
|
||||
DyeColor byData = DyeColor.getByData(data);
|
||||
assertThat(byData, is(dye));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getByWoolData() {
|
||||
byte data = dye.getWoolData();
|
||||
|
||||
DyeColor byData = DyeColor.getByWoolData(data);
|
||||
assertThat(byData, is(dye));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getByDyeData() {
|
||||
byte data = dye.getDyeData();
|
||||
|
||||
DyeColor byData = DyeColor.getByDyeData(data);
|
||||
assertThat(byData, is(dye));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDyeDyeColor() {
|
||||
testColorable(new Dye(Material.INK_SACK, dye.getDyeData()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWoolDyeColor() {
|
||||
testColorable(new Wool(Material.WOOL, dye.getWoolData()));
|
||||
}
|
||||
|
||||
private void testColorable(final Colorable colorable) {
|
||||
assertThat(colorable.getColor(), is(this.dye));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user