summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorErik Broes <erikbroes@grum.nl>2012-01-29 11:10:40 +0100
committerErik Broes <erikbroes@grum.nl>2012-01-29 11:17:44 +0100
commit839d00f9d6ca09fc7b2b4fe86b7778e91ee40040 (patch)
tree9408a7fc2fadddb80893a2f064b6835ec8a1eff3 /src/test
parent76dc09be3ca0fd633eb95699072d573c7ffb29df (diff)
downloadbukkit-839d00f9d6ca09fc7b2b4fe86b7778e91ee40040.tar
bukkit-839d00f9d6ca09fc7b2b4fe86b7778e91ee40040.tar.gz
bukkit-839d00f9d6ca09fc7b2b4fe86b7778e91ee40040.tar.lz
bukkit-839d00f9d6ca09fc7b2b4fe86b7778e91ee40040.tar.xz
bukkit-839d00f9d6ca09fc7b2b4fe86b7778e91ee40040.zip
Add some testing
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/bukkit/AchievementTest.java28
-rw-r--r--src/test/java/org/bukkit/ArtTest.java45
-rw-r--r--src/test/java/org/bukkit/ChatColorTest.java71
-rw-r--r--src/test/java/org/bukkit/CoalTypeTest.java15
-rw-r--r--src/test/java/org/bukkit/CropStateTest.java15
-rw-r--r--src/test/java/org/bukkit/DifficultyTest.java15
-rw-r--r--src/test/java/org/bukkit/DyeColorTest.java15
-rw-r--r--src/test/java/org/bukkit/EffectTest.java15
-rw-r--r--src/test/java/org/bukkit/EntityEffectTest.java15
-rw-r--r--src/test/java/org/bukkit/GameModeTest.java15
-rw-r--r--src/test/java/org/bukkit/GrassSpeciesTest.java15
-rw-r--r--src/test/java/org/bukkit/InstrumentTest.java15
-rw-r--r--src/test/java/org/bukkit/MaterialTest.java82
-rw-r--r--src/test/java/org/bukkit/NoteTest.java107
-rw-r--r--src/test/java/org/bukkit/StatisticTest.java22
-rw-r--r--src/test/java/org/bukkit/TreeSpeciesTest.java15
-rw-r--r--src/test/java/org/bukkit/WorldTypeTest.java15
17 files changed, 491 insertions, 29 deletions
diff --git a/src/test/java/org/bukkit/AchievementTest.java b/src/test/java/org/bukkit/AchievementTest.java
new file mode 100644
index 00000000..ddd46e78
--- /dev/null
+++ b/src/test/java/org/bukkit/AchievementTest.java
@@ -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]));
+ }
+}
diff --git a/src/test/java/org/bukkit/ArtTest.java b/src/test/java/org/bukkit/ArtTest.java
new file mode 100644
index 00000000..29fe34ad
--- /dev/null
+++ b/src/test/java/org/bukkit/ArtTest.java
@@ -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));
+ }
+}
diff --git a/src/test/java/org/bukkit/ChatColorTest.java b/src/test/java/org/bukkit/ChatColorTest.java
index acf7c5e9..7ccff623 100644
--- a/src/test/java/org/bukkit/ChatColorTest.java
+++ b/src/test/java/org/bukkit/ChatColorTest.java
@@ -1,58 +1,71 @@
package org.bukkit;
-import org.junit.AfterClass;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+
import org.junit.Test;
-import static org.junit.Assert.*;
-import org.junit.BeforeClass;
-import static org.hamcrest.CoreMatchers.*;
public class ChatColorTest {
@Test
- public void testGetCode() {
- ChatColor color = ChatColor.DARK_RED;
- assertThat(color.getCode(), equalTo(4));
+ public void getByDeprecated() {
+ for (ChatColor color : ChatColor.values()) {
+ assertThat(ChatColor.getByCode(color.getCode()), is(color));
+ }
}
@Test
- public void testGetChar() {
- ChatColor color = ChatColor.MAGIC;
- assertThat(color.getChar(), equalTo('k'));
+ public void getByChar() {
+ for (ChatColor color : ChatColor.values()) {
+ assertThat(ChatColor.getByChar(color.getChar()), is(color));
+ }
}
- @Test
- public void testToString() {
- ChatColor color = ChatColor.LIGHT_PURPLE;
- assertThat(color.toString(), equalTo("\u00A7d"));
+ @Test(expected = IllegalArgumentException.class)
+ public void getByStringWithNull() {
+ ChatColor.getByChar((String) null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void getByStringWithEmpty() {
+ ChatColor.getByChar("");
}
@Test
- public void testGetByCode() {
- ChatColor color = ChatColor.AQUA;
- assertThat(ChatColor.getByCode(color.getCode()), equalTo(color));
+ public void getByNull() {
+ assertThat(ChatColor.stripColor(null), is(nullValue()));
}
@Test
- public void testGetByChar_char() {
- ChatColor color = ChatColor.GOLD;
- assertThat(ChatColor.getByChar(color.getChar()), equalTo(color));
+ public void getByString() {
+ for (ChatColor color : ChatColor.values()) {
+ assertThat(ChatColor.getByChar(String.valueOf(color.getChar())), is(color));
+ }
}
@Test
- public void testGetByChar_String() {
- ChatColor color = ChatColor.BLUE;
- assertThat(ChatColor.getByChar(((Character)color.getChar()).toString()), equalTo(color));
+ public void stripColorOnNullString() {
+ assertThat(ChatColor.stripColor(null), is(nullValue()));
}
@Test
- public void testStripColor() {
- String string = "";
- String expected = "";
+ public void stripColor() {
+ StringBuilder subject = new StringBuilder();
+ StringBuilder expected = new StringBuilder();
+ final String filler = "test";
for (ChatColor color : ChatColor.values()) {
- string += color + "test";
- expected += "test";
+ subject.append(color).append(filler);
+ expected.append(filler);
}
- assertThat(ChatColor.stripColor(string), equalTo(expected));
+ 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()));
+ }
}
}
diff --git a/src/test/java/org/bukkit/CoalTypeTest.java b/src/test/java/org/bukkit/CoalTypeTest.java
new file mode 100644
index 00000000..7eb11cea
--- /dev/null
+++ b/src/test/java/org/bukkit/CoalTypeTest.java
@@ -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));
+ }
+ }
+}
diff --git a/src/test/java/org/bukkit/CropStateTest.java b/src/test/java/org/bukkit/CropStateTest.java
new file mode 100644
index 00000000..f792a1c4
--- /dev/null
+++ b/src/test/java/org/bukkit/CropStateTest.java
@@ -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));
+ }
+ }
+}
diff --git a/src/test/java/org/bukkit/DifficultyTest.java b/src/test/java/org/bukkit/DifficultyTest.java
new file mode 100644
index 00000000..293e283a
--- /dev/null
+++ b/src/test/java/org/bukkit/DifficultyTest.java
@@ -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));
+ }
+ }
+}
diff --git a/src/test/java/org/bukkit/DyeColorTest.java b/src/test/java/org/bukkit/DyeColorTest.java
new file mode 100644
index 00000000..70049d7f
--- /dev/null
+++ b/src/test/java/org/bukkit/DyeColorTest.java
@@ -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));
+ }
+ }
+}
diff --git a/src/test/java/org/bukkit/EffectTest.java b/src/test/java/org/bukkit/EffectTest.java
new file mode 100644
index 00000000..08aa71d3
--- /dev/null
+++ b/src/test/java/org/bukkit/EffectTest.java
@@ -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));
+ }
+ }
+}
diff --git a/src/test/java/org/bukkit/EntityEffectTest.java b/src/test/java/org/bukkit/EntityEffectTest.java
new file mode 100644
index 00000000..0c92d5cd
--- /dev/null
+++ b/src/test/java/org/bukkit/EntityEffectTest.java
@@ -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));
+ }
+ }
+}
diff --git a/src/test/java/org/bukkit/GameModeTest.java b/src/test/java/org/bukkit/GameModeTest.java
new file mode 100644
index 00000000..f671faef
--- /dev/null
+++ b/src/test/java/org/bukkit/GameModeTest.java
@@ -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));
+ }
+ }
+}
diff --git a/src/test/java/org/bukkit/GrassSpeciesTest.java b/src/test/java/org/bukkit/GrassSpeciesTest.java
new file mode 100644
index 00000000..9e332c71
--- /dev/null
+++ b/src/test/java/org/bukkit/GrassSpeciesTest.java
@@ -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));
+ }
+ }
+}
diff --git a/src/test/java/org/bukkit/InstrumentTest.java b/src/test/java/org/bukkit/InstrumentTest.java
new file mode 100644
index 00000000..f1a05705
--- /dev/null
+++ b/src/test/java/org/bukkit/InstrumentTest.java
@@ -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));
+ }
+ }
+}
diff --git a/src/test/java/org/bukkit/MaterialTest.java b/src/test/java/org/bukkit/MaterialTest.java
new file mode 100644
index 00000000..46be920b
--- /dev/null
+++ b/src/test/java/org/bukkit/MaterialTest.java
@@ -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));
+ }
+ }
+}
diff --git a/src/test/java/org/bukkit/NoteTest.java b/src/test/java/org/bukkit/NoteTest.java
new file mode 100644
index 00000000..34284b96
--- /dev/null
+++ b/src/test/java/org/bukkit/NoteTest.java
@@ -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()));
+ }
+ }
+}
diff --git a/src/test/java/org/bukkit/StatisticTest.java b/src/test/java/org/bukkit/StatisticTest.java
new file mode 100644
index 00000000..1c758fc3
--- /dev/null
+++ b/src/test/java/org/bukkit/StatisticTest.java
@@ -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));
+ }
+ }
+}
diff --git a/src/test/java/org/bukkit/TreeSpeciesTest.java b/src/test/java/org/bukkit/TreeSpeciesTest.java
new file mode 100644
index 00000000..4a997306
--- /dev/null
+++ b/src/test/java/org/bukkit/TreeSpeciesTest.java
@@ -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));
+ }
+ }
+}
diff --git a/src/test/java/org/bukkit/WorldTypeTest.java b/src/test/java/org/bukkit/WorldTypeTest.java
new file mode 100644
index 00000000..d31c2052
--- /dev/null
+++ b/src/test/java/org/bukkit/WorldTypeTest.java
@@ -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));
+ }
+ }
+}