-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GameTestLoaderHelpers for Forge and NeoForge
- Loading branch information
1 parent
74e1e03
commit c42775d
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
loader-common/src/main/java/org/cyclops/cyclopscore/gametest/GameTestLoaderHelpers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.cyclops.cyclopscore.gametest; | ||
|
||
import com.google.common.collect.Lists; | ||
import net.minecraft.gametest.framework.GameTest; | ||
import net.minecraft.gametest.framework.GameTestAssertException; | ||
import net.minecraft.gametest.framework.StructureUtils; | ||
import net.minecraft.gametest.framework.TestFunction; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
/** | ||
* Utilities for loading game tests in a multi-loader environment. | ||
* @author rubensworks | ||
*/ | ||
public class GameTestLoaderHelpers { | ||
|
||
public static Collection<TestFunction> generateCommonTests(String modId, Class<?>[] testClasses) throws InstantiationException, IllegalAccessException { | ||
List<TestFunction> testsList = Lists.newArrayList(); | ||
|
||
for(Class<?> clazz : testClasses) { | ||
Object instance = clazz.newInstance(); | ||
for (Method method : clazz.getDeclaredMethods()) { | ||
if (method.isAnnotationPresent(GameTest.class)) { | ||
GameTest gameTest = method.getAnnotation(GameTest.class); | ||
testsList.add(new TestFunction( | ||
modId, | ||
modId + "." + method.getName(), | ||
gameTest.template(), | ||
StructureUtils.getRotationForRotationSteps(gameTest.rotationSteps()), | ||
gameTest.timeoutTicks(), | ||
gameTest.setupTicks(), | ||
gameTest.required(), | ||
gameTest.manualOnly(), | ||
gameTest.attempts(), | ||
gameTest.requiredSuccesses(), | ||
gameTest.skyAccess(), | ||
(gameTestHelpers) -> { | ||
try { | ||
method.invoke(instance, gameTestHelpers); | ||
} catch (InvocationTargetException | IllegalAccessException e) { | ||
e.printStackTrace(); | ||
throw new GameTestAssertException(e.getMessage()); | ||
} | ||
} | ||
)); | ||
} | ||
} | ||
} | ||
|
||
return testsList; | ||
} | ||
|
||
} |