Skip to content
This repository has been archived by the owner on Jul 21, 2024. It is now read-only.

Commit

Permalink
Added Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexeption committed Nov 29, 2020
1 parent 50f320e commit 988854f
Show file tree
Hide file tree
Showing 54 changed files with 3,578 additions and 17 deletions.
11 changes: 11 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ configurations{
}

dependencies {
testCompile 'org.hamcrest:hamcrest-all:1.3'
testCompile 'org.hamcrest:hamcrest-library:1.3'
testCompile group: 'junit', name: 'junit', version: '4.12'
compile(group: 'bukkit', name: 'bukkit', version: '1.12.2-R0.1')
compile 'com.conversantmedia:disruptor:1.2.14'
Expand Down Expand Up @@ -164,6 +166,9 @@ minecraft {
}
}

extractForgeSources { exclude "**/SideOnly.java", "**/Side.java" }
extractForgeResources { exclude "**/log4j2.xml" }

sourceCompatibility = 1.8
tasks.generateXmlConfig.dependsOn installer
tasks.compileJava.enabled = false
Expand Down Expand Up @@ -244,11 +249,17 @@ extractForgeSources {
}

genGradleProjects {
addTestCompileDep "junit:junit:4.12" // TODO update unit tests to junit 5 and remove this
addTestCompileDep "org.junit.jupiter:junit-jupiter-api:5.0.0"
addTestCompileDep "org.opentest4j:opentest4j:1.0.0" // needed for junit 5
addTestCompileDep "org.hamcrest:hamcrest-all:1.3"
addTestCompileDep "org.hamcrest:hamcrest-library:1.3"
addCompileDep "junit:junit:4.12"
addCompileDep "bukkit:bukkit:1.12.2-R0.1"
addCompileDep "org.reflections:reflections:0.9.10"
addCompileDep "javassist:javassist:3.12.1.GA"
addRepo("MagmaFoundation", "https://repo.hexeption.dev/repository/magma/")
filter { dep -> !dep.contains("scala") }
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public CraftChunkData(World world) {
this(world.getMaxHeight());
}

/* pp for tests */ CraftChunkData(int maxHeight) {
public CraftChunkData(int maxHeight) {
if (maxHeight > 256) {
throw new IllegalArgumentException("World height exceeded max chunk height");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public final class CraftItemFactory implements ItemFactory {
static final Color DEFAULT_LEATHER_COLOR = Color.fromRGB(0xA06540);
static final Collection<String> KNOWN_NBT_ATTRIBUTE_NAMES;
public static final Collection<String> KNOWN_NBT_ATTRIBUTE_NAMES;
private static final CraftItemFactory instance;

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ boolean isEmpty() {
}

@Override
boolean applicableTo(Material type) {
public boolean applicableTo(Material type) {
return type == Material.BANNER;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ boolean isEmpty() {
}

@Override
boolean applicableTo(Material type) {
public boolean applicableTo(Material type) {
switch(type){
case FURNACE:
case CHEST:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ boolean isBookEmpty() {
}

@Override
boolean applicableTo(Material type) {
public boolean applicableTo(Material type) {
switch (type) {
case WRITTEN_BOOK:
case BOOK_AND_QUILL:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ boolean isEmpty() {
}

@Override
boolean applicableTo(Material type) {
public boolean applicableTo(Material type) {
switch (type) {
case WRITTEN_BOOK:
case BOOK_AND_QUILL:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void applyToItem(NBTTagCompound itemTag) {
}

@Override
boolean applicableTo(Material type) {
public boolean applicableTo(Material type) {
switch (type) {
case FIREWORK_CHARGE:
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void applyToItem(NBTTagCompound itemTag) {
}

@Override
boolean applicableTo(Material type) {
public boolean applicableTo(Material type) {
switch (type) {
case ENCHANTED_BOOK:
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ static void addColors(NBTTagCompound compound, ItemMetaKey key, List<Color> colo
}

@Override
boolean applicableTo(Material type) {
public boolean applicableTo(Material type) {
switch(type) {
case FIREWORK:
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
* <li> SerializableMeta.Deserializers deserializer()
*/
@DelegateDeserialization(CraftMetaItem.SerializableMeta.class)
class CraftMetaItem implements ItemMeta, Repairable {
public class CraftMetaItem implements ItemMeta, Repairable {

static class ItemMetaKey {

Expand Down Expand Up @@ -615,7 +615,7 @@ void setDisplayTag(NBTTagCompound tag, String key, NBTBase value) {
}

@Overridden
boolean applicableTo(Material type) {
public boolean applicableTo(Material type) {
return type != Material.AIR;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ boolean isBookEmpty() {
}

@Override
boolean applicableTo(Material type) {
public boolean applicableTo(Material type) {
switch (type) {
case KNOWLEDGE_BOOK:
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ boolean isLeatherArmorEmpty() {
}

@Override
boolean applicableTo(Material type) {
public boolean applicableTo(Material type) {
switch(type) {
case LEATHER_HELMET:
case LEATHER_CHESTPLATE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void applyToItem(NBTTagCompound tag) {
}

@Override
boolean applicableTo(Material type) {
public boolean applicableTo(Material type) {
switch (type) {
case MAP:
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ boolean isPotionEmpty() {
}

@Override
boolean applicableTo(Material type) {
public boolean applicableTo(Material type) {
switch(type) {
case POTION:
case SPLASH_POTION:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ boolean isSkullEmpty() {
}

@Override
boolean applicableTo(Material type) {
public boolean applicableTo(Material type) {
switch(type) {
case SKULL_ITEM:
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void applyToItem(NBTTagCompound tag) {
}

@Override
boolean applicableTo(Material type) {
public boolean applicableTo(Material type) {
switch (type) {
case MONSTER_EGG:
return true;
Expand Down
65 changes: 65 additions & 0 deletions src/test/java/org/bukkit/ArtTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.bukkit;

import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;

import com.google.common.collect.Lists;
import java.util.Collections;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import net.minecraft.entity.item.EntityPainting.EnumArt;
import org.bukkit.craftbukkit.v1_12_R1.CraftArt;
import org.junit.Test;

public class ArtTest {

private static final int UNIT_MULTIPLIER = 16;

@Test
public void verifyMapping() {
List<Art> arts = Lists.newArrayList(Art.values());

for (EnumArt enumArt : EnumArt.values()) {
int id = enumArt.ordinal();
String name = enumArt.title;
int width = enumArt.sizeX / UNIT_MULTIPLIER;
int height = enumArt.sizeY / UNIT_MULTIPLIER;

Art subject = Art.getById(id);

String message = String.format("org.bukkit.Art is missing id: %d named: '%s'", id, name);
assertNotNull(message, subject);

assertThat(Art.getByName(name), is(subject));
assertThat("Art." + subject + "'s width", subject.getBlockWidth(), is(width));
assertThat("Art." + subject + "'s height", subject.getBlockHeight(), is(height));

arts.remove(subject);
}

assertThat("org.bukkit.Art has too many arts", arts, is(Collections.EMPTY_LIST));
}

@Test
public void testCraftArtToNotch() {
Map<EnumArt, Art> cache = new EnumMap(EnumArt.class);
for (Art art : Art.values()) {
EnumArt enumArt = CraftArt.BukkitToNotch(art);
assertNotNull(art.name(), enumArt);
assertThat(art.name(), cache.put(enumArt, art), is(nullValue()));
}
}

@Test
public void testCraftArtToBukkit() {
Map<Art, EnumArt> cache = new EnumMap(Art.class);
for (EnumArt enumArt : EnumArt.values()) {
Art art = CraftArt.NotchToBukkit(enumArt);
assertNotNull(enumArt.name(), art);
assertThat(enumArt.name(), cache.put(art, enumArt), is(nullValue()));
}
}
}
24 changes: 24 additions & 0 deletions src/test/java/org/bukkit/BiomeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.bukkit;

import org.bukkit.block.Biome;
import org.bukkit.craftbukkit.v1_12_R1.block.CraftBlock;
import org.bukkit.support.AbstractTestingBase;
import org.junit.Assert;
import org.junit.Test;

public class BiomeTest extends AbstractTestingBase {

@Test
public void testBukkitToMinecraft() {
for (Biome biome : Biome.values()) {
Assert.assertNotNull("No NMS mapping for " + biome, CraftBlock.biomeToBiomeBase(biome));
}
}

@Test
public void testMinecraftToBukkit() {
for (Object biome : net.minecraft.world.biome.Biome.REGISTRY) {
Assert.assertNotNull("No Bukkit mapping for " + biome, CraftBlock.biomeBaseToBiome((net.minecraft.world.biome.Biome) biome));
}
}
}
22 changes: 22 additions & 0 deletions src/test/java/org/bukkit/ChatTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.bukkit;

import net.minecraft.util.text.TextFormatting;
import org.bukkit.craftbukkit.v1_12_R1.util.CraftChatMessage;
import org.junit.Assert;
import org.junit.Test;

public class ChatTest {

@Test
public void testColors() {
for (ChatColor color : ChatColor.values()) {
Assert.assertNotNull(CraftChatMessage.getColor(color));
Assert.assertEquals(color, CraftChatMessage.getColor(CraftChatMessage.getColor(color)));
}

for (TextFormatting format : TextFormatting.values()) {
Assert.assertNotNull(CraftChatMessage.getColor(format));
Assert.assertEquals(format, CraftChatMessage.getColor(CraftChatMessage.getColor(format)));
}
}
}
46 changes: 46 additions & 0 deletions src/test/java/org/bukkit/DyeColorsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.bukkit;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;

import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemDye;
import org.bukkit.support.AbstractTestingBase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;

@RunWith(Parameterized.class)
public class DyeColorsTest extends AbstractTestingBase {

@Parameter
public DyeColor dye;

@Parameters(name = "{index}: {0}")
public static List<Object[]> data() {
List<Object[]> list = new ArrayList<Object[]>();
for (DyeColor dye : DyeColor.values()) {
list.add(new Object[]{dye});
}
return list;
}

@Test
public void checkColor() {
Color color = dye.getColor();
float[] nmsColorArray = EnumDyeColor.byMetadata(dye.getWoolData()).getColorComponentValues();
Color nmsColor = Color.fromRGB((int) (nmsColorArray[0] * 255), (int) (nmsColorArray[1] * 255), (int) (nmsColorArray[2] * 255));
assertThat(color, is(nmsColor));
}

@Test
public void checkFireworkColor() {
Color color = dye.getFireworkColor();
int nmsColor = ItemDye.DYE_COLORS[dye.getDyeData()];
assertThat(color, is(Color.fromRGB(nmsColor)));
}
}
48 changes: 48 additions & 0 deletions src/test/java/org/bukkit/MaterialTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.bukkit;

import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;

import com.google.common.collect.Maps;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import net.minecraft.item.Item;
import org.bukkit.craftbukkit.v1_12_R1.util.CraftMagicNumbers;
import org.bukkit.support.AbstractTestingBase;
import org.junit.Test;

public class MaterialTest extends AbstractTestingBase {

@Test
public void verifyMapping() {
Map<Integer, Material> materials = Maps.newHashMap();
for (Material material : Material.values()) {
if (INVALIDATED_MATERIALS.contains(material)) {
continue;
}

materials.put(material.getId(), material);
}

Iterator<Item> items = Item.REGISTRY.iterator();

while (items.hasNext()) {
Item item = items.next();
if (item == null) {
continue;
}

int id = CraftMagicNumbers.getId(item);
String name = item.getUnlocalizedName();

Material material = materials.remove(id);

assertThat("Missing " + name + "(" + id + ")", material, is(not(nullValue())));
}

assertThat(materials, is(Collections.EMPTY_MAP));
}
}
Loading

0 comments on commit 988854f

Please sign in to comment.