2012-01-29 11:10:40 +01:00
|
|
|
package org.bukkit;
|
|
|
|
|
2012-11-17 11:13:58 -06:00
|
|
|
import static org.hamcrest.Matchers.*;
|
|
|
|
import static org.junit.Assert.*;
|
2012-01-29 11:10:40 +01:00
|
|
|
|
2012-11-17 11:13:58 -06:00
|
|
|
import org.bukkit.material.MaterialData;
|
2012-01-29 11:10:40 +01:00
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
public class MaterialTest {
|
|
|
|
@Test
|
|
|
|
public void getByName() {
|
|
|
|
for (Material material : Material.values()) {
|
|
|
|
assertThat(Material.getMaterial(material.toString()), is(material));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void getById() {
|
|
|
|
for (Material material : Material.values()) {
|
|
|
|
assertThat(Material.getMaterial(material.getId()), is(material));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void isBlock() {
|
|
|
|
for (Material material : Material.values()) {
|
|
|
|
if (material.getId() > 255) continue;
|
|
|
|
|
|
|
|
assertTrue(String.format("[%d] %s", material.getId(), material.toString()), material.isBlock());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void getByOutOfRangeId() {
|
|
|
|
assertThat(Material.getMaterial(Integer.MAX_VALUE), is(nullValue()));
|
2013-01-11 02:07:38 +01:00
|
|
|
assertThat(Material.getMaterial(Integer.MIN_VALUE), is(nullValue()));
|
2012-01-29 11:10:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void getByNameNull() {
|
|
|
|
assertThat(Material.getMaterial(null), is(nullValue()));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void getData() {
|
|
|
|
for (Material material : Material.values()) {
|
2012-11-17 11:13:58 -06:00
|
|
|
Class<? extends MaterialData> clazz = material.getData();
|
2012-01-29 11:10:40 +01:00
|
|
|
|
2012-11-17 11:13:58 -06:00
|
|
|
assertThat(material.getNewData((byte) 0), is(instanceOf(clazz)));
|
2012-01-29 11:10:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = IllegalArgumentException.class)
|
|
|
|
public void matchMaterialByNull() {
|
|
|
|
Material.matchMaterial(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void matchMaterialById() {
|
|
|
|
for (Material material : Material.values()) {
|
|
|
|
assertThat(Material.matchMaterial(String.valueOf(material.getId())), is(material));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void matchMaterialByName() {
|
|
|
|
for (Material material : Material.values()) {
|
|
|
|
assertThat(Material.matchMaterial(material.toString()), is(material));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void matchMaterialByLowerCaseAndSpaces() {
|
|
|
|
for (Material material : Material.values()) {
|
|
|
|
String name = material.toString().replaceAll("_", " ").toLowerCase();
|
|
|
|
assertThat(Material.matchMaterial(name), is(material));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|