Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
MaterialTest.java
1 package org.bukkit;
2 
3 import static org.hamcrest.Matchers.*;
4 import static org.junit.Assert.*;
5 
7 import org.junit.Test;
8 
9 public class MaterialTest {
10  @Test
11  public void getByName() {
12  for (Material material : Material.values()) {
13  assertThat(Material.getMaterial(material.toString()), is(material));
14  }
15  }
16 
17  @Test
18  public void getById() throws Throwable {
19  for (Material material : Material.values()) {
20  if (material.getClass().getField(material.name()).getAnnotation(Deprecated.class) != null) {
21  continue;
22  }
23  assertThat(Material.getMaterial(material.getId()), is(material));
24  }
25  }
26 
27  @Test
28  public void isBlock() {
29  for (Material material : Material.values()) {
30  if (material.getId() > 255) continue;
31 
32  assertTrue(String.format("[%d] %s", material.getId(), material.toString()), material.isBlock());
33  }
34  }
35 
36  @Test
37  public void getByOutOfRangeId() {
38  assertThat(Material.getMaterial(Integer.MAX_VALUE), is(nullValue()));
39  assertThat(Material.getMaterial(Integer.MIN_VALUE), is(nullValue()));
40  }
41 
42  @Test
43  public void getByNameNull() {
44  assertThat(Material.getMaterial(null), is(nullValue()));
45  }
46 
47  @Test
48  public void getData() {
49  for (Material material : Material.values()) {
50  Class<? extends MaterialData> clazz = material.getData();
51 
52  assertThat(material.getNewData((byte) 0), is(instanceOf(clazz)));
53  }
54  }
55 
56  @Test(expected = IllegalArgumentException.class)
57  public void matchMaterialByNull() {
58  Material.matchMaterial(null);
59  }
60 
61  @Test
62  public void matchMaterialById() throws Throwable {
63  for (Material material : Material.values()) {
64  if (material.getClass().getField(material.name()).getAnnotation(Deprecated.class) != null) {
65  continue;
66  }
67  assertThat(Material.matchMaterial(String.valueOf(material.getId())), is(material));
68  }
69  }
70 
71  @Test
72  public void matchMaterialByName() {
73  for (Material material : Material.values()) {
74  assertThat(Material.matchMaterial(material.toString()), is(material));
75  }
76  }
77 
78  @Test
79  public void matchMaterialByLowerCaseAndSpaces() {
80  for (Material material : Material.values()) {
81  String name = material.toString().replaceAll("_", " ").toLowerCase();
82  assertThat(Material.matchMaterial(name), is(material));
83  }
84  }
85 }
static Material getMaterial(final int id)
Definition: Material.java:575
static Material matchMaterial(final String name)
Definition: Material.java:608