summaryrefslogtreecommitdiffstats
path: root/src/test/java/org/bukkit/MaterialTest.java
blob: 61c6871180da87f3d88a4f4f3fb3d2e838f421aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package org.bukkit;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;

import org.bukkit.material.MaterialData;
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() throws Throwable {
        for (Material material : Material.values()) {
            if (material.getClass().getField(material.name()).getAnnotation(Deprecated.class) != null) {
                continue;
            }
            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()));
        assertThat(Material.getMaterial(Integer.MIN_VALUE), is(nullValue()));
    }

    @Test
    public void getByNameNull() {
        assertThat(Material.getMaterial(null), is(nullValue()));
    }

    @Test
    public void getData() {
        for (Material material : Material.values()) {
            Class<? extends MaterialData> clazz = material.getData();

            assertThat(material.getNewData((byte) 0), is(instanceOf(clazz)));
        }
    }

    @Test(expected = IllegalArgumentException.class)
    public void matchMaterialByNull() {
        Material.matchMaterial(null);
    }

    @Test
    public void matchMaterialById() throws Throwable {
        for (Material material : Material.values()) {
            if (material.getClass().getField(material.name()).getAnnotation(Deprecated.class) != null) {
                continue;
            }
            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(java.util.Locale.ENGLISH);
            assertThat(Material.matchMaterial(name), is(material));
        }
    }
}