| @@ -1,34 +1,35 @@ | ||
| package org.bukkit; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| import com.google.common.collect.Maps; | ||
|
|
||
| public enum Instrument { | ||
|
|
||
| PIANO(0x0), // All other | ||
| BASS_DRUM(0x1), // Stone | ||
| SNARE_DRUM(0x2), // Sand | ||
| STICKS(0x3), // Glass | ||
| BASS_GUITAR(0x4); // Wood | ||
|
|
||
| private final byte type; | ||
| private final static Map<Byte, Instrument> BY_DATA = Maps.newHashMap(); | ||
|
|
||
| private Instrument(final int type) { | ||
| this.type = (byte) type; | ||
| } | ||
|
|
||
| public byte getType() { | ||
| return this.type; | ||
| } | ||
|
|
||
| public static Instrument getByType(final byte type) { | ||
| return BY_DATA.get(type); | ||
| } | ||
|
|
||
| static { | ||
| for (Instrument instrument : Instrument.values()) { | ||
| BY_DATA.put(instrument.getType(), instrument); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,28 @@ | ||
| package org.bukkit; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.junit.Assert.assertThat; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| public class AchievementTest { | ||
|
|
||
| @Test | ||
| public void getByDeprecated() { | ||
| for (Achievement achievement : Achievement.values()) { | ||
| assertThat(Achievement.getAchievement(achievement.getId()), is(achievement)); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void getById() { | ||
| for (Achievement achievement : Achievement.values()) { | ||
| assertThat(Achievement.getById(achievement.getId()), is(achievement)); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void getByOffset() { | ||
| assertThat(Achievement.getById(Achievement.STATISTIC_OFFSET), is(Achievement.values()[0])); | ||
| } | ||
| } |
| @@ -0,0 +1,45 @@ | ||
| package org.bukkit; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.hamcrest.Matchers.greaterThan; | ||
| import static org.junit.Assert.assertThat; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| public class ArtTest { | ||
|
|
||
| @Test(expected = IllegalArgumentException.class) | ||
| public void getByNullName() { | ||
| Art.getByName(null); | ||
| } | ||
|
|
||
| @Test | ||
| public void getById() { | ||
| for (Art art : Art.values()) { | ||
| assertThat(Art.getById(art.getId()), is(art)); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void getByName() { | ||
| for (Art art : Art.values()) { | ||
| assertThat(Art.getByName(art.toString()), is(art)); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void dimensionSanityCheck() { | ||
| for (Art art : Art.values()) { | ||
| assertThat(art.getBlockHeight(), is(greaterThan(0))); | ||
| assertThat(art.getBlockWidth(), is(greaterThan(0))); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void getByNameWithMixedCase() { | ||
| Art subject = Art.values()[0]; | ||
| String name = subject.toString().replace('E', 'e'); | ||
|
|
||
| assertThat(Art.getByName(name), is(subject)); | ||
| } | ||
| } |
| @@ -1,58 +1,71 @@ | ||
| package org.bukkit; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.hamcrest.CoreMatchers.nullValue; | ||
| import static org.junit.Assert.assertThat; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| public class ChatColorTest { | ||
| @Test | ||
| public void getByDeprecated() { | ||
| for (ChatColor color : ChatColor.values()) { | ||
| assertThat(ChatColor.getByCode(color.getCode()), is(color)); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void getByChar() { | ||
| for (ChatColor color : ChatColor.values()) { | ||
| assertThat(ChatColor.getByChar(color.getChar()), is(color)); | ||
| } | ||
| } | ||
|
|
||
| @Test(expected = IllegalArgumentException.class) | ||
| public void getByStringWithNull() { | ||
| ChatColor.getByChar((String) null); | ||
| } | ||
|
|
||
| @Test(expected = IllegalArgumentException.class) | ||
| public void getByStringWithEmpty() { | ||
| ChatColor.getByChar(""); | ||
| } | ||
|
|
||
| @Test | ||
| public void getByNull() { | ||
| assertThat(ChatColor.stripColor(null), is(nullValue())); | ||
| } | ||
|
|
||
| @Test | ||
| public void getByString() { | ||
| for (ChatColor color : ChatColor.values()) { | ||
| assertThat(ChatColor.getByChar(String.valueOf(color.getChar())), is(color)); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void stripColorOnNullString() { | ||
| assertThat(ChatColor.stripColor(null), is(nullValue())); | ||
| } | ||
|
|
||
| @Test | ||
| public void stripColor() { | ||
| StringBuilder subject = new StringBuilder(); | ||
| StringBuilder expected = new StringBuilder(); | ||
|
|
||
| final String filler = "test"; | ||
| for (ChatColor color : ChatColor.values()) { | ||
| subject.append(color).append(filler); | ||
| expected.append(filler); | ||
| } | ||
|
|
||
| assertThat(ChatColor.stripColor(subject.toString()), is(expected.toString())); | ||
| } | ||
|
|
||
| @Test | ||
| public void toStringWorks() { | ||
| for (ChatColor color : ChatColor.values()) { | ||
| assertThat(String.format("%c%c", ChatColor.COLOR_CHAR, color.getChar()), is(color.toString())); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,15 @@ | ||
| package org.bukkit; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.junit.Assert.assertThat; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| public class CoalTypeTest { | ||
| @Test | ||
| public void getByData() { | ||
| for (CoalType coalType : CoalType.values()) { | ||
| assertThat(CoalType.getByData(coalType.getData()), is(coalType)); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,15 @@ | ||
| package org.bukkit; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.junit.Assert.assertThat; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| public class CropStateTest { | ||
| @Test | ||
| public void getByData() { | ||
| for (CropState cropState : CropState.values()) { | ||
| assertThat(CropState.getByData(cropState.getData()), is(cropState)); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,15 @@ | ||
| package org.bukkit; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.junit.Assert.assertThat; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| public class DifficultyTest { | ||
| @Test | ||
| public void getByValue() { | ||
| for (Difficulty difficulty : Difficulty.values()) { | ||
| assertThat(Difficulty.getByValue(difficulty.getValue()), is(difficulty)); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,15 @@ | ||
| package org.bukkit; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.junit.Assert.assertThat; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| public class DyeColorTest { | ||
| @Test | ||
| public void getByData() { | ||
| for (DyeColor dyeColor : DyeColor.values()) { | ||
| assertThat(DyeColor.getByData(dyeColor.getData()), is(dyeColor)); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,15 @@ | ||
| package org.bukkit; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.junit.Assert.assertThat; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| public class EffectTest { | ||
| @Test | ||
| public void getById() { | ||
| for (Effect effect : Effect.values()) { | ||
| assertThat(Effect.getById(effect.getId()), is(effect)); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,15 @@ | ||
| package org.bukkit; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.junit.Assert.assertThat; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| public class EntityEffectTest { | ||
| @Test | ||
| public void getByData() { | ||
| for (EntityEffect entityEffect : EntityEffect.values()) { | ||
| assertThat(EntityEffect.getByData(entityEffect.getData()), is(entityEffect)); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,15 @@ | ||
| package org.bukkit; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.junit.Assert.assertThat; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| public class GameModeTest { | ||
| @Test | ||
| public void getByValue() { | ||
| for (GameMode gameMode : GameMode.values()) { | ||
| assertThat(GameMode.getByValue(gameMode.getValue()), is(gameMode)); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,15 @@ | ||
| package org.bukkit; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.junit.Assert.assertThat; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| public class GrassSpeciesTest { | ||
| @Test | ||
| public void getByData() { | ||
| for (GrassSpecies grassSpecies : GrassSpecies.values()) { | ||
| assertThat(GrassSpecies.getByData(grassSpecies.getData()), is(grassSpecies)); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,15 @@ | ||
| package org.bukkit; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.junit.Assert.assertThat; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| public class InstrumentTest { | ||
| @Test | ||
| public void getByType() { | ||
| for (Instrument instrument : Instrument.values()) { | ||
| assertThat(Instrument.getByType(instrument.getType()), is(instrument)); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,82 @@ | ||
| package org.bukkit; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.hamcrest.CoreMatchers.isA; | ||
| import static org.hamcrest.CoreMatchers.nullValue; | ||
| import static org.junit.Assert.assertThat; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| 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())); | ||
| } | ||
|
|
||
| @Test | ||
| public void getByNameNull() { | ||
| assertThat(Material.getMaterial(null), is(nullValue())); | ||
| } | ||
|
|
||
| // [EB]: gawd we need better code >.> | ||
| @SuppressWarnings({ "unchecked", "rawtypes" }) | ||
| @Test | ||
| public void getData() { | ||
| for (Material material : Material.values()) { | ||
| Class clazz = material.getData(); | ||
|
|
||
| assertThat(material.getNewData((byte) 0), isA(clazz)); | ||
| } | ||
| } | ||
|
|
||
| @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)); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,107 @@ | ||
| package org.bukkit; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.hamcrest.CoreMatchers.nullValue; | ||
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertNotNull; | ||
| import static org.junit.Assert.assertThat; | ||
| import static org.junit.Assert.assertTrue; | ||
| import static org.junit.Assert.fail; | ||
|
|
||
| import java.util.Collection; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| import com.google.common.collect.Lists; | ||
|
|
||
| public class NoteTest { | ||
| @Test | ||
| public void getToneByDeprecated() { | ||
| for (Note.Tone tone : Note.Tone.values()) { | ||
| assertThat(Note.Tone.getToneById(tone.getId()), is(tone)); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void getToneByData() { | ||
| for (Note.Tone tone : Note.Tone.values()) { | ||
| assertThat(Note.Tone.getById(tone.getId()), is(tone)); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void verifySharpedData() { | ||
| for (Note.Tone tone : Note.Tone.values()) { | ||
| if (!tone.isSharpable()) return; | ||
|
|
||
| assertFalse(tone.isSharped(tone.getId(false))); | ||
| assertTrue(tone.isSharped(tone.getId(true))); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void verifyUnknownToneData() { | ||
| Collection<Byte> tones = Lists.newArrayList(); | ||
| for (int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) { | ||
| tones.add((byte) i); | ||
| } | ||
|
|
||
| for (Note.Tone tone : Note.Tone.values()) { | ||
| if (tone.isSharpable()) tones.remove(tone.getId(true)); | ||
| tones.remove(tone.getId()); | ||
| } | ||
|
|
||
| for (Byte data : tones) { | ||
| assertThat(Note.Tone.getById(data), is(nullValue())); | ||
|
|
||
| for (Note.Tone tone : Note.Tone.values()) { | ||
| try { | ||
| tone.isSharped(data); | ||
|
|
||
| fail(data + " should throw IllegalArgumentException"); | ||
| } catch (IllegalArgumentException e) { | ||
| assertNotNull(e); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Test(expected = IllegalArgumentException.class) | ||
| public void createNoteBelowMin() { | ||
| new Note((byte) -1); | ||
| } | ||
|
|
||
| @Test(expected = IllegalArgumentException.class) | ||
| public void createNoteAboveMax() { | ||
| new Note((byte) 25); | ||
| } | ||
|
|
||
| @Test(expected = IllegalArgumentException.class) | ||
| public void createNoteOctaveBelowMax() { | ||
| new Note((byte) -1, Note.Tone.A, true); | ||
| } | ||
|
|
||
| @Test(expected = IllegalArgumentException.class) | ||
| public void createNoteOctaveAboveMax() { | ||
| new Note((byte) 3, Note.Tone.A, true); | ||
| } | ||
|
|
||
| @Test(expected = IllegalArgumentException.class) | ||
| public void createNoteOctaveNonSharpable() { | ||
| new Note((byte) 0, Note.Tone.B, true); | ||
| } | ||
|
|
||
| @Test | ||
| public void doo() { | ||
| for (int i = 1; i <= 24; i++) { | ||
| Note note = new Note((byte) i); | ||
| int octave = note.getOctave(); | ||
| Note.Tone tone = note.getTone(); | ||
| boolean sharped = note.isSharped(); | ||
|
|
||
| Note newNote = new Note(octave, tone, sharped); | ||
| assertThat(newNote, is(note)); | ||
| assertThat(newNote.getId(), is(note.getId())); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,22 @@ | ||
| package org.bukkit; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.junit.Assert.assertThat; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| public class StatisticTest { | ||
| @Test | ||
| public void getDeprecated() { | ||
| for (Statistic statistic : Statistic.values()) { | ||
| assertThat(Statistic.getStatistic(statistic.getId()), is(statistic)); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void getById() { | ||
| for (Statistic statistic : Statistic.values()) { | ||
| assertThat(Statistic.getById(statistic.getId()), is(statistic)); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,15 @@ | ||
| package org.bukkit; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.junit.Assert.assertThat; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| public class TreeSpeciesTest { | ||
| @Test | ||
| public void getByData() { | ||
| for (TreeSpecies treeSpecies : TreeSpecies.values()) { | ||
| assertThat(TreeSpecies.getByData(treeSpecies.getData()), is(treeSpecies)); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,15 @@ | ||
| package org.bukkit; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.junit.Assert.assertThat; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| public class WorldTypeTest { | ||
| @Test | ||
| public void getByName() { | ||
| for (WorldType worldType : WorldType.values()) { | ||
| assertThat(WorldType.getByName(worldType.getName()), is(worldType)); | ||
| } | ||
| } | ||
| } |