Add some testing

By: Erik Broes <erikbroes@grum.nl>
This commit is contained in:
Bukkit/Spigot
2012-01-29 11:10:40 +01:00
parent ae0eb736d1
commit ac2271958e
34 changed files with 871 additions and 281 deletions

View File

@@ -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]));
}
}

View File

@@ -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));
}
}

View File

@@ -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));
}
@Test
public void testGetChar() {
ChatColor color = ChatColor.MAGIC;
assertThat(color.getChar(), equalTo('k'));
}
@Test
public void testToString() {
ChatColor color = ChatColor.LIGHT_PURPLE;
assertThat(color.toString(), equalTo("\u00A7d"));
}
@Test
public void testGetByCode() {
ChatColor color = ChatColor.AQUA;
assertThat(ChatColor.getByCode(color.getCode()), equalTo(color));
}
@Test
public void testGetByChar_char() {
ChatColor color = ChatColor.GOLD;
assertThat(ChatColor.getByChar(color.getChar()), equalTo(color));
}
@Test
public void testGetByChar_String() {
ChatColor color = ChatColor.BLUE;
assertThat(ChatColor.getByChar(((Character)color.getChar()).toString()), equalTo(color));
}
@Test
public void testStripColor() {
String string = "";
String expected = "";
public void getByDeprecated() {
for (ChatColor color : ChatColor.values()) {
string += color + "test";
expected += "test";
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(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()));
}
}
}

View File

@@ -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));
}
}
}

View File

@@ -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));
}
}
}

View File

@@ -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));
}
}
}

View File

@@ -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));
}
}
}

View File

@@ -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));
}
}
}

View File

@@ -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));
}
}
}

View File

@@ -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));
}
}
}

View File

@@ -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));
}
}
}

View File

@@ -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));
}
}
}

View File

@@ -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));
}
}
}

View File

@@ -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()));
}
}
}

View File

@@ -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));
}
}
}

View File

@@ -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));
}
}
}

View File

@@ -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));
}
}
}