Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.patchbukkit.testplugin;

import java.util.List;

public interface DynamicTestProvider {
List<TestResult> runDynamicTests();
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public void onEnable() {
framework.registerSuite(new ConsoleSenderTests());
framework.registerSuite(new UnsafeValuesTests());
framework.registerSuite(new StubTests());
framework.registerSuite(new LegacyMaterialTests());

// Set executor on the PluginCommand created by PatchBukkit's Rust side
PbTestCommand cmd = new PbTestCommand(framework);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public enum TestCategory {
ENTITY,
CONSOLE_SENDER,
UNSAFE_VALUES,
STUBS
STUBS,
LEGACY_MATERIALS
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,9 @@ public List<TestResult> runAll() {
}

public List<TestResult> runCategory(TestCategory category) {
List<TestResult> results = new ArrayList<>();
for (Object suite : suites) {
for (Method method : suite.getClass().getDeclaredMethods()) {
ConformanceTest ann = method.getAnnotation(ConformanceTest.class);
if (ann != null && ann.category() == category) {
results.add(runTest(suite, method, ann));
}
}
}
return results;
return runAll().stream()
.filter(r -> r.category() == category)
.toList();
}

private List<TestResult> runSuite(Object suite) {
Expand All @@ -60,6 +53,9 @@ private List<TestResult> runSuite(Object suite) {
results.add(runTest(suite, method, ann));
}
}
if (suite instanceof DynamicTestProvider provider) {
results.addAll(provider.runDynamicTests());
}
return results;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.patchbukkit.testplugin.tests;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.material.MaterialData;
import org.patchbukkit.testplugin.DynamicTestProvider;
import org.patchbukkit.testplugin.TestCategory;
import org.patchbukkit.testplugin.TestExpectation;
import org.patchbukkit.testplugin.TestResult;

import java.util.ArrayList;
import java.util.List;

@SuppressWarnings("deprecation")
public final class LegacyMaterialTests implements DynamicTestProvider {

@Override
public List<TestResult> runDynamicTests() {
List<TestResult> results = new ArrayList<>();

for (Material mat : Material.values()) {
if (!mat.isLegacy()) continue;
if (mat == Material.LEGACY_AIR) continue;

String name = mat.name();
try {
Material result = Bukkit.getUnsafe().fromLegacy(new MaterialData(mat, (byte) 0));
if (result != null && result != Material.AIR) {
results.add(new TestResult(
name + " -> " + result.name(),
TestCategory.LEGACY_MATERIALS,
TestExpectation.SHOULD_WORK,
true,
null
));
} else {
results.add(new TestResult(
name + " -> " + result,
TestCategory.LEGACY_MATERIALS,
TestExpectation.SHOULD_WORK,
false,
"Converted to " + result + " (expected non-AIR)"
));
}
} catch (Exception e) {
results.add(new TestResult(
name + " -> ERROR",
TestCategory.LEGACY_MATERIALS,
TestExpectation.SHOULD_WORK,
false,
e.getClass().getSimpleName() + ": " + e.getMessage()
));
}
}

return results;
}
}
Loading